Guest User

Untitled

a guest
Aug 14th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. How do you hash a string? I need random strings somehow turned into integers to put them in my hash table
  2. unsigned long hash(unsigned char *str)
  3. {
  4. unsigned long hash = 5381;
  5. int c;
  6.  
  7. while (c = *str++)
  8. hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
  9.  
  10. return hash;
  11. }
  12.  
  13. #include <boost/functional/hash.hpp>
  14.  
  15. int main()
  16. {
  17. boost::hash<std::string> string_hash;
  18.  
  19. std::size_t h = string_hash("Hash me");
  20.  
  21. size_t table_index = h % 811;
  22. }
  23.  
  24. #include <stdlib.h>
  25. i = atoi(char *);
Add Comment
Please, Sign In to add comment