Created
          May 16, 2012 08:04 
        
      - 
      
- 
        Save kauppim/2708523 to your computer and use it in GitHub Desktop. 
    Implemented awesome-hash without any advanced error handling.
  
        
  
    
      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
    
  
  
    
  | #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