Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formula used to calculate boost::hash

Tags:

hash

boost

I would like to know the formula used to calculate the hash values for Boost.Bimap. For example if I want to know and calculate manually for integer 123456, or bit-set 1101001 or character string abcda.

like image 366
AwaitedOne Avatar asked Aug 06 '18 17:08

AwaitedOne


1 Answers

Boost uses Boost::hash for unordered containers, including Bimap. Boost::hash implementations could be found here on Ginhub.

See hash_range for strings, hash_value_signed/unsigned for integers.

You could use this snippet to calculate hash values (use your data type instead of int):

boost::hash<int> hasher;
size_t hash_value = hasher(your_int_key);

You could also create custom hash function for your data types.

like image 157
Heavy Avatar answered Oct 25 '22 21:10

Heavy