Following java code returns hash code of a string.
String uri = "Some URI" public int hashCode() { return uri.hashCode(); }
I want to translate this code to c++. Is there any function availabe in c++ or an easy way to translate this.
Calculation of the hash of a stringhash ( s ) = s [ 0 ] + s [ 1 ] ⋅ p + s [ 2 ] ⋅ p 2 + . . .
A Hash function is a function that maps any kind of data of arbitrary size to fixed-size values. The values returned by the function are called Hash Values or digests. There are many popular Hash Functions such as DJBX33A, MD5, and SHA-256.
A Hash Table in C/C++ (Associative array) is a data structure that maps keys to values. This uses a hash function to compute indexes for a key. Based on the Hash Table index, we can store the value at the appropriate location.
In C++03, boost::hash
. In C++11, std::hash
.
std::hash<std::string>()("foo");
Boost provides a hash function:
boost hash
#include <boost/functional/hash.hpp> int hashCode() { boost::hash<std::string> string_hash; return string_hash("Hash me"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With