Skip to content

Instantly share code, notes, and snippets.

@jonathanmarvens
Last active August 29, 2015 14:05
Show Gist options
  • Save jonathanmarvens/01daf97e976f68dacd66 to your computer and use it in GitHub Desktop.
Save jonathanmarvens/01daf97e976f68dacd66 to your computer and use it in GitHub Desktop.
#define AP_HASH(h, s, l) \
do { \
h = 0xAAAAAAAAu; \
unsigned int i = 0u; \
while (i < l) { \
if ((i & 1u) == 0u) { \
h ^= (h << 7) ^ (((unsigned char) s[0]) * (h >> 3)); \
} else { \
h ^= ~((h << 11) + (((unsigned char) s[0]) ^ (h >> 5))); \
} \
s++; \
i++; \
} \
} while (0)
#if 0
// -------
// Usage
// -------
#include <stdio.h>
int
main(void) {
unsigned int hash;
const char *str = "jonathan";
AP_HASH(hash, str, 8);
printf("Hash: %u.\n", hash);
return 0;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment