fork(4) download
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3.  
  4. #include "stdint.h" /* Replace with <stdint.h> if appropriate */
  5. #undef get16bits
  6. #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
  7.   || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
  8. #define get16bits(d) (*((const uint16_t *) (d)))
  9. #endif
  10.  
  11. #if !defined (get16bits)
  12. #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
  13.   +(uint32_t)(((const uint8_t *)(d))[0]) )
  14. #endif
  15.  
  16. uint32_t SuperFastHash (const char * data, int len) {
  17. uint32_t hash = len, tmp;
  18. int rem;
  19.  
  20. if (len <= 0 || data == NULL) return 0;
  21.  
  22. rem = len & 3;
  23. len >>= 2;
  24.  
  25. /* Main loop */
  26. for (;len > 0; len--) {
  27. hash += get16bits (data);
  28. tmp = (get16bits (data+2) << 11) ^ hash;
  29. hash = (hash << 16) ^ tmp;
  30. data += 2*sizeof (uint16_t);
  31. hash += hash >> 11;
  32. }
  33.  
  34. /* Handle end cases */
  35. switch (rem) {
  36. case 3: hash += get16bits (data);
  37. hash ^= hash << 16;
  38. hash ^= ((signed char)data[sizeof (uint16_t)]) << 18;
  39. hash += hash >> 11;
  40. break;
  41. case 2: hash += get16bits (data);
  42. hash ^= hash << 11;
  43. hash += hash >> 17;
  44. break;
  45. case 1: hash += (signed char)*data;
  46. hash ^= hash << 10;
  47. hash += hash >> 1;
  48. }
  49.  
  50. /* Force "avalanching" of final 127 bits */
  51. hash ^= hash << 3;
  52. hash += hash >> 5;
  53. hash ^= hash << 4;
  54. hash += hash >> 17;
  55. hash ^= hash << 25;
  56. hash += hash >> 6;
  57.  
  58. return hash;
  59. }
  60.  
  61. int main(void) {
  62. char chunk[] = "Underside.Travel.Bubble";
  63. uint32_t hash = SuperFastHash(chunk, sizeof(chunk) - 1);
  64. printf("value = %d\n", hash);
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0s 5404KB
stdin
Standard input is empty
stdout
value = 321326432