I'm doing something similar with sparsetable:
http://google-sparsehash.googlecode.com/svn/trunk/doc/implementation.html
typedef sparsetable<string,48> index_t;
Works well when you know the range of unsigned integer keys. The
integer is effectively the hash.
Cheers,
Donovan.
> --
> You received this message because you are subscribed to the Google Groups "google-sparsehash" group.
> To post to this group, send email to google-s...@googlegroups.com.
> To unsubscribe from this group, send email to google-sparseh...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-sparsehash?hl=en.
>
>
sparsetable<unique_id_class,48> table(1024);
unique_id_class unique1("foo");
unique_id_class unique2("bar");
table.set(12,unique1);
table.set(1000,unique1);
table.set(99,unique2);
If you wanted to maintain uniqueness you could keep pointers in the
sparsetable instead and have an unordered_set to store the actual
values, or you could build a custom hash function for your
tuples/arrays:
http://stackoverflow.com/questions/1250599/how-to-unordered-settupleint-int
Depends a lot on what your use case is, as usual!
Cheers,
Donovan.
You can do something like
sparse_hash_map<int, whatever> foo;
foo[5] = whatever;
foo[15] = whatever;
But I agree a sparsetable is more natural for this app.
craig
always enjoy a challenge! The ambiguous nature of the term vector is a
wonderful source of misunderstanding :)
To put a custom data structure in an unordered type map requires the
definition of both an equality and a hash function for that structure.
Equality functions are easy but hash functions are an endless source
of benchmarking fun. I've put a simple example here:
https://gist.github.com/1343184
which uses the suggested hashing from here:
http://www.beosil.com/download/CollisionDetectionHashing_VMV03.pdf
While it always fun to write your own code, there are some libraries
which cover this arena:
http://www.boost.org/doc/libs/1_47_0/libs/numeric/ublas/doc/index.htm
http://eigen.tuxfamily.org/
Hope that helps!
Donovan.
yes, the equality function will compare the two values with the same
hash and take the appropriate action. This action varies between
hashmap implementations and is another source of endless fun :)
http://en.wikipedia.org/wiki/Open_addressing
Cheers,
Donovan.