Multidimensional hash functions

M

Mike

Hi,

I have a multidimensional array that I would like to access as a hash
map for performance reasons. I cannot see anything in the STL (I mean
STL/TR1) that supports multi-dimensional hash access like eg :

hash_map<Key1, Key2, Value> md_hash;

V1 = md_hash.find(k1, k2); //etc

Do I really need to do this by making hash_maps for each of the rows
and then take a hash_map of all the maps ? Or is there an easier
way ?

Also, the set of {Key,Value} pairs is constant (it is a look up
table) and I would like to initialise the hash map from a 2
dimensional const array. It seems there is no way to do this directly
using STL type hashes but instead I need to create a wrapper class and
iterate through the initialiser array to initialise the hash maps.
This has the downside of wasting the original table of values which is
discarded after the initialisation process, and also is a waste of
time. Does anyone know of a canned (presumeably non STL) hash map
that can utilise the original initialisation array as the actual data
storeage ?

Efficiency is important to me because I'm working on a video codec.

Many thanks,

Mike
 
V

Victor Bazarov

Mike said:
I have a multidimensional array that I would like to access as a hash
map for performance reasons. I cannot see anything in the STL (I mean
STL/TR1) that supports multi-dimensional hash access like eg :

hash_map<Key1, Key2, Value> md_hash;

V1 = md_hash.find(k1, k2); //etc

Do I really need to do this by making hash_maps for each of the rows
and then take a hash_map of all the maps ? Or is there an easier
way ?

I'd try

Value> md_hash; said:
Also, the set of {Key,Value} pairs is constant (it is a look up
table) and I would like to initialise the hash map from a 2
dimensional const array. It seems there is no way to do this directly
using STL type hashes but instead I need to create a wrapper class and
iterate through the initialiser array to initialise the hash maps.

Whatever works...
This has the downside of wasting the original table of values which is
discarded after the initialisation process, and also is a waste of
time.

Keep pointers to const values in your hash_map instead.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top