#pragma once#include <stdint.h>//fnv1a 32 and 64 bit hash functions// key is the data to hash, len is the size of the data (or how much of it to hash against)// code license: public domain or equivalent// post: https://notes.underscorediscovery.com/constexpr-fnv1a/inlineconstuint32_t hash_32_fnv1a(constvoid* key, constuint32_t len){constchar* data =(char*)key;uint32_t hash =0x811c9dc5;uint32_t prime =0x1000193;for(int i =0; i < len;++i){uint8_t value = data[i];
hash = hash ^ value;
hash *= prime;}return hash;}//hash_32_fnv1ainlineconstuint64_t hash_64_fnv1a(constvoid* key, constuint64_t len){constchar* data =(char*)key;uint64_t hash =0xcbf29ce484222325;uint64_t prime =0x100000001b3;for(int i =0; i < len;++i){uint8_t value = data[i];
hash = hash ^ value;
hash *= prime;}return hash;}//hash_64_fnv1a
cpp/hash.1562928511.txt.gz · Last modified: by allspark_ise