ref: 3d7695c257de8ea4d4c0b8999682de0b29ee3c20
parent: 90c065621cb9245e996dd379270ffa7c277d13db
parent: f8e8b084dad7b4b7ea813bc4b612f64a07f27cd7
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jun 15 05:28:17 EDT 2016
Merge remote-tracking branch 'ac/htabsimp'
--- a/lib/std/htab.myr
+++ b/lib/std/htab.myr
@@ -18,6 +18,7 @@
;;
generic mkht : (h : (k : @k -> uint32), eq : (a : @k, b : @k -> bool) -> htab(@k, @v)#)
+ generic htinit : (ht : htab(@k, @v)#, h : (k : @k -> uint32), eq : (a : @k, b : @k -> bool) -> void)
generic htfree : (ht : htab(@k, @v)# -> void)
generic htput : (ht : htab(@k, @v)#, k : @k, v : @v -> void)
generic htdel : (ht : htab(@k, @v)#, k : @k -> void)
@@ -87,7 +88,6 @@
di++
i = (h + di) & (ht.keys.len - 1)
;;
-
if ht.hashes[i] == 0
-> `None
;;
@@ -104,7 +104,13 @@
var ht
ht = alloc()
+ htinit(ht, h, eq)
+ -> ht
+}
+
+generic htinit = {ht, h, eq
+
ht.hash = h
ht.eq = eq
@@ -114,7 +120,6 @@
ht.vals = slalloc(Initsz)
ht.hashes = slzalloc(Initsz)
ht.dead = slzalloc(Initsz)
- -> ht
}
generic htfree = {ht
@@ -135,16 +140,9 @@
i = h & (ht.keys.len - 1)
neltincr = 1
while ht.hashes[i] != 0 && !ht.dead[i]
- /* second insertion overwrites */
- if ht.hashes[i] == h && !ht.dead[i]
- /* dead key, we can just insert here */
- if ht.dead[i]
- break
- /* replacing a key */
- elif ht.eq(ht.keys[i], k)
- neltincr = 0
- break
- ;;
+ if ht.hashes[i] == h && ht.eq(ht.keys[i], k)
+ neltincr = 0
+ break
;;
di++
i = (h + di) & (ht.keys.len - 1)
@@ -212,8 +210,6 @@
generic htbykeyvals = {ht
-> [.ht = ht, .idx = 0]
}
-
-extern const put : (str : byte[:], args : ... -> size)
impl iterable htkviter(@k, @v) -> (@k, @v) =
__iternext__ = {itp, valp