diff options
-rw-r--r-- | libstd/bitset.myr | 11 | ||||
-rw-r--r-- | libstd/hashfuncs.myr | 14 |
2 files changed, 23 insertions, 2 deletions
diff --git a/libstd/bitset.myr b/libstd/bitset.myr index 0cf8bbf..00b27c1 100644 --- a/libstd/bitset.myr +++ b/libstd/bitset.myr @@ -13,6 +13,8 @@ pkg std = const bsdup : (bs : bitset# -> bitset#) const bsfree : (bs : bitset# -> void) + const bsmax : (a : bitset# -> size) + generic bsput : (bs : bitset#, v : @a::(integral,numeric) -> void) generic bsdel : (bs : bitset#, v : @a::(integral,numeric) -> void) generic bshas : (bs : bitset#, v : @a::(integral,numeric) -> bool) @@ -23,6 +25,7 @@ pkg std = const bseq : (a : bitset#, b : bitset# -> bool) const bsissubset : (a : bitset#, b : bitset# -> bool) + const bsclear : (bs : bitset# -> bitset#) ;; @@ -44,6 +47,10 @@ const bsclear = {bs -> bs } +const bsmax = {bs + -> bs.bits.len * sizeof(size) * 8 +} + generic bsput = {bs, v var idx var off @@ -126,7 +133,7 @@ const bseq = {a, b } const ensurespace = {bs, v - if bs.bits.len <= v + if bs.bits.len*8 <= v bs.bits = slzgrow(bs.bits, v + 1) ;; } @@ -134,7 +141,7 @@ const ensurespace = {bs, v const eqsz = {a, b var sz - sz = max(a.bits.len, b.bits.len) + sz = max(a.bits.len, b.bits.len)*8 ensurespace(a, sz) ensurespace(b, sz) } 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) |