This commit is contained in:
@@ -5,22 +5,34 @@
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/assert/assert.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
#include "../../../prng/xorshift/xorshift.h"
|
||||
|
||||
wp_intern inline void validateMur3HasherCtx(const WpMur3HasherCtx *io);
|
||||
wp_intern inline void validateMur3HasherCtx(const WpHasherCtx *ctx);
|
||||
wp_intern inline u64 fmix64(u64 k);
|
||||
|
||||
WpHasher wpX64Mur3Hasher(WpMur3HasherCtx *data) {
|
||||
return (WpHasher){ .func = wpX64Mur3Hasher128, .data = (void *)data };
|
||||
WpHasher wpX64Mur3Hasher(void) {
|
||||
WpXor256State state = wpPrngXorshiftInit();
|
||||
u32 seed = (u32)wpPrngXorshift256(&state);
|
||||
return wpX64Mur3HasherWithSeed(seed);
|
||||
}
|
||||
|
||||
WpU128Hash wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
WpMur3HasherCtx *io = (WpMur3HasherCtx *)hasher_io;
|
||||
validateMur3HasherCtx(io);
|
||||
WpHasher wpX64Mur3HasherWithSeed(u32 seed) {
|
||||
return (WpHasher){
|
||||
.func = wpX64Mur3GetHash128,
|
||||
.ctx = (WpHasherCtx){
|
||||
.type = WP_HASHER_CTX_MURMUR3,
|
||||
.murmur3 = seed,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
WpU128 wpX64Mur3GetHash128(WpU8Stream *bytes, WpHasherCtx ctx) {
|
||||
validateMur3HasherCtx(&ctx);
|
||||
|
||||
const i32 nblocks = (bytes->count * bytes->item_size) / 16;
|
||||
|
||||
u64 h1 = io->seed;
|
||||
u64 h2 = io->seed;
|
||||
u64 h1 = ctx.murmur3;
|
||||
u64 h2 = ctx.murmur3;
|
||||
|
||||
const u64 c1 = wpU64Const(0x87c37b91114253d5);
|
||||
const u64 c2 = wpU64Const(0x4cf5ad432745937f);
|
||||
@@ -96,11 +108,11 @@ WpU128Hash wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||
h1 += h2;
|
||||
h2 += h1;
|
||||
|
||||
return (WpU128Hash){ .hash = { [0] = h1, [1] = h2 } };
|
||||
return (WpU128){ .value = { [0] = h1, [1] = h2 } };
|
||||
}
|
||||
|
||||
wp_intern inline void validateMur3HasherCtx(const WpMur3HasherCtx *ctx) {
|
||||
wpRuntimeAssert(ctx->magic == WP_MUR3_HASHER_MAGIC, "Invalid Murmur3 hash context");
|
||||
wp_intern inline void validateMur3HasherCtx(const WpHasherCtx *ctx) {
|
||||
wpRuntimeAssert(ctx->type == WP_HASHER_CTX_MURMUR3, "Invalid Murmur3 hash context");
|
||||
}
|
||||
|
||||
wp_intern inline u64 fmix64(u64 k) {
|
||||
|
||||
Reference in New Issue
Block a user