Guest User

Untitled

a guest
Aug 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. hash function for string
  2. unsigned long
  3. hash(unsigned char *str)
  4. {
  5. unsigned long hash = 5381;
  6. int c;
  7.  
  8. while (c = *str++)
  9. hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
  10.  
  11. return hash;
  12. }
  13.  
  14. int hash(char const *input) {
  15. int result = 0x55555555;
  16.  
  17. while (*input) {
  18. result ^= *input++;
  19. result = rol(result, 5);
  20. }
  21. }
  22.  
  23. uint32_t jenkins_one_at_a_time_hash(char *key, size_t len)
  24. {
  25. uint32_t hash, i;
  26. for(hash = i = 0; i < len; ++i)
  27. {
  28. hash += key[i];
  29. hash += (hash << 10);
  30. hash ^= (hash >> 6);
  31. }
  32. hash += (hash << 3);
  33. hash ^= (hash >> 11);
  34. hash += (hash << 15);
  35. return hash;
  36. }
Add Comment
Please, Sign In to add comment