Advertisement
Guest User

Untitled

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