ref: 076f0227af253fb49225135e5dbbfb2e2aba49e6
parent: f080badd0962a2ab65a4dcf4f4bbd813fc669646
author: Ori Bernstein <[email protected]>
date: Wed May 6 12:59:04 EDT 2015
Add bitset max function. Gives the largest value that can be held by the bitset. Icky; should be replaced with a proper iterator.
--- a/libstd/bitset.myr
+++ b/libstd/bitset.myr
@@ -13,6 +13,8 @@
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 @@
const bseq : (a : bitset#, b : bitset# -> bool)
const bsissubset : (a : bitset#, b : bitset# -> bool)
+
const bsclear : (bs : bitset# -> bitset#)
;;
@@ -44,6 +47,10 @@
-> bs
}
+const bsmax = {bs
+ -> bs.bits.len * sizeof(size) * 8
+}
+
generic bsput = {bs, v
var idx
var off
@@ -126,7 +133,7 @@
}
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 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)
}
--- a/libstd/hashfuncs.myr
+++ b/libstd/hashfuncs.myr
@@ -13,9 +13,23 @@
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