
Dominique Devienne
We have BMIs of entries with complex composite "natural-keys". [...] After recently reading http://www.sqlite.org/draft/optoverview.html#skipscan and its Skip-Scan optimization, I wondered about changing my ByNKey unique index from hashed to ordered, and thought that in theory, I could perhaps avoid the maintenance and memory cost of the additional type+name+parent indexes, since all three are subsets of the ByNKey unique index, and using a similar skip-scan strategy, which might/would still provide reasonable performance, at least better than no index at all (i.e. a full scan).
This is an interesting idea! Without making any internal change to
Boost.MultiIndex indices, a decent approximation to skip-scanning can
be achieved. The code pasted at the bottom provides a function skip_scan
that you can use like this
// scan elements with keys *,1,2,3
skip_scan<1>(
c,[](const element& v){std::cout<
{};
template<> struct make_index_sequence_help<0>:index_sequence<>{};
template<> struct make_index_sequence_help<1>:index_sequence<0>{};
template<int n> using make_index_sequence=invoke
void skip_scan(const Container& c,F f,Args&&... args)
{
skip_scan_helper<N>(c,f,Indices(),std::forward<Args>(args)...);
}
// testing
#include
multi_t;
int main()
{
multi_t c={
{0,1,2,3,4},
{0,1,2,3,5},
{0,1,3,4,0},
{1,0,0,0,0},
{1,1,2,3,0},
{1,1,2,3,0},
{2,1,2,1,0},
{2,2,2,3,0},
};
skip_scan<1>(
c,[](const element& v){std::cout<