diff options
Diffstat (limited to 'libstd/hashfuncs.myr')
-rw-r--r-- | libstd/hashfuncs.myr | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libstd/hashfuncs.myr b/libstd/hashfuncs.myr index 8edb439..00c44c4 100644 --- a/libstd/hashfuncs.myr +++ b/libstd/hashfuncs.myr @@ -13,10 +13,24 @@ pkg std = generic inteq : (a : @a::(integral,numeric), b : @a::(integral,numeric) -> bool) const murmurhash2 : (data : byte[:], seed : uint32 -> uint32) + + generic slhash : (sl : @a[:] -> uint32) + generic tobytes : (sl : @a[:] -> byte[:]) ;; const Seed = 1234 +generic slhash = {data : @a[:] + -> strhash(slbytes(data)) +} + +generic slbytes = {data : @a[:] + var n + + n = data.len * sizeof(@a) + -> (data castto(byte#))[:n] +} + /* Supremely simple djb hash. */ const strhash = {s -> murmurhash2(s, Seed) |