Skip to content

Instantly share code, notes, and snippets.

@Mons
Created November 19, 2012 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mons/4110215 to your computer and use it in GitHub Desktop.
Save Mons/4110215 to your computer and use it in GitHub Desktop.
kinda hash or crc
if (sizeof(uintmax_t) == 8) {
size_t i;
uintmax_t
*l = (uintmax_t *) str->str,
xx = 0x2020202020202020ULL;
;
for (i=0; i < str->len / 8; i++) {
xx ^= l[i];
}
unsigned char x =
(( xx & 0xff00000000000000ULL ) >> 56) ^
(( xx & 0x00ff000000000000ULL ) >> 48) ^
(( xx & 0x0000ff0000000000ULL ) >> 40) ^
(( xx & 0x000000ff00000000ULL ) >> 32) ^
(( xx & 0x00000000ff000000ULL ) >> 24) ^
(( xx & 0x0000000000ff0000ULL ) >> 16) ^
(( xx & 0x000000000000ff00ULL ) >> 8) ^
(( xx & 0x00000000000000ffULL ) >> 0)
;
i *= 8;
for (; i < str->len; i++) {
x ^= str->str[i];
}
return x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment