42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
// vim:fileencoding=utf-8:foldmethod=marker
|
|
|
|
#include "test_hasher.h"
|
|
#include "MurmurHash3.h"
|
|
#include "wapp.h"
|
|
|
|
WpTestFuncResult test_murmur3(void) {
|
|
b8 result = true;
|
|
|
|
WpStr8 str = wpStr8Lit("Hello world");
|
|
WpI32Array arr = wpArray(i32, 1, 2, 3, 4, 5);
|
|
u64 num = 287324;
|
|
|
|
WpMur3HasherIO io = wpMur3HasherIO(873923);
|
|
|
|
WpU8Stream str_bytes = wpStream(u8, str.buf, str.size);
|
|
WpU8Stream arr_bytes = wpStream(u8, (u8 *)arr, wpArrayCount(arr) * wpArrayItemSize(arr));
|
|
WpU8Stream num_bytes = wpStream(u8, (u8 *)&num, sizeof(u64));
|
|
|
|
u64 hash[2] = {0};
|
|
|
|
// Sring hash
|
|
wpX64Mur3Hasher128(&str_bytes, (void *)&io);
|
|
MurmurHash3_x64_128(str_bytes.data, str_bytes.count * str_bytes.item_size, io.seed, (void *)hash);
|
|
|
|
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
|
|
|
// Array hash
|
|
wpX64Mur3Hasher128(&arr_bytes, (void *)&io);
|
|
MurmurHash3_x64_128(arr_bytes.data, arr_bytes.count * arr_bytes.item_size, io.seed, (void *)hash);
|
|
|
|
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
|
|
|
// Number hash
|
|
wpX64Mur3Hasher128(&num_bytes, (void *)&io);
|
|
MurmurHash3_x64_128(num_bytes.data, num_bytes.count * num_bytes.item_size, io.seed, (void *)hash);
|
|
|
|
result = result && io.hash[0] == hash[0] && io.hash[1] == hash[1];
|
|
|
|
return wpTesterResult(result);
|
|
}
|