+2
-2
@@ -10,9 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `wpMiscUtilsRotl64` utility
|
- `wpMiscUtilsRotl64` utility
|
||||||
- `wpMur3HasherIO` to setup the MurmurHash3 IO struct
|
- `wpMur3HasherData` to setup the MurmurHash3 data struct
|
||||||
- `wpX64Mur3Hasher128` implementation for the x64 128-bit variant of the MurmurHash3 algorithm
|
- `wpX64Mur3Hasher128` implementation for the x64 128-bit variant of the MurmurHash3 algorithm
|
||||||
- `wpSip24Hasher128IO`, `wpSip48Hasher128IO`, `wpSip24Hasher64IO` and `wpSip48Hasher64IO` to setup the siphash IO structs for the different variants
|
- `wpSip24HasherData` and `wpSip48HasherData` to setup the siphash data structs for the different variants
|
||||||
- `wpSipHasher128` and `wpSipHasher64` implementation for the 128 and 64 variants of siphash
|
- `wpSipHasher128` and `wpSipHasher64` implementation for the 128 and 64 variants of siphash
|
||||||
- Add `wpU8Const`, `wpU16Const`, `wpU32Const`, `wpU64Const`, `wpI8Const`, `wpI16Const`, `wpI32Const`, and `wpI64Const`
|
- Add `wpU8Const`, `wpU16Const`, `wpU32Const`, `wpU64Const`, `wpI8Const`, `wpI16Const`, `wpI32Const`, and `wpI64Const`
|
||||||
- `wpPrngXorshiftInitWithSeed` to allow for user control with PRNG
|
- `wpPrngXorshiftInitWithSeed` to allow for user control with PRNG
|
||||||
|
|||||||
@@ -9,7 +9,35 @@
|
|||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // !WP_PLATFORM_CPP
|
#endif // !WP_PLATFORM_CPP
|
||||||
|
|
||||||
typedef void (*WpHasher)(WpU8Stream *stream, void *hasher_io);
|
typedef struct {
|
||||||
|
u64 hash[2];
|
||||||
|
} WpU128Hash;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WP_HASH_TYPE_64,
|
||||||
|
WP_HASH_TYPE_128,
|
||||||
|
|
||||||
|
COUNT_HASH_TYPES,
|
||||||
|
} WpHasherType;
|
||||||
|
|
||||||
|
typedef u64 (*WpHasher64) (WpU8Stream *stream, void *hasher_data);
|
||||||
|
typedef WpU128Hash (*WpHasher128)(WpU8Stream *stream, void *hasher_data);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
WpHasherType type;
|
||||||
|
union {
|
||||||
|
WpHasher64 hasher_64;
|
||||||
|
WpHasher128 hasher_128;
|
||||||
|
};
|
||||||
|
} WpHasher;
|
||||||
|
|
||||||
|
#ifdef WP_PLATFORM_CPP
|
||||||
|
#define wpHasher64(HASHER) (WpHasher64{ WP_HASH_TYPE_64, (HASHER) })
|
||||||
|
#define wpHasher128(HASHER) (WpHasher128{ WP_HASH_TYPE_128, (HASHER) })
|
||||||
|
#else
|
||||||
|
#define wpHasher64(HASHER) ((WpHasher64){ .type = WP_HASH_TYPE_64, .hasher_64 = (HASHER) })
|
||||||
|
#define wpHasher128(HASHER) ((WpHasher128){ .type = WP_HASH_TYPE_128, .hasher_128 = (HASHER) })
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
// vim:fileencoding=utf-8:foldmethod=marker
|
// vim:fileencoding=utf-8:foldmethod=marker
|
||||||
|
|
||||||
#include "murmur3.h"
|
#include "murmur3.h"
|
||||||
|
#include "hasher.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/assert/assert.h"
|
#include "../../../common/assert/assert.h"
|
||||||
#include "../../../common/misc/misc_utils.h"
|
#include "../../../common/misc/misc_utils.h"
|
||||||
|
|
||||||
wp_intern inline void validateIO(const WpMur3HasherIO *io);
|
wp_intern inline void validateMur3HasherData(const WpMur3HasherData *io);
|
||||||
wp_intern inline u64 fmix64(u64 k);
|
wp_intern inline u64 fmix64(u64 k);
|
||||||
|
|
||||||
void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
WpU128Hash wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
||||||
WpMur3HasherIO *io = (WpMur3HasherIO *)hasher_io;
|
WpMur3HasherData *io = (WpMur3HasherData *)hasher_io;
|
||||||
validateIO(io);
|
validateMur3HasherData(io);
|
||||||
|
|
||||||
const i32 nblocks = (bytes->count * bytes->item_size) / 16;
|
const i32 nblocks = (bytes->count * bytes->item_size) / 16;
|
||||||
|
|
||||||
@@ -91,12 +92,11 @@ void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io) {
|
|||||||
h1 += h2;
|
h1 += h2;
|
||||||
h2 += h1;
|
h2 += h1;
|
||||||
|
|
||||||
io->hash[0] = h1;
|
return (WpU128Hash){ .hash = { [0] = h1, [1] = h2 } };
|
||||||
io->hash[1] = h2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern inline void validateIO(const WpMur3HasherIO *io) {
|
wp_intern inline void validateMur3HasherData(const WpMur3HasherData *data) {
|
||||||
wpRuntimeAssert(io->magic == WP_MUR3_HASHER_MAGIC, "Invalid Murmur3 hash IO");
|
wpRuntimeAssert(data->magic == WP_MUR3_HASHER_MAGIC, "Invalid Murmur3 hash data");
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern inline u64 fmix64(u64 k) {
|
wp_intern inline u64 fmix64(u64 k) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifndef MURMUR3_H
|
#ifndef MURMUR3_H
|
||||||
#define MURMUR3_H
|
#define MURMUR3_H
|
||||||
|
|
||||||
|
#include "hasher.h"
|
||||||
#include "../../stream/stream.h"
|
#include "../../stream/stream.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/platform/platform.h"
|
#include "../../../common/platform/platform.h"
|
||||||
@@ -19,18 +20,17 @@ BEGIN_C_LINKAGE
|
|||||||
#define WP_MUR3_HASHER_MAGIC wpU64Const(0x57504d4841534833)
|
#define WP_MUR3_HASHER_MAGIC wpU64Const(0x57504d4841534833)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 hash[2];
|
|
||||||
u64 magic;
|
u64 magic;
|
||||||
u32 seed;
|
u32 seed;
|
||||||
} WpMur3HasherIO;
|
} WpMur3HasherData;
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
#define wpMur3HasherIO(SEED) (WpMur3HasherIO{{}, WP_MUR3_HASHER_MAGIC, SEED})
|
#define wpMur3HasherData(SEED) (WpMur3HasherData{WP_MUR3_HASHER_MAGIC, SEED})
|
||||||
#else
|
#else
|
||||||
#define wpMur3HasherIO(SEED) ((WpMur3HasherIO){ .magic = WP_MUR3_HASHER_MAGIC, .seed = SEED })
|
#define wpMur3HasherData(SEED) ((WpMur3HasherData){ .magic = WP_MUR3_HASHER_MAGIC, .seed = SEED })
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io);
|
WpU128Hash wpX64Mur3Hasher128(WpU8Stream *bytes, void *hasher_io);
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
// vim:fileencoding=utf-8:foldmethod=marker
|
// vim:fileencoding=utf-8:foldmethod=marker
|
||||||
|
|
||||||
#include "siphash.h"
|
#include "siphash.h"
|
||||||
|
#include "hasher.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/assert/assert.h"
|
#include "../../../common/assert/assert.h"
|
||||||
#include "../../../common/misc/misc_utils.h"
|
#include "../../../common/misc/misc_utils.h"
|
||||||
|
|
||||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out, u64 outlen);
|
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8 *out, u64 outlen);
|
||||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io);
|
wp_intern inline void validateSipHasherData(const WpSipHasherData *io);
|
||||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io);
|
wp_intern inline b8 checkRounds(const WpSipHasherData *params);
|
||||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params);
|
|
||||||
|
|
||||||
#define _u32To8LE(p, v) \
|
#define _u32To8LE(p, v) \
|
||||||
(p)[0] = (u8)((v)); \
|
(p)[0] = (u8)((v)); \
|
||||||
@@ -44,19 +44,23 @@ wp_intern inline b8 checkRounds(const WpSipHasherParams *params);
|
|||||||
v2 = wpMiscUtilsRotl64(v2, 32); \
|
v2 = wpMiscUtilsRotl64(v2, 32); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
void wpSipHasher128(WpStream *bytes, void *hasher_io) {
|
WpU128Hash wpSipHasher128(WpStream *bytes, void *hasher_data) {
|
||||||
WpSipHasher128IO *io = (WpSipHasher128IO *)hasher_io;
|
WpSipHasherData *data = (WpSipHasherData *)hasher_data;
|
||||||
validate128IO(io);
|
validateSipHasherData(data);
|
||||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64) * 2);
|
WpU128Hash output = {0};
|
||||||
|
siphash(bytes, data, (u8 *)&output.hash, sizeof(u64) * 2);
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wpSipHasher64(WpStream *bytes, void *hasher_io) {
|
u64 wpSipHasher64(WpStream *bytes, void *hasher_data) {
|
||||||
WpSipHasher64IO *io = (WpSipHasher64IO *)hasher_io;
|
WpSipHasherData *data = (WpSipHasherData *)hasher_data;
|
||||||
validate64IO(io);
|
validateSipHasherData(data);
|
||||||
siphash(bytes, &io->params, (u8 *)&io->hash, sizeof(u64));
|
u64 output = 0;
|
||||||
|
siphash(bytes, data, (u8 *)&output, sizeof(u64));
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params, u8 *out,
|
wp_intern inline void siphash(WpStream *bytes, const WpSipHasherData *params, u8 *out,
|
||||||
u64 outlen) {
|
u64 outlen) {
|
||||||
const u8 *kk = (const u8 *)¶ms->key;
|
const u8 *kk = (const u8 *)¶ms->key;
|
||||||
u64 inlen = bytes->count * bytes->item_size;
|
u64 inlen = bytes->count * bytes->item_size;
|
||||||
@@ -157,20 +161,14 @@ wp_intern inline void siphash(WpStream *bytes, const WpSipHasherParams *params,
|
|||||||
_u64To8LE(out + 8, b);
|
_u64To8LE(out + 8, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern inline void validate128IO(const WpSipHasher128IO *io) {
|
wp_intern inline void validateSipHasherData(const WpSipHasherData *data) {
|
||||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_128_MAGIC;
|
b8 magic_match = data->magic == WP_SIP_HASHER_MAGIC;
|
||||||
b8 rounds = checkRounds(&io->params);
|
b8 rounds = checkRounds(data);
|
||||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 128 IO");
|
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash data");
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_intern inline void validate64IO(const WpSipHasher64IO *io) {
|
wp_intern inline b8 checkRounds(const WpSipHasherData *data) {
|
||||||
b8 magic_match = io->params.magic == WP_SIP_HASHER_64_MAGIC;
|
b8 rounds24 = data->compression == 2 && data->finalisation == 4;
|
||||||
b8 rounds = checkRounds(&io->params);
|
b8 rounds48 = data->compression == 4 && data->finalisation == 8;
|
||||||
wpRuntimeAssert(magic_match && rounds, "Invalid Siphash 64 IO");
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_intern inline b8 checkRounds(const WpSipHasherParams *params) {
|
|
||||||
b8 rounds24 = params->compression == 2 && params->finalisation == 4;
|
|
||||||
b8 rounds48 = params->compression == 4 && params->finalisation == 8;
|
|
||||||
return rounds24 || rounds48;
|
return rounds24 || rounds48;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#ifndef SIPHASH_H
|
#ifndef SIPHASH_H
|
||||||
#define SIPHASH_H
|
#define SIPHASH_H
|
||||||
|
|
||||||
|
#include "hasher.h"
|
||||||
#include "../../stream/stream.h"
|
#include "../../stream/stream.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
#include "../../../common/platform/platform.h"
|
#include "../../../common/platform/platform.h"
|
||||||
@@ -16,8 +17,7 @@
|
|||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // !WP_PLATFORM_CPP
|
#endif // !WP_PLATFORM_CPP
|
||||||
|
|
||||||
#define WP_SIP_HASHER_128_MAGIC wpU64Const(0x5750534950313238)
|
#define WP_SIP_HASHER_MAGIC wpU64Const(0x5750534950485348)
|
||||||
#define WP_SIP_HASHER_64_MAGIC wpU64Const(0x57505349503634)
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 lo;
|
u64 lo;
|
||||||
@@ -29,72 +29,28 @@ typedef struct {
|
|||||||
u64 magic;
|
u64 magic;
|
||||||
u64 compression;
|
u64 compression;
|
||||||
u64 finalisation;
|
u64 finalisation;
|
||||||
} WpSipHasherParams;
|
} WpSipHasherData;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
WpSipHasherParams params;
|
|
||||||
u64 hash[2];
|
|
||||||
} WpSipHasher128IO;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
WpSipHasherParams params;
|
|
||||||
u64 hash;
|
|
||||||
} WpSipHasher64IO;
|
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
#define wpSip24Hasher128IO(KEY) (WpSipHasher128IO{ \
|
#define wpSip24HasherData(KEY) (WpSipHasherData{KEY, WP_SIP_HASHER_MAGIC, 2, 4})
|
||||||
WpSipHasherParams{KEY, WP_SIP_HASHER_128_MAGIC, 2, 4}, \
|
#define wpSip48HasherData(KEY) (WpSipHasherData{KEY, WP_SIP_HASHER_MAGIC, 4, 8})
|
||||||
{}, \
|
|
||||||
})
|
|
||||||
#define wpSip48Hasher128IO(KEY) (WpSipHasher128IO{ \
|
|
||||||
WpSipHasherParams{KEY, WP_SIP_HASHER_128_MAGIC, 4, 8}, \
|
|
||||||
{}, \
|
|
||||||
})
|
|
||||||
#define wpSip24Hasher64IO(KEY) (WpSipHasher64IO{ \
|
|
||||||
WpSipHasherParams{KEY, WP_SIP_HASHER_64_MAGIC, 2, 4}, \
|
|
||||||
0, \
|
|
||||||
})
|
|
||||||
#define wpSip48Hasher64IO(KEY) (WpSipHasher64IO{ \
|
|
||||||
WpSipHasherParams{KEY, WP_SIP_HASHER_64_MAGIC, 4, 8}, \
|
|
||||||
0, \
|
|
||||||
})
|
|
||||||
#else
|
#else
|
||||||
#define wpSip24Hasher128IO(KEY) ((WpSipHasher128IO){ \
|
#define wpSip24HasherData(KEY) ((WpSipHasherData){ \
|
||||||
.params = (WpSipHasherParams){ \
|
|
||||||
.key = KEY, \
|
.key = KEY, \
|
||||||
.magic = WP_SIP_HASHER_128_MAGIC, \
|
.magic = WP_SIP_HASHER_MAGIC, \
|
||||||
.compression = 2, \
|
.compression = 2, \
|
||||||
.finalisation = 4, \
|
.finalisation = 4, \
|
||||||
} \
|
|
||||||
})
|
})
|
||||||
#define wpSip48Hasher128IO(KEY) ((WpSipHasher128IO){ \
|
#define wpSip48HasherData(KEY) ((WpSipHasherData){ \
|
||||||
.params = (WpSipHasherParams){ \
|
|
||||||
.key = KEY, \
|
.key = KEY, \
|
||||||
.magic = WP_SIP_HASHER_128_MAGIC, \
|
.magic = WP_SIP_HASHER_MAGIC, \
|
||||||
.compression = 4, \
|
.compression = 4, \
|
||||||
.finalisation = 8, \
|
.finalisation = 8, \
|
||||||
} \
|
|
||||||
})
|
|
||||||
#define wpSip24Hasher64IO(KEY) ((WpSipHasher64IO){ \
|
|
||||||
.params = (WpSipHasherParams){ \
|
|
||||||
.key = KEY, \
|
|
||||||
.magic = WP_SIP_HASHER_64_MAGIC, \
|
|
||||||
.compression = 2, \
|
|
||||||
.finalisation = 4, \
|
|
||||||
} \
|
|
||||||
})
|
|
||||||
#define wpSip48Hasher64IO(KEY) ((WpSipHasher64IO){ \
|
|
||||||
.params = (WpSipHasherParams){ \
|
|
||||||
.key = KEY, \
|
|
||||||
.magic = WP_SIP_HASHER_64_MAGIC, \
|
|
||||||
.compression = 4, \
|
|
||||||
.finalisation = 8, \
|
|
||||||
} \
|
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void wpSipHasher128(WpU8Stream *bytes, void *hasher_io);
|
WpU128Hash wpSipHasher128(WpU8Stream *bytes, void *hasher_io);
|
||||||
void wpSipHasher64(WpU8Stream *bytes, void *hasher_io);
|
u64 wpSipHasher64(WpU8Stream *bytes, void *hasher_io);
|
||||||
|
|
||||||
#ifdef WP_PLATFORM_CPP
|
#ifdef WP_PLATFORM_CPP
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
|||||||
+30
-30
@@ -12,7 +12,7 @@ WpTestFuncResult test_murmur3(void) {
|
|||||||
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
|
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
|
||||||
u64 num = 287324;
|
u64 num = 287324;
|
||||||
|
|
||||||
WpMur3HasherIO io = wpMur3HasherIO(873923);
|
WpMur3HasherData data = wpMur3HasherData(873923);
|
||||||
|
|
||||||
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
||||||
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
||||||
@@ -21,22 +21,22 @@ WpTestFuncResult test_murmur3(void) {
|
|||||||
u64 hash[2] = {0};
|
u64 hash[2] = {0};
|
||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
wpX64Mur3Hasher128(&str_bytes, (void *)&io);
|
WpU128Hash mur_hash = wpX64Mur3Hasher128(&str_bytes, (void *)&data);
|
||||||
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, io.seed, (void *)hash);
|
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, data.seed, (void *)hash);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && mur_hash.hash[0] == hash[0] && mur_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
wpX64Mur3Hasher128(&arr_bytes, (void *)&io);
|
mur_hash = wpX64Mur3Hasher128(&arr_bytes, (void *)&data);
|
||||||
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, io.seed, (void *)hash);
|
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, data.seed, (void *)hash);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && mur_hash.hash[0] == hash[0] && mur_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
wpX64Mur3Hasher128(&num_bytes, (void *)&io);
|
mur_hash = wpX64Mur3Hasher128(&num_bytes, (void *)&data);
|
||||||
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, io.seed, (void *)hash);
|
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, data.seed, (void *)hash);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && mur_hash.hash[0] == hash[0] && mur_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
return wpTesterResult(result);
|
return wpTesterResult(result);
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ WpTestFuncResult test_siphash_128(void) {
|
|||||||
u64 num = 287324;
|
u64 num = 287324;
|
||||||
|
|
||||||
WpSipHasherKey key = { .lo = 238742, .hi = 671734 };
|
WpSipHasherKey key = { .lo = 238742, .hi = 671734 };
|
||||||
WpSipHasher128IO io = wpSip24Hasher128IO(key);
|
WpSipHasherData data = wpSip24HasherData(key);
|
||||||
|
|
||||||
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
||||||
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
||||||
@@ -58,25 +58,25 @@ WpTestFuncResult test_siphash_128(void) {
|
|||||||
u64 hash[2] = {0};
|
u64 hash[2] = {0};
|
||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
wpSipHasher128(&str_bytes, (void *)&io);
|
WpU128Hash sip_hash = wpSipHasher128(&str_bytes, (void *)&data);
|
||||||
siphash(str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&io.params.key,
|
siphash(str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)hash, sizeof(u64) * 2);
|
(u8 *)hash, sizeof(u64) * 2);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && sip_hash.hash[0] == hash[0] && sip_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
wpSipHasher128(&arr_bytes, (void *)&io);
|
sip_hash = wpSipHasher128(&arr_bytes, (void *)&data);
|
||||||
siphash(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&io.params.key,
|
siphash(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)hash, sizeof(u64) * 2);
|
(u8 *)hash, sizeof(u64) * 2);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && sip_hash.hash[0] == hash[0] && sip_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
wpSipHasher128(&num_bytes, (void *)&io);
|
sip_hash = wpSipHasher128(&num_bytes, (void *)&data);
|
||||||
siphash(num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&io.params.key,
|
siphash(num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)hash, sizeof(u64) * 2);
|
(u8 *)hash, sizeof(u64) * 2);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && sip_hash.hash[0] == hash[0] && sip_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
return wpTesterResult(result);
|
return wpTesterResult(result);
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ WpTestFuncResult test_siphash_64(void) {
|
|||||||
u64 num = 287324;
|
u64 num = 287324;
|
||||||
|
|
||||||
WpSipHasherKey key = { .lo = 238742, .hi = 671734 };
|
WpSipHasherKey key = { .lo = 238742, .hi = 671734 };
|
||||||
WpSipHasher64IO io = wpSip24Hasher64IO(key);
|
WpSipHasherData data = wpSip24HasherData(key);
|
||||||
|
|
||||||
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
||||||
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
||||||
@@ -98,25 +98,25 @@ WpTestFuncResult test_siphash_64(void) {
|
|||||||
u64 hash = {0};
|
u64 hash = {0};
|
||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
wpSipHasher64(&str_bytes, (void *)&io);
|
u64 sip_hash = wpSipHasher64(&str_bytes, (void *)&data);
|
||||||
siphash(str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&io.params.key,
|
siphash(str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)&hash, sizeof(u64));
|
(u8 *)&hash, sizeof(u64));
|
||||||
|
|
||||||
result = result && io.hash == hash;
|
result = result && sip_hash == hash;
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
wpSipHasher64(&arr_bytes, (void *)&io);
|
sip_hash = wpSipHasher64(&arr_bytes, (void *)&data);
|
||||||
siphash(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&io.params.key,
|
siphash(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)&hash, sizeof(u64));
|
(u8 *)&hash, sizeof(u64));
|
||||||
|
|
||||||
result = result && io.hash == hash;
|
result = result && sip_hash == hash;
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
wpSipHasher64(&num_bytes, (void *)&io);
|
sip_hash = wpSipHasher64(&num_bytes, (void *)&data);
|
||||||
siphash(num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&io.params.key,
|
siphash(num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)&hash, sizeof(u64));
|
(u8 *)&hash, sizeof(u64));
|
||||||
|
|
||||||
result = result && io.hash == hash;
|
result = result && sip_hash == hash;
|
||||||
|
|
||||||
return wpTesterResult(result);
|
return wpTesterResult(result);
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-30
@@ -12,7 +12,7 @@ WpTestFuncResult test_murmur3(void) {
|
|||||||
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
|
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
|
||||||
u64 num = 287324;
|
u64 num = 287324;
|
||||||
|
|
||||||
WpMur3HasherIO io = wpMur3HasherIO(873923);
|
WpMur3HasherData data = wpMur3HasherData(873923);
|
||||||
|
|
||||||
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
||||||
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
||||||
@@ -21,22 +21,22 @@ WpTestFuncResult test_murmur3(void) {
|
|||||||
u64 hash[2] = {0};
|
u64 hash[2] = {0};
|
||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
wpX64Mur3Hasher128(&str_bytes, (void *)&io);
|
WpU128Hash mur_hash = wpX64Mur3Hasher128(&str_bytes, (void *)&data);
|
||||||
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, io.seed, (void *)hash);
|
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, data.seed, (void *)hash);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && mur_hash.hash[0] == hash[0] && mur_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
wpX64Mur3Hasher128(&arr_bytes, (void *)&io);
|
mur_hash = wpX64Mur3Hasher128(&arr_bytes, (void *)&data);
|
||||||
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, io.seed, (void *)hash);
|
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, data.seed, (void *)hash);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && mur_hash.hash[0] == hash[0] && mur_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
wpX64Mur3Hasher128(&num_bytes, (void *)&io);
|
mur_hash = wpX64Mur3Hasher128(&num_bytes, (void *)&data);
|
||||||
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, io.seed, (void *)hash);
|
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, data.seed, (void *)hash);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && mur_hash.hash[0] == hash[0] && mur_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
return wpTesterResult(result);
|
return wpTesterResult(result);
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ WpTestFuncResult test_siphash_128(void) {
|
|||||||
u64 num = 287324;
|
u64 num = 287324;
|
||||||
|
|
||||||
WpSipHasherKey key = { 238742, 671734 };
|
WpSipHasherKey key = { 238742, 671734 };
|
||||||
WpSipHasher128IO io = wpSip24Hasher128IO(key);
|
WpSipHasherData data = wpSip24HasherData(key);
|
||||||
|
|
||||||
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
||||||
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
||||||
@@ -58,25 +58,25 @@ WpTestFuncResult test_siphash_128(void) {
|
|||||||
u64 hash[2] = {0};
|
u64 hash[2] = {0};
|
||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
wpSipHasher128(&str_bytes, (void *)&io);
|
WpU128Hash sip_hash = wpSipHasher128(&str_bytes, (void *)&data);
|
||||||
siphash((void *)str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&io.params.key,
|
siphash(str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)hash, sizeof(u64) * 2);
|
(u8 *)hash, sizeof(u64) * 2);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && sip_hash.hash[0] == hash[0] && sip_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
wpSipHasher128(&arr_bytes, (void *)&io);
|
sip_hash = wpSipHasher128(&arr_bytes, (void *)&data);
|
||||||
siphash((void *)arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&io.params.key,
|
siphash(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)hash, sizeof(u64) * 2);
|
(u8 *)hash, sizeof(u64) * 2);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && sip_hash.hash[0] == hash[0] && sip_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
wpSipHasher128(&num_bytes, (void *)&io);
|
sip_hash = wpSipHasher128(&num_bytes, (void *)&data);
|
||||||
siphash((void *)num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&io.params.key,
|
siphash(num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)hash, sizeof(u64) * 2);
|
(u8 *)hash, sizeof(u64) * 2);
|
||||||
|
|
||||||
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
result = result && sip_hash.hash[0] == hash[0] && sip_hash.hash[1] == hash[1];
|
||||||
|
|
||||||
return wpTesterResult(result);
|
return wpTesterResult(result);
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ WpTestFuncResult test_siphash_64(void) {
|
|||||||
u64 num = 287324;
|
u64 num = 287324;
|
||||||
|
|
||||||
WpSipHasherKey key = { 238742, 671734 };
|
WpSipHasherKey key = { 238742, 671734 };
|
||||||
WpSipHasher64IO io = wpSip24Hasher64IO(key);
|
WpSipHasherData data = wpSip24HasherData(key);
|
||||||
|
|
||||||
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
||||||
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
||||||
@@ -98,25 +98,25 @@ WpTestFuncResult test_siphash_64(void) {
|
|||||||
u64 hash = {0};
|
u64 hash = {0};
|
||||||
|
|
||||||
// Sring hash
|
// Sring hash
|
||||||
wpSipHasher64(&str_bytes, (void *)&io);
|
u64 sip_hash = wpSipHasher64(&str_bytes, (void *)&data);
|
||||||
siphash((void *)str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&io.params.key,
|
siphash(str_bytes.data, str_bytes.count * str_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)&hash, sizeof(u64));
|
(u8 *)&hash, sizeof(u64));
|
||||||
|
|
||||||
result = result && io.hash == hash;
|
result = result && sip_hash == hash;
|
||||||
|
|
||||||
// Array hash
|
// Array hash
|
||||||
wpSipHasher64(&arr_bytes, (void *)&io);
|
sip_hash = wpSipHasher64(&arr_bytes, (void *)&data);
|
||||||
siphash((void *)arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&io.params.key,
|
siphash(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)&hash, sizeof(u64));
|
(u8 *)&hash, sizeof(u64));
|
||||||
|
|
||||||
result = result && io.hash == hash;
|
result = result && sip_hash == hash;
|
||||||
|
|
||||||
// Number hash
|
// Number hash
|
||||||
wpSipHasher64(&num_bytes, (void *)&io);
|
sip_hash = wpSipHasher64(&num_bytes, (void *)&data);
|
||||||
siphash((void *)num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&io.params.key,
|
siphash(num_bytes.data, num_bytes.count * num_bytes.item_size, (void *)&data.key,
|
||||||
(u8 *)&hash, sizeof(u64));
|
(u8 *)&hash, sizeof(u64));
|
||||||
|
|
||||||
result = result && io.hash == hash;
|
result = result && sip_hash == hash;
|
||||||
|
|
||||||
return wpTesterResult(result);
|
return wpTesterResult(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user