Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #define ADDRESS(p,o) ((void *)(((char *)p)+(o)))
  2. #define CC_HASH_READ8(d,o) ((uint32_t)(((uint8_t *)d)[o]))
  3. #define CC_HASH_AREAD16(d,o) ((uint32_t)(*((uint16_t *)ADDRESS(d,o))))
  4. #define CC_HASH_UREAD16(d,o) ((((uint32_t)(((uint8_t *)(d))[o+1]))<<8)+(uint32_t)(((uint8_t *)(d))[o]))
  5.  
  6. uint32_t ccHash32Data( void *data, int size )
  7. {
  8. uint32_t hash;
  9. int rem;
  10. rem = size & 3;
  11. size >>= 2;
  12. hash = 0;
  13. if( !( ( (uintptr_t)data ) & 0x1 ) )
  14. {
  15. for( ; size ; size-- )
  16. {
  17. hash += CC_HASH_AREAD16( data, 0 );
  18. hash = ( hash << 16 ) ^ ( ( CC_HASH_AREAD16( data, 2 ) << 11 ) ^ hash );
  19. hash += hash >> 11;
  20. data = ADDRESS( data, 4 );
  21. }
  22. }
  23. else
  24. {
  25. for( ; size ; size-- )
  26. {
  27. hash += CC_HASH_UREAD16( data, 0 );
  28. hash = ( hash << 16 ) ^ ( ( CC_HASH_UREAD16( data, 2 ) << 11 ) ^ hash );
  29. hash += hash >> 11;
  30. data = ADDRESS( data, 4 );
  31. }
  32. }
  33. switch( rem )
  34. {
  35. case 3:
  36. hash += CC_HASH_UREAD16( data, 0 );
  37. hash ^= hash << 16;
  38. hash ^= CC_HASH_READ8( data, 2 ) << 18;
  39. hash += hash >> 11;
  40. break;
  41. case 2:
  42. hash += CC_HASH_UREAD16( data, 0 );
  43. hash ^= hash << 11;
  44. hash += hash >> 17;
  45. break;
  46. case 1:
  47. hash += CC_HASH_READ8( data, 0 );
  48. hash ^= hash << 10;
  49. hash += hash >> 1;
  50. break;
  51. case 0:
  52. break;
  53. }
  54. hash ^= hash << 3;
  55. hash += hash >> 5;
  56. hash ^= hash << 4;
  57. hash += hash >> 17;
  58. hash ^= hash << 25;
  59. hash += hash >> 6;
  60. return hash;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement