save works
This commit is contained in:
parent
d0174f2f30
commit
4db6b039c5
8 changed files with 140 additions and 34 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ < 28)
|
||||
#include <pthread.h>
|
||||
#else
|
||||
|
|
@ -587,3 +588,74 @@ void block_sig(int signo)
|
|||
sigaddset(&mask, signo);
|
||||
sigprocmask(SIG_BLOCK, &mask, NULL);
|
||||
}
|
||||
|
||||
#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
|
||||
#define mix(a, b, c) \
|
||||
{ \
|
||||
a -= c; \
|
||||
a ^= rot(c, 4); \
|
||||
c += b; \
|
||||
b -= a; \
|
||||
b ^= rot(a, 6); \
|
||||
a += c; \
|
||||
c -= b; \
|
||||
c ^= rot(b, 8); \
|
||||
b += a; \
|
||||
a -= c; \
|
||||
a ^= rot(c, 16); \
|
||||
c += b; \
|
||||
b -= a; \
|
||||
b ^= rot(a, 19); \
|
||||
a += c; \
|
||||
c -= b; \
|
||||
c ^= rot(b, 4); \
|
||||
b += a; \
|
||||
}
|
||||
#define final(a, b, c) \
|
||||
{ \
|
||||
c ^= b; \
|
||||
c -= rot(b, 14); \
|
||||
a ^= c; \
|
||||
a -= rot(c, 11); \
|
||||
b ^= a; \
|
||||
b -= rot(a, 25); \
|
||||
c ^= b; \
|
||||
c -= rot(b, 16); \
|
||||
a ^= c; \
|
||||
a -= rot(c, 4); \
|
||||
b ^= a; \
|
||||
b -= rot(a, 14); \
|
||||
c ^= b; \
|
||||
c -= rot(b, 24); \
|
||||
}
|
||||
|
||||
uint32_t hash(uint32_t a, uint32_t b,uint32_t c, uint32_t d) {
|
||||
uint32_t i1 = a, i2 = b, i3 = c, i4 = d;
|
||||
|
||||
mix(i1,i2,i3);
|
||||
mix(i2,i3,i4);
|
||||
mix(i3,i4,i1);
|
||||
final(i4,i1,i2);
|
||||
|
||||
return i2;
|
||||
}
|
||||
|
||||
uint32_t hash64(uint64_t x) {
|
||||
uint32_t a = (uint32_t)(x & UMAX_BITS(32));
|
||||
uint32_t b = (uint32_t)(rot(x, 16) & UMAX_BITS(32));
|
||||
uint32_t c = (uint32_t)(rot(x,32) & UMAX_BITS(32));
|
||||
uint32_t d = (uint32_t)(rot(x, 48) & UMAX_BITS(32));
|
||||
|
||||
return hash(a,b,c,d);
|
||||
}
|
||||
|
||||
uint32_t hash_string(const char *key) {
|
||||
uint32_t hc = 5381;
|
||||
int c;
|
||||
|
||||
while ((c = *key ++)) {
|
||||
hc = ((hc << 5) + hc) + c;
|
||||
}
|
||||
|
||||
return hc;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue