Skip to content

Instantly share code, notes, and snippets.

@co-dan co-dan/hashable.js
Created Sep 10, 2013

What would you like to do?
/* FNV-1 hash
* The FNV-1 hash description:
* The FNV-1 hash is 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
You can’t perform that action at this time.