summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-05-06 16:59:04 -0700
committerOri Bernstein <ori@eigenstate.org>2015-05-06 16:59:04 -0700
commitb0b7356f91f09dcb819de5aaa93a284442c6226f (patch)
treece2397ec65f2481a779a4f0c30ee6e99b536c463 /libstd
parentff0960cb7029fb443abc45b8961b7a1c1263752c (diff)
downloadmc-b0b7356f91f09dcb819de5aaa93a284442c6226f.tar.gz
Add bitset max function.
Gives the largest value that can be held by the bitset. Icky; should be replaced with a proper iterator.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/bitset.myr11
-rw-r--r--libstd/hashfuncs.myr14
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)