github.com/tursom/GoCollections@v0.3.10/util/bloom/hash.h (about) 1 #pragma once 2 3 #include<stdint.h> 4 5 uint32_t hash(uint8_t* data, size_t size, uint32_t seed) { 6 uint32_t hash = seed; 7 switch (size % sizeof(uint32_t)) { 8 case 3: 9 hash = hash*31 ^ *data++; 10 case 2: 11 hash = hash*31 ^ *data++; 12 case 1: 13 hash = hash*31 ^ *data++; 14 } 15 16 int n = size / sizeof(uint32_t); 17 for (int i = 0; i < n; i++) { 18 hash = hash*31 ^ *(uint32_t*)data; 19 data += sizeof(uint32_t); 20 } 21 22 return hash; 23 }