Skip to content

Instantly share code, notes, and snippets.

@kauppim
Created May 16, 2012 08:04
Show Gist options
  • Save kauppim/2708523 to your computer and use it in GitHub Desktop.
Save kauppim/2708523 to your computer and use it in GitHub Desktop.
Implemented awesome-hash without any advanced error handling.
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "awesome-hash.h"
uint64_t hashGenerate(const char* input, size_t length) {
assert(input);
uint64_t FNV_Offset_Basis = 14695981039346656037;
uint64_t FNV_Prime = 1099511628211;
uint64_t hash = FNV_Offset_Basis; // Well apparently hash isn't a reserved word in C
for ( size_t i = 0; i < length; i++ ) {
hash = hash * FNV_Prime;
hash ^= input[i];
}
return hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment