I'd like create a data structure that will describe a relation between posts and tags. Each post can have multiple tags and a tag can be applied to many posts.
Each post and tag can be uniquely identified by a key (let's say int
).
I want to be able to efficiently get all the tags for a given post and all the posts of a given tag.
I want to move from a code that looks like this:
unordered_map<int, vector<int> > post_to_tags;
unordered_map<int, vector<int> > tags_to_post;
to boost::bimap
. I've tried this:
typedef bimap<
unordered_multiset_of<int>,
unordered_multiset_of<int>,
unconstrained_set_of_relation
> BimapType;
BimapType bm;
Without the unconstrained_set_of_relation
the bimap would allow to insert the same (post, tag) pair more than once (since it uses a multiset for the relation). With the unconstrained_set_of_relation
I am unable to figure out how to insert elements into this container (there's no insert defined).
- Can
boost::bimap
describe this relationship at all? - How can insert be performed?
- Is Boost.MultiIndex a better choice (easier to use/efficient) for this case?