Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ADDRESS(p,o) ((void *)(((char *)p)+(o)))
- #define CC_HASH_READ8(d,o) ((uint32_t)(((uint8_t *)d)[o]))
- #define CC_HASH_AREAD16(d,o) ((uint32_t)(*((uint16_t *)ADDRESS(d,o))))
- #define CC_HASH_UREAD16(d,o) ((((uint32_t)(((uint8_t *)(d))[o+1]))<<8)+(uint32_t)(((uint8_t *)(d))[o]))
- uint32_t ccHash32Data( void *data, int size )
- {
- uint32_t hash;
- int rem;
- rem = size & 3;
- size >>= 2;
- hash = 0;
- if( !( ( (uintptr_t)data ) & 0x1 ) )
- {
- for( ; size ; size-- )
- {
- hash += CC_HASH_AREAD16( data, 0 );
- hash = ( hash << 16 ) ^ ( ( CC_HASH_AREAD16( data, 2 ) << 11 ) ^ hash );
- hash += hash >> 11;
- data = ADDRESS( data, 4 );
- }
- }
- else
- {
- for( ; size ; size-- )
- {
- hash += CC_HASH_UREAD16( data, 0 );
- hash = ( hash << 16 ) ^ ( ( CC_HASH_UREAD16( data, 2 ) << 11 ) ^ hash );
- hash += hash >> 11;
- data = ADDRESS( data, 4 );
- }
- }
- switch( rem )
- {
- case 3:
- hash += CC_HASH_UREAD16( data, 0 );
- hash ^= hash << 16;
- hash ^= CC_HASH_READ8( data, 2 ) << 18;
- hash += hash >> 11;
- break;
- case 2:
- hash += CC_HASH_UREAD16( data, 0 );
- hash ^= hash << 11;
- hash += hash >> 17;
- break;
- case 1:
- hash += CC_HASH_READ8( data, 0 );
- hash ^= hash << 10;
- hash += hash >> 1;
- break;
- case 0:
- break;
- }
- hash ^= hash << 3;
- hash += hash >> 5;
- hash ^= hash << 4;
- hash += hash >> 17;
- hash ^= hash << 25;
- hash += hash >> 6;
- return hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement