Subject : [Multi-index] -- using a hashed unique index that is not part of the hashed value
Hello,
what I basically want to do is using multi-index like a hashmap.
I want to use vector<long> as key. However, all the examples I found
are using member-fields of the values or the values themselves as key.
Is it not possible to use multi-index like a hash_map
On 8/21/07, Oliver Kania
Hello,
Hi Oliver,
what I basically want to do is using multi-index like a hashmap. I want to use vector<long> as key. However, all the examples I found are using member-fields of the values or the values themselves as key. Is it not possible to use multi-index like a hash_map
where the key is independent of the value type ? If yes, could someone please provide an example ?
You need Boost.Bimap. Online docs here: http://tinyurl.com/22sja5 Look at "Unconstrained sets" section. It will be included in Boost 1.35, you can check out of svn head now. An example of what you are asking: typedef bimap < vector_of< long >, unconstrained_set_of< something >
bm_type; bm_type bm; assign::push_back( bm ) ( 1, a ) ( 2, b ) ( 3, c ); BOOST_FOREACH( bm_type::left_reference p, bm.left ) { cout << p.first << "-->" << p.second; } King regards Matias
Hello Matias,
thank you for the solution.
1. Is the bimap method as efficient as using, for example,
the hashmap form the gnu-ext namespace ? ( I am talking about
time-efficiency)
2. Is a bimap serializeable by boost::serialize ? That would be absolutely
essential
3. I am sure that I read somewhere boost multi-index can be used as a mormal
hashmap
Did I misinterpret something ? i am asking because I know that multiindex is
serializeable.
regards, Oliver
On 8/21/07, Matias Capeletto
On 8/21/07, Oliver Kania
wrote: Hello,
Hi Oliver,
what I basically want to do is using multi-index like a hashmap. I want to use vector<long> as key. However, all the examples I found are using member-fields of the values or the values themselves as key. Is it not possible to use multi-index like a hash_map
where the key is independent of the value type ? If yes, could someone please provide an example ? You need Boost.Bimap. Online docs here: http://tinyurl.com/22sja5 Look at "Unconstrained sets" section. It will be included in Boost 1.35, you can check out of svn head now.
An example of what you are asking:
typedef bimap < vector_of< long >, unconstrained_set_of< something >
bm_type;
bm_type bm; assign::push_back( bm ) ( 1, a ) ( 2, b ) ( 3, c );
BOOST_FOREACH( bm_type::left_reference p, bm.left ) { cout << p.first << "-->" << p.second; }
King regards Matias _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Matias Capeletto
-
Oliver Kania