Last active
April 13, 2025 12:25
-
-
Save DaseinPhaos/ff0059bd32995f4504b7e9c608ee62ba to your computer and use it in GitHub Desktop.
Port of [polymur-hash](https://github.com/orlp/polymur-hash) in JAI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A simple port of polymur-hash into JAI. | |
| /* | |
| PolymurHash version 2.0 | |
| Copyright (c) 2023 Orson Peters | |
| This software is provided 'as-is', without any express or implied warranty. In | |
| no event will the authors be held liable for any damages arising from the use of | |
| this software. | |
| Permission is granted to anyone to use this software for any purpose, including | |
| commercial applications, and to alter it and redistribute it freely, subject to | |
| the following restrictions: | |
| 1. The origin of this software must not be misrepresented; you must not claim | |
| that you wrote the original software. If you use this software in a product, | |
| an acknowledgment in the product documentation would be appreciated but is | |
| not required. | |
| 2. Altered source versions must be plainly marked as such, and must not be | |
| misrepresented as being the original software. | |
| 3. This notice may not be removed or altered from any source distribution. | |
| */ | |
| // ---------- PolymurHash public API ---------- | |
| HashParams :: struct { // the defaults are precomputed from init_params_from_seed(0) | |
| k: u64=1472835858483279345; | |
| k2:u64=157013146407168452; | |
| k7:u64=1077430455308857634; | |
| s: u64=17604609809052898104; | |
| } | |
| // Expands a 64-bit or 128-bit seed to a set of parameters for hash evaluation. | |
| init_params :: (p: *HashParams, k_seed: u64, s_seed: u64) { | |
| p.s = s_seed ^ ARBITRARY1; // People love to pass zero. | |
| // POW37[i] = 37^(2^i) mod (2^61 - 1) | |
| // Could be replaced by a 512 byte LUT, costs ~400 byte overhead but 2x | |
| // faster seeding. However, seeding is rather rare, so I chose not to. | |
| POW37: [64]u64; | |
| POW37[0] = 37; POW37[32] = (559096694736811184).(u64); | |
| for i: 0..30 { | |
| POW37[i+ 1] = extrared611(red611(mul128(POW37[i], POW37[i]))); | |
| POW37[i+33] = extrared611(red611(mul128(POW37[i+32], POW37[i+32]))); | |
| } | |
| while true { | |
| // Choose a random exponent coprime to 2^61 - 2. ~35.3% success rate. | |
| k_seed += ARBITRARY2; | |
| e := (k_seed >> 3) | (1).(u64); // e < 2^61, odd. | |
| if e % 3 == 0 continue; | |
| if !((e % 5) && (e % 7)) continue; | |
| if !((e % 11) && (e % 13) && (e % 31)) continue; | |
| if !((e % 41) && (e % 61) && (e % 151) && (e % 331) && (e % 1321)) continue; | |
| // Compute k = 37^e mod 2^61 - 1. Since e is coprime with the order of | |
| // the multiplicative group mod 2^61 - 1 and 37 is a generator, this | |
| // results in another generator of the group. | |
| ka :u64= 1; | |
| kb :u64= 1; | |
| i := 0; | |
| while e { defer {i+=2; e>>=2;} | |
| if (e & 1) ka = extrared611(red611(mul128(ka, POW37[i]))); | |
| if (e & 2) kb = extrared611(red611(mul128(kb, POW37[i+1]))); | |
| } | |
| k := extrared611(red611(mul128(ka, kb))); | |
| // ~46.875% success rate. Bound on k^7 needed for efficient reduction. | |
| p.k = extrared611(k); | |
| p.k2= extrared611(red611(mul128(p.k, p.k))); | |
| k3 := red611(mul128(p.k, p.k2)); | |
| k4 := red611(mul128(p.k2, p.k2)); | |
| p.k7= extrared611(red611(mul128(k3, k4))); | |
| if (p.k7 < ((1).(u64) << 60) - ((1).(u64) << 56)) break; | |
| // Our key space is log2(totient(2^61 - 2) * (2^60-2^56)/2^61) ~= 57.4 bits. | |
| } | |
| } | |
| init_params_from_seed :: inline (p: *HashParams, seed: u64) { | |
| init_params(p, mix(seed + ARBITRARY3), mix(seed + ARBITRARY4)); | |
| } | |
| // Computes the full hash of buf. The tweak is added to the hash before final | |
| // mixing, allowing different outputs much faster than re-seeding. No claims are | |
| // made about the collision probability between hashes with different tweaks. | |
| hash :: (bytes: string, p: HashParams, tweak: u64) -> u64 { | |
| h := hash_poly611(bytes.data, xx bytes.count, p, tweak, default_advance_buffer_callback, null); | |
| return mix(h) + p.s; | |
| } | |
| hash :: (bytes: []u8, p: HashParams, tweak: u64) -> u64 { | |
| h := hash_poly611(bytes.data, xx bytes.count, p, tweak, default_advance_buffer_callback, null); | |
| return mix(h) + p.s; | |
| } | |
| // Computes the hash of file starting from current position. | |
| // The tweak is added to the hash before final mixing, | |
| // allowing different outputs much faster than re-seeding. No claims are | |
| // made about the collision probability between hashes with different tweaks. | |
| // TODO: error handling in this needs to be more robust. | |
| hash :: (file: File, p: HashParams, tweak: u64, max_bytes_to_read:s64=0x7fff_ffff_ffff_ffff) -> u64 { | |
| CachedFile :: struct { | |
| hdl: File; | |
| cache: []u8; | |
| end_from_cache_start: s64; | |
| }; | |
| cf:= CachedFile.{hdl=file}; | |
| fl, ok := file_length(file); | |
| assert(ok); | |
| fp:, ok = file_current_position(file); | |
| assert(ok); | |
| cf.end_from_cache_start = min(fl-fp, max_bytes_to_read); | |
| cache_size := min(cf.end_from_cache_start, 0x80_0000); // read in 8mb chunks, perhaps? | |
| cf.cache = NewArray(cache_size, u8,, temp); | |
| bytes_read: s64; | |
| ok, bytes_read = file_read(file, cf.cache.data, cf.cache.count); | |
| assert(ok); | |
| assert(bytes_read == cf.cache.count); | |
| // advance buffer by `toAdvance`, also ensuring min(len, 64) bytes directly addressable | |
| // after advancing | |
| advance_buffer_callback :: (data: *void, buf: *u8, len: u64, _toAdvance: u64) -> (*u8, u64) { | |
| cf := data.(*CachedFile); | |
| pos_in_cache := buf - cf.cache.data; | |
| toAdvance := _toAdvance.(s64,no_check); | |
| assert(pos_in_cache+len.(s64,no_check) == cf.end_from_cache_start); | |
| // these should be guaranteed by the caller. | |
| assert(pos_in_cache+toAdvance <= cf.cache.count); | |
| assert(len >= _toAdvance); | |
| pos_in_cache += toAdvance; | |
| len -= _toAdvance; | |
| directAddressableBytesNeeded := min(len.(s64,no_check), 64); | |
| if pos_in_cache + directAddressableBytesNeeded > cf.cache.count { | |
| // need to read more from the underlying file. | |
| // first, move cached tail to the start of the file | |
| tail := cf.cache.count-pos_in_cache; | |
| if tail > 0 { | |
| memcpy(cf.cache.data, buf+toAdvance, tail); | |
| } | |
| bytesToRead := min(cf.cache.count-tail, cf.end_from_cache_start-cf.cache.count); | |
| dstToRead := cf.cache.data+tail; | |
| ok, bytesRead := file_read(cf.hdl, dstToRead, bytesToRead); | |
| assert(ok); | |
| assert(bytesRead == bytesToRead); | |
| cf.end_from_cache_start -= cf.cache.count-tail; | |
| buf = cf.cache.data; | |
| } else { | |
| buf += toAdvance; | |
| } | |
| return buf, len; | |
| } | |
| h := hash_poly611(cf.cache.data, xx cf.end_from_cache_start, p, tweak, advance_buffer_callback, *cf); | |
| return mix(h) + p.s; | |
| } | |
| #scope_file | |
| // ---------- Cross-platform compatibility ---------- | |
| LIKELY :: (x: $T) -> bool #expand {return (!!(x));} | |
| UNLIKELY :: (x: $T) -> bool #expand {return (!!(x));} | |
| is_little_endian :: inline () -> bool { | |
| v := 1; | |
| return (*v).(*u8).* == 1; | |
| } | |
| bswap32 :: inline (v: u32) -> u32 { | |
| return ((v >> 24) & 0x000000ff) | ((v >> 8) & 0x0000ff00) | ((v << 8) & 0x00ff0000) | ((v << 24) & 0xff000000); | |
| } | |
| bswap64 :: inline (v: u64) -> u64 { | |
| return (bswap32(v.(u32,trunc)).(u64) << 32) | bswap32((v >> 32).(u32,trunc)); | |
| } | |
| load_le_u32 :: inline (p: *u8) -> u32 { | |
| v :u32= 0; | |
| memcpy(*v, p, 4); | |
| return #ifx #run is_little_endian() then v else bswap32(v); | |
| } | |
| load_le_u64 :: inline (p: *u8) -> u64 { | |
| v :u64= 0; | |
| memcpy(*v, p, 8); | |
| return #ifx #run is_little_endian() then v else bswap64(v); | |
| } | |
| // Loads 0 to 8 bytes from buf with length len as a 64-bit little-endian integer. | |
| load_le_u64_0_8 :: inline (buf: *u8, len: u64) -> u64 { | |
| if (len < 4) { | |
| if (len == 0) return 0; | |
| v :u64= buf[0]; | |
| v |= buf[len / 2].(u64) << (8 * (len / 2)); | |
| v |= buf[len - 1].(u64) << (8 * (len - 1)); | |
| return v; | |
| } | |
| lo := load_le_u32(buf); | |
| hi := load_le_u32(buf + len - 4).(u64); | |
| return lo | (hi << (8 * (len - 4))); | |
| } | |
| // ---------- Integer arithmetic ---------- | |
| P611 :u64: (((1).(u64) << 61) - 1); | |
| u128_t :: struct { | |
| lo: u64; | |
| hi: u64; | |
| } | |
| add128 :: (_a: u128_t, b: u128_t) -> u128_t { | |
| a := _a; | |
| a.lo += b.lo; | |
| a.hi += b.hi + (ifx (a.lo < b.lo) then 1 else 0).(u64); | |
| return a; | |
| } | |
| mul128 :: (a: u64, b: u64) -> u128_t { | |
| ret: u128_t; | |
| #if CPU == .X64 { | |
| // _umul128 :: (a:u64,b:u64,hi:*u64) -> u64 #intrinsic "llvm.x86._umul128"; | |
| // ret.lo = _umul128(a, b, *ret.hi); | |
| r: u64=---; | |
| #asm { | |
| r === d; | |
| a === a; | |
| mul r, a, b; | |
| } | |
| ret.hi = r; | |
| ret.lo = a; | |
| } else #if CPU == .ARM64 { | |
| ret.lo = a * b; | |
| __umulh :: (a:u64,b:u64) -> u64 #intrinsic "llvm.umulh.i64"; | |
| ret.hi = __umulh(a, b); | |
| } else { | |
| lo_lo := (a & 0xffffffff) * (b & 0xffffffff); | |
| hi_lo := (a >> 32) * (b & 0xffffffff); | |
| lo_hi := (a & 0xffffffff) * (b >> 32); | |
| hi_hi := (a >> 32) * (b >> 32); | |
| cross := (lo_lo >> 32) + (hi_lo & 0xffffffff) + lo_hi; | |
| ret.hi = (hi_lo >> 32) + (cross >> 32) + hi_hi; | |
| ret.lo = (cross << 32) | (lo_lo & 0xffffffff); | |
| } | |
| return ret; | |
| } | |
| red611 :: inline (x: u128_t) -> u64 { | |
| return (x.lo & P611) + ((x.lo >> 61) | (x.hi << 3)); | |
| } | |
| extrared611 :: inline (x: u64) -> u64 { | |
| return (x & P611) + (x >> 61); | |
| } | |
| // ---------- Hash function ---------- | |
| ARBITRARY1 :u64: 0x6a09e667f3bcc908; // Completely arbitrary, these | |
| ARBITRARY2 :u64: 0xbb67ae8584caa73b; // are taken from SHA-2, and | |
| ARBITRARY3 :u64: 0x3c6ef372fe94f82b; // are the fractional bits of | |
| ARBITRARY4 :u64: 0xa54ff53a5f1d36f1; // sqrt(p), p = 2, 3, 5, 7. | |
| mix :: inline (x: u64) -> u64 { | |
| // Mixing function from https://jonkagstrom.com/mx3/mx3_rev2.html. | |
| x ^= x >> 32; | |
| x *= (0xe9846af9b1a615d).(u64); | |
| x ^= x >> 32; | |
| x *= (0xe9846af9b1a615d).(u64); | |
| x ^= x >> 28; | |
| return x; | |
| } | |
| AdvanceBufferCallback :: #type (data: *void, buf: *u8, len: u64, toAdvance: u64) -> (*u8, u64); | |
| default_advance_buffer_callback :: inline (data: *void, buf: *u8, len: u64, toAdvance: u64) -> (*u8, u64) { | |
| assert(len >= toAdvance); | |
| return buf+toAdvance, len-toAdvance; | |
| } | |
| // the buffer has to be directly addressable by at least 49 bytes | |
| hash_poly611 :: (buf: *u8, len: u64, p: HashParams, tweak: u64, _advance_buffer:AdvanceBufferCallback, _advance_buffer_data: *void) -> u64 { | |
| m: [7]u64; | |
| poly_acc := tweak; | |
| if LIKELY(len <= 7) { | |
| m[0] = load_le_u64_0_8(buf, len); | |
| return poly_acc + red611(mul128(p.k + m[0], p.k2 + len)); | |
| } | |
| k3 := red611(mul128( p.k, p.k2)); | |
| k4 := red611(mul128(p.k2, p.k2)); | |
| if UNLIKELY(len >= 50) { | |
| k5 := extrared611(red611(mul128(p.k, k4))); | |
| k6 := extrared611(red611(mul128(p.k2, k4))); | |
| k3 = extrared611(k3); | |
| k4 = extrared611(k4); | |
| h :u64= 0; | |
| while true { | |
| for i: 0..6 { | |
| m[i] = load_le_u64(buf + 7*i) & (0x00ffffffffffffff).(u64); | |
| } | |
| t0:= mul128(p.k + m[0], k6 + m[1]); | |
| t1:= mul128(p.k2 + m[2], k5 + m[3]); | |
| t2:= mul128( k3 + m[4], k4 + m[5]); | |
| t3:= mul128( h + m[6], p.k7); | |
| s := add128(add128(t0, t1), add128(t2, t3)); | |
| h = red611(s); | |
| buf, len = _advance_buffer(_advance_buffer_data, buf, len, 49); | |
| if !(len >= 50) then break; | |
| } | |
| k14 := red611(mul128(p.k7, p.k7)); | |
| hk14 := red611(mul128(extrared611(h), k14)); | |
| poly_acc += extrared611(hk14); | |
| } | |
| if LIKELY(len >= 8) { | |
| m[0] = load_le_u64(buf) & (0x00ffffffffffffff).(u64); | |
| m[1] = load_le_u64(buf + (len - 7) / 2) & (0x00ffffffffffffff).(u64); | |
| m[2] = load_le_u64(buf + len - 8) >> 8; | |
| t0 := mul128(p.k2 + m[0], p.k7 + m[1]); | |
| t1 := mul128(p.k + m[2], k3 + len); | |
| if LIKELY(len <= 21) then return poly_acc + red611(add128(t0, t1)); | |
| m[3] = load_le_u64(buf + 7) & (0x00ffffffffffffff).(u64); | |
| m[4] = load_le_u64(buf + 14) & (0x00ffffffffffffff).(u64); | |
| m[5] = load_le_u64(buf + len - 21) & (0x00ffffffffffffff).(u64); | |
| m[6] = load_le_u64(buf + len - 14) & (0x00ffffffffffffff).(u64); | |
| t0r := red611(t0); | |
| t2 := mul128(p.k2 + m[3], p.k7 + m[4]); | |
| t3 := mul128( t0r + m[5], k4 + m[6]); | |
| s := add128(add128(t1, t2), t3); | |
| return poly_acc + red611(s); | |
| } | |
| m[0] = load_le_u64_0_8(buf, len); | |
| return poly_acc + red611(mul128(p.k + m[0], p.k2 + len)); | |
| } | |
| #import "Basic"; | |
| #import "File"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| P :: #import,file "./polymur.jai"; | |
| Basic :: #import "Basic"; | |
| main :: () { | |
| POLYMUR_TEST_STRINGS :: string.[ | |
| "", | |
| "i", | |
| "es", | |
| "vca", | |
| "bdxa", | |
| "bbbmc", | |
| "vn5719", | |
| "lpvif62", | |
| "1fcjgark", | |
| "1jlz2nr6w", | |
| "g4q6ebxvod", | |
| "ehiybujo2n1", | |
| "6u2990ulzi7m", | |
| "c3xcb4ew8v678", | |
| "bhcaqrm221pea1", | |
| "oyl3iqxqr85eeve", | |
| "b41kacwmnim8rup5", | |
| "563ug64z3zdtlj438", | |
| "3spvl57qfg4udw2l3s", | |
| "297r1bqesqdhb3jd50g", | |
| "kbc5btot9x1fqslddmha", | |
| "r0vxw6kk8tc6pk0oxnr6m", | |
| "wkgmmma9icgky3bnj5bjir", | |
| "5eslfmq1w3i7wvd89ls7nvf", | |
| "40ytv0ye8cq49no6ys1pdrot", | |
| "p3mbto6bl36g3cx9sstyiugsd", | |
| "m0ylpn0wh5krbebs0j5trzgveb", | |
| "qsy8gpheo76vb8g0ivaojk1zgk4", | |
| "dwqf8tpad4k3x69sah7pstrg8zxx", | |
| "ls3zrsjf1o3cr5sjy7dzp98198i3y", | |
| "xvhvx3wbzer9b7kr4jqg2ok9e3mv5d", | |
| "yapzlwab361wvh0xf1rydn5ynqx8cz0", | |
| "nj56v1p9dc7qdmcn2wksfg5kic1uegm2", | |
| "hlebeoafjqtqxfwd9ge94z3ofk88c4a5x", | |
| "6li8qyu0n8nwoggm4hqzqdamem5barzjyw", | |
| "wj7sp7dhpfapsd8w2nzn8s7xtnro9g45x7t", | |
| "ahio6so1x30oziw54ux5iojjdfvkwpw2v14d", | |
| "wm6yacnl6k3kj3c6i1jeajuwmquv9yujms0wq", | |
| "kzs6xfhmc4ifmstnekcze4y1l83ddvxust2r0o", | |
| "ckamexupx7cmsuza9nssw6n45e7go4s3osr1903", | |
| "nob5bj9tok346dg62jbfjfrhg5l6itsno2hkhfru", | |
| "vgo0ko42n5jvrvnv3ddpwg8h7gkqoxbllv2fdy0no", | |
| "dgs47djqzq3czo0i0v1u3d3x72vtvi3w2tsf9shx6k", | |
| "8vjrw7jz90kf969txb5qrh0u5332zf5epsp8aes4aqh", | |
| "3ni9vtqiq6vnxipfa2wag8vfwq2nyce1kgq5nj3razx9", | |
| "u29xjkod6rtu5j5tlwkydt9khih6o2do84q6ukwlr00xf", | |
| "yxxubvyxuusw827qctqr6tmm69rij5ex2zk1etps8qh61e", | |
| "p7lh4mvadnp6uw0vt7bnzcbv1wjswuuc6gjmu684yznx8lp", | |
| "8c27lotvnab6ra8pq9aon0w30ydyulesinew3akqrhhmm39e", | |
| "ttipbm97gpk7tiog1doncalwgpb7alk16dapga2ekzjt59pv6", | |
| "mbbtplseab2mgtgh8uwlhbmdrwxae3tc2mtf98bwuhmz4bfjnf", | |
| "shnjeydnj8awrkz3rd69wqqd9srie4eo6gc6ylhz2ouv4t4qbar", | |
| "lckl12agnpr6q5053h9v38lyk71emkvwdzrv0ic3a4a4pn3w3o4x", | |
| "7927wqjo5jiecfk0bbtt6065j5jl7x0vv1mcxxxl0j1oatrom44zp", | |
| "bajk3ff026vx0u7o5d7ry7w7n07sqdy4urv4psr79jp13e0mxsks1r", | |
| "en6j5o90gmgj7ssbz6jv3kzdsbzczu518c3zmezkp02rtvo1s88n9pu", | |
| "58fkwyf44tjnrytgplb5qfbvlwtav3zutxowoor2mklkr2up4nzpefos", | |
| "cep02qfl6swv1j3mwy5kprm4p8drszchufrkyr5ejbtzgu5cti6fqab5c", | |
| "lr5q0p1dljga8h4vruy1doa79hntwbdyolnh1fbe3phfk7f5rgs4815foj", | |
| "hmnjq6h1sslivjzmbxbpqba29f6kvbea6n6c4sanm40nzmrxt8hm61ooq3e", | |
| "ae43xxu1mqrbynmctit7m4wf02o0kf2vvw1l3y51n4cu5v5ba4dia67wf0bo", | |
| "qz9ye2ur849obmm23d5tnfc3xdaeajil0gm2pz8z9psedj50h5hcwbcn8n2lo", | |
| "w3xar1pzaff7fhyw6cshdgechm2pj1ebwrbkdct5xfbmxskr3937dodvky62i8", | |
| "ypy5k197quc9ypqoj9kle2eky307jnnd7tu52hqhn6mo7jj1fvmi42kkgq40iy6", | |
| "k1bp6qwiul8fnd6rfe42ge6gskk0jkr9fjgmuujey3kn8ie88h9qguw2gboo7i80", | |
| "begb64jkzfujx7ch3ain1iixidnbhcbcglcuf7nys8eansnkewtiye9xv7s2ksuev", | |
| "vf5d8vdjtwp5vo1ocb274nkl6h8vg97m4v5htfwv02tj9u68vdnteeim6q0zllxflj", | |
| "dcg9osulcdw9sqaue4cfz6k990vpstoxmvwbxzhzichkhdujy36v556u7oxug51gdup", | |
| "1rtgdtibcaos4ebzrbl1fkjahtbel6fyqipuu8lxfrwnggjr8wgoscfxp46wv9wjk315", | |
| "r27qj342zj4anpkqpr9yqo7udnldwiqqpq667zzjgw33yia3wt2p6t221onq4pvfaywbj", | |
| "2yzxskad06pt9zvjmiobfz12a3q6wqgpj4450rpxj0jvjk3cx39qo6cbpukxqsy6idqd40", | |
| "813zultj26k3gn6gibolpuozgaxu8exfatf4iqqugelcf6k8dnzvsjb9s25g3gyess2uscc", | |
| "i4p0jkxf3ajc02x330y3tg8l521fzootabn53ovru20ph3n17hfygaz1axs61jxipz6jac5z", | |
| "5bk748kkvww7toeyeueukk2qyin2o5ohnvj7l1cqs9zgy92n6ujxg6sxdjw81hfd29nzrb4kh", | |
| "uvhy62avo1wqms1rrtefth84xhnv1a59aez6r4xq0pla74036o3vznihxexwydnfjojmk6ipl6", | |
| "0t0dlfopg27cqv1xp4qfgwdlivvgqz204hkh5ianbb4abgk0yjolcwhhitrcksha5s6otmps0hd", | |
| "vrbhcwrmn5xbq8f518ntvmaeg89n7nh1uxebfsmd7smoog3k2w12zv0px32pf4b78er5f3pgy7b9", | |
| "x5bmnefocbtxm8avt22ekuy5hcdyxh86is5fnns9ycfm7o25x9frwv9kfv2ohyd3txlc8zlg5rjjx", | |
| "ttfrgnfvvj552vjymrqqd1yjlyff7vkffprnvu3co4vuah8y0s56tziih3yowm64ja810gb1sgk0um", | |
| "a66t43i9vrr3cmg5qf52akuk8bxl4rm3i86rm7h5brjou9k2egrzy3h19hh8kqr2queyvrwb673qikj", | |
| "mfuwhbvd88n21obpmwx273mmeqiz98qfmb04z0ute54kc1d9bbdyfbx2sc4em6t4pfektm05qs7bgc9z", | |
| "x8wbm0kjpyua8wpgsejgxc06geitm1c0bxihvcwnxnif63dj7cygzk7led0z49ol6zf2xwcmf99n4osip", | |
| "fvba43myr0ozab882crozdz0zx4lfl2h7xe2phfqte97g58fake2fzi87mpftz9qdmt45gm79xl43k1hji", | |
| "wnr0pz08rm3j65b7pl116l59pxy6prnydf9xod1qdi3hp3lod2vuzy1v7gt2g72sejaomn5u53daxjrr9xk", | |
| "bwo7nfqda6w56voyvg1nr7vkq61zi7gy0aggn6pic3gup7uy18zzsc7y5yz3ptvp5cd53i95dj521k4n6n7t", | |
| "mromebynw459uydhhgcgrate6hnst5srng9knfjc02vtg1vywok3rdbw935pf1qwghnh0nibyb60l9elkmajg", | |
| "59dcjawsd4kjjcceco3hphizua88l0qtrfd000iam3rnb4tmy6kzf5bhkc9ud1hsg3dd53tlsxarcl0n59081h", | |
| "odgdgfkwcpz0zjcwsz9is5h4nhebzht7fqa1b4g8e2snb6bn5hu3ixyd2pk1ey5g3eab0m3aoknfi9ctkpxz07j", | |
| "0ljqm7r10ns2pjo8x69oi0zuqss9y7301yd6rmex8djwrbqmvh2mbwscgj9pmrgul5ao0tvpefpe5a9cac5xbdwb", | |
| "b449ak3ihp8tdrbteffru5vboeh1z63c55at3qz70p13d2fim50q8i06zjyb53i4gqzunx6rsl07jxjd9g77me1ww", | |
| "oqzf6c40snvrjz4v0f4h8p0ozjfy1y4xihxwaz16vbxf3qsa805xodw8z5xq3hb7dag8fnxtlsc62150kk253i3buj", | |
| "2eicp9a5aq2uycq55y7rsixlg3pfk7gyin65fghf03kks18dixbckxmbv5xnhyrir7qm8maz4rk2bi3zs9chidlhehf", | |
| "7k1wyjs6fxss4e0ywqfurgop6f7y7e97f3mr5hnb0hlhqkqbqvi1e1z3qfyxc3te75r67fc4h9li06rl9zadg3v9zmz6", | |
| "k3e403zdtia8i0gpodm00yaujr1w474bh3985o3csbfjp3dll4t98i5lesloo6rqjec2aycb3ttx1t6lg0cl9hrjkgheb", | |
| "2fv8zdl1ljmpjbvaan0nt99tra48yjmc5pv91n1c5l8qp5pv77zwsx75ouay7bmgy2tjc1aazyu5zj7oimesavv9n2h7ky", | |
| "ghxs7uejpzpbxjsdmc2w9fabrg4j4pwwbn0wjxux2luk1k0ciror4gcvww18e610u2wpczuwrcphy2xr1129vweqhhgitge", | |
| "vk7wfi9hhi0j9n2grs8rxgq68kw54dbdviuxnvtwgz77h0qkbzqw7pgm7zgn21cxlxnyzigeyz2rzrj3awloq86tqe60e070", | |
| "d1aot9216s547uk1rg651iscb1bjpgth5j4f6arx1902npcykk8niz3ffpbed47idgzvt4u59fyi5e0e2afpjb5gjk4rysn8j", | |
| "2jef2xl4o9yub0z6jnxu8gm87g9iv9zdtu9yolvxtensjrtgplnmnuhz43nsxztk8s936k6eruckkiwc5hnch4qdzft093986x", | |
| "oo70ed77jci4bgodhnyf37axrx4f8gf8qs94f4l9xi9h0jkdl2ozoi2p7q7qu1945l21dzj6rhvqearzrmblfo3ljjldj0m9fue", | |
| ]; | |
| POLYMUR_REFERENCE_VALUES :: u64.[ | |
| 0x1a6ef9f9d6c576fb, 0xd16d059771c65e13, 0x5ee4e0c09f562f87, 0x535b5311db007b0b, | |
| 0xd17124f14bd16b5d, 0xe84c87105c5b5cad, 0xb16ce684b89df9c0, 0x656525cace200667, | |
| 0x92b460794885d16d, 0xe6cc0fd9725b46b9, 0xc875ade1929bc93d, 0x68a2686ced37268a, | |
| 0x1d1809fd7e7e14ef, 0x699b8f31fc40c137, 0xd10dca2605654d2d, 0xd6bc75cb729f18d7, | |
| 0xfe0c617e7cb1bffe, 0xf5f14c731c1b9a22, 0x7a0382228d248631, 0x6c3a5f49d8a48bc0, | |
| 0x3606ebe637bb4ebc, 0xeb4854d75431ad1d, 0xfa8ff1a34793ebb0, 0x7e46ad8e2338cc38, | |
| 0xf8ff088ada3154b4, 0x706669bf0925914f, 0x70fc5fbcd3485ace, 0x96fd279baed2f2ab, | |
| 0x6403a64c68d7bf68, 0x3f8f532e1df472e5, 0xbfc49c083515596f, 0xd678a4b338fbf03b, | |
| 0x127142a2f38b70a1, 0x8a1a56fbb85b71f6, 0x961d22b14e6f1932, 0xa166b0326c942c30, | |
| 0x0f3d837dddb86ae2, 0x0f8164504b4ea8b1, 0xe4f6475d5a739af4, 0xbf535ad625c0d51f, | |
| 0x47f10a5a13be50ad, 0x3dc5ce9c148969b3, 0x8dc071fb4df8e144, 0x9d0a83586cbed3b8, | |
| 0xc4379e22f2809b99, 0x42010c7dd7657650, 0xcc31a6fbcdab8be8, 0x7bad06c38400138a, | |
| 0x0178b41584eb483d, 0x78afc38d52514efc, 0x65a57c4e59288dc7, 0x86e7cc3e273e4e47, | |
| 0xeb99661fb41a6bd2, 0xea0979aa6cd70feb, 0xa64a347c0b8e007b, 0x3692969270fe8fa4, | |
| 0x17640c6052e26555, 0xdf9e0fd276291357, 0x64cca6ebf4580720, 0xf82b33f6399c3f49, | |
| 0xbe3ccb7526561379, 0x8c796fce8509c043, 0x9849fded8c92ce51, 0xa0e744d838dbc4ef, | |
| 0x8e4602d33a961a65, 0xda381d6727886a7e, 0xa503a344fc066833, 0xbf8ff5bc36d5dc7b, | |
| 0x795ae9ed95bca7e9, 0x19c80807dc900762, 0xea7d27083e6ca641, 0xeba7e4a637fe4fb5, | |
| 0x34ac9bde50ce9087, 0xe290dd0393f2586a, 0xbd7074e9843d9dca, 0x66c17140a05887e6, | |
| 0x4ad7b3e525e37f94, 0xde0d009c18880dd6, 0x1516bbb1caca46d3, 0xe9c907ec28f89499, | |
| 0xd677b655085e1e14, 0xac5f949b08f29553, 0xd353b06cb49b5503, 0x9c25eb30ffa8cc78, | |
| 0x6cf18c91658e0285, 0x99264d2b2cc86a77, 0x8b438cd1bb8fb65d, 0xdfd56cf20b217732, | |
| 0x71f4e35bf761bacf, 0x87d7c01f2b11659c, 0x95de608c3ad2653c, 0x51b50e6996b8de93, | |
| 0xd21e837b2121e8c9, 0x73d07c7cb3fa0ba7, 0x8113fab03cab6df3, 0x57cdddea972cc490, | |
| 0xc3df94778f1eec30, 0x7509771e4127701e, 0x28240c74c56f8f7c, 0x194fa4f68aab8e27 | |
| ]; | |
| p : P.HashParams; | |
| P.init_params_from_seed(*p, 0xfedbca9876543210); | |
| tweak :u64= 0xabcdef0123456789; | |
| for s: POLYMUR_TEST_STRINGS { | |
| h := P.hash(s, p, tweak); | |
| rh := POLYMUR_REFERENCE_VALUES[it_index]; | |
| Basic.log("h of [%] is % ref is: %", s, h, rh); | |
| Basic.assert(h == rh); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment