What is an appropriate container for compound index that allows ignoring the sub-index at lookup? It should not use more resources than a container without this feature.
F.e. given the index
struct index_t
{
index_t(unsigned key_, unsigned subkey_)
: key(key_)
, subkey(subkey_)
{}
unsigned key;
unsigned subkey;
};
and inserting
index_t(1,11)
index_t(2,21)
index_t(2,22)
index_t(2,23)
index_t(3,31)
all the elements with f.e. key == 2 and ignoring the subkey have to be looked up.
Also lookups with given key and subkey must be possible. So using a multiset/map with key as the only container’s key is not a solution.
You could do
And for searching for all items with a given key and any subkey, do
That’ll preserve 2*log n performance.