Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How do you hash a string? I need random strings somehow turned into integers to put them in my hash table
- unsigned long hash(unsigned char *str)
- {
- unsigned long hash = 5381;
- int c;
- while (c = *str++)
- hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
- return hash;
- }
- #include <boost/functional/hash.hpp>
- int main()
- {
- boost::hash<std::string> string_hash;
- std::size_t h = string_hash("Hash me");
- size_t table_index = h % 811;
- }
- #include <stdlib.h>
- i = atoi(char *);
Add Comment
Please, Sign In to add comment