开发者

C++, what is a good way to hash array data?

开发者 https://www.devze.com 2022-12-20 17:36 出处:网络
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), whic开发者_C百科h basically differ in two-th

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), whic开发者_C百科h 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?


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 here

0

精彩评论

暂无评论...
验证码 换一张
取 消