Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multi-Index] Categorised Container
From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2011-04-29 19:00:16


Hi Marsh,

multi_index_container
<
  T
  hashed_non_unique<...>,
  ordered_non_unique<...>
> my_container;

> 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?

Sure. Take T = pair<TimeStamp, shared_ptr<B> > where B is some base class for a hierarchy in my application. B has a pure virtual member function called id() which returns the same string for any instance of a class D, where D is derived from B.

I will need to have all the instances the dynamic type of the second element of which is of D, but sorted according to TimeStamp's operator <. My idea was to get the first index in my_container to be this id() member function and the second index to be operator < (const TimeStamp&, const TimeStamp&). Is that doable in Multi-Index?

> 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).

Sorry but I'm not sure I can follow your English here. Would you mind paraphrasing it if the issue is still important?

> 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.

This much redundancy is not a matter for me. But, I'd rather not calculate the category on-the-fly for this container is going to be heavily accessed (and also populated/garbage-collected) for every D which derives from B.

Does that make it easier to answer my questions?

TIA,
--Hossein


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net