Created
September 10, 2013 15:40
-
-
Save co-dan/6511275 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* FNV-1 hash | |
* | |
* The FNV-1 hash description: http://isthe.com/chongo/tech/comp/fnv/ | |
* The FNV-1 hash is public domain: http://isthe.com/chongo/tech/comp/fnv/#public_domain | |
long hashable_fnv_hash(const unsigned char* str, long len, long hash) { | |
while (len--) { | |
hash = (hash * 16777619) ^ *str++; | |
} | |
return hash; | |
} | |
*/ | |
function h$hashable_fnv_hash(str, len, hashInit) { | |
var hash = hashInit; | |
var i; | |
for (i = 0; i < len; i++) { | |
hash = (hash * 16777619) ^ str[i]; | |
} | |
return hash; | |
} | |
/* Used for ByteArray#s. We can't treat them like pointers in | |
native Haskell, but we can in unsafe FFI calls. | |
long hashable_fnv_hash_offset(const unsigned char* str, long offset, long len, long hash) { | |
return hashable_fnv_hash(str + offset, len, hash); | |
} | |
*/ | |
function h$hashable_fnv_hash_offset(str, offset, len, hash) { | |
return h$hashable_fnv_hash(str.substring(offset), len, hash); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment