hashfunctions

generic hash functions and PRFs: Jenkins, FNV, siphash
git clone https://noulin.net/git/hashfunctions.git
Log | Files | Refs | LICENSE

commit 2fb107d131073a145a1d4617484da038ffceec51
parent 1e6fbeed03000f36de4fc16404f6c5ca1248fd3c
Author: Remy Noulin <loader2x@gmail.com>
Date:   Wed, 22 May 2019 11:46:05 -0400

add bHashFNV1A bHashFNV1A64 for buffer fnv hash

hashfunctions.c | 26 ++++++++++++++++++++++++++
hashfunctions.h |  2 ++
package.yml     |  8 +++-----
3 files changed, 31 insertions(+), 5 deletions(-)

Diffstat:
Mhashfunctions.c | 26++++++++++++++++++++++++++
Mhashfunctions.h | 2++
Mpackage.yml | 8+++-----
3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/hashfunctions.c b/hashfunctions.c @@ -25,6 +25,32 @@ u64 strHashFNV1A64(char *k) { } /** + * FNV 1-a buffer hash. + */ +u32 bHashFNV1A(void *k, size_t size) { + u32 hash = 2166136261U; + const u8* ptr = (const u8*)k; + loop(size) { + hash = (hash ^ *ptr) * 16777619U; + ptr++; + } + return hash; +} + +/** + * FNV 1-a buffer 64 bit hash. + */ +u64 bHashFNV1A64(void *k, size_t size) { + u64 hash = 14695981039346656073ULL; + const u8* ptr = (const u8*)k; + loop(size) { + hash = (hash ^ *ptr) * 1099511628211ULL; + ptr++; + } + return hash; +} + +/** * Integer reversible hash function for 32 bits. * Implementation of the Robert Jenkins "4-byte Integer Hashing", * from http://burtleburtle.net/bob/hash/integer.html diff --git a/hashfunctions.h b/hashfunctions.h @@ -6,6 +6,8 @@ u32 strHashFNV1A(char *k); u64 strHashFNV1A64(char *k); +u32 bHashFNV1A(void *k, size_t size); +u64 bHashFNV1A64(void *k, size_t size); u32 u32Hash(u32 k); u64 u64Hash(u64 k); diff --git a/package.yml b/package.yml @@ -1,16 +1,14 @@ --- name: hashfunctions - version: 0.0.7 + version: 0.0.8 description: "generic hash functions and PRFs: Jenkins, FNV, siphash, murmur2, murmur3, md5, jump consistent hash" bin: ./hashfunctions.c cflags: "-O3 -std=gnu11 -fPIC -pipe" repository: type: git - url: "git+https://github.com/RemyNoulin/hashfunctions.git" + url: "git+https://noulin.net/git/hashfunctions.git" keywords: - hashing author: Anonymous license: MIT - bugs: - url: "https://github.com/RemyNoulin/hashfunctions/issues" - homepage: "https://github.com/RemyNoulin/hashfunctions" + homepage: "https://noulin.net/hashfunctions/log.html"