Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multi-Index] Categorised Container
From: Marsh Ray (marsh_at_[hidden])
Date: 2011-04-29 13:05:08

Warning: I'm no expert on Multi-Index, I just find it interesting.

On 04/29/2011 11:46 AM, Hossein Haeri wrote:
> I have an application where something we call a "categorised container"
> with colleagues comes very hand. We do currently have a working version
> and I am looking to see whether it's possible to do some refactoring on
> that using Multi-Index. Here is an exemplified explanation of what
> constitutes a decision-making point for me. I would be pleased if anyone
> here could tell me whether this facility is available under Multi-Index:
> multi_index_container
> <
> T
> hashed_non_unique<...>,
> ordered_non_unique<...>
> > my_container;
> Now, is there anyway I can get all elements of my_container which have a
> certain hash and sorted according to the second index?

So are you expecting hash collisions and doing something useful with
them? This is interesting, can you explain more about the problem and
why this is useful?

> In our own local
> terminology, we call that retrieving all the elements of a given
> CATEGORY in a sorted manner. (Sorry I'm not still fluent in the
> MultiIndex syntax to make that more formal with actual code.)

Usually the hash values used for data structure hashes are not given any
additional meaning. I think you're on the right track by calling them
'categories' and suggest you not try to overload it with the hash value
used to index the collection (even if they happen to be the same).

Could you just define a member of T to hold the category and index it
with any non-unique index type? (maybe even a index with an identity
hash function ;-)

If you didn't want to store redundant data in T, you could define a key
extractor which runs your preferred hash function to calculate the
category on the fly.

- Marsh

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at