views:

78

answers:

1

hello

I have a curious problem and I am brainstorming possible solutions. The problem is such: I have a number of inputs (up to several thousand different ones), which basically differ in two-three arrays (arrays are a different size generaly, from size one up to couple thousand elements long). the functions which process arrays take some time to initialize data, so i thought to cache function/functor together with data and store them in map.

now, how do i go about converting raw arrays into usable hashtable type? i initially thought to read array into a string and use string as the key. is it good idea? do you have better suggestion?

thanks

+1  A: 

Are these arrays integer? If yes, just go with something like this

hash= (hash+(324723947+a[i]))^93485734985;

Similar thing would work fine for strings if you do it on all characters.

Finally, you may check out extra libs: http://www.boost.org/doc/libs/1_42_0/doc/html/hash.html

BarsMonster
double precision, so technically they can be integers.
aaa
Then it would work perfectly. I would still hash them as integers.
BarsMonster
this hash function, what is the collision rate? I am a bit worried about that
aaa
For float numbers it is going to be nearly perfectly random.So collision rate would depend solely on your hash table size.
BarsMonster