summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-06-16 23:22:00 -0700
committerOri Bernstein <ori@eigenstate.org>2015-06-16 23:22:00 -0700
commit6213b1e182c21e0903fcdae8e32ec5e93b61912c (patch)
tree2543ca0a4c23d572cee643b9c59bd171045c5c4a /libstd
parentf09d58f381dee6f9f9cdea78a10651e3796e9831 (diff)
downloadmc-6213b1e182c21e0903fcdae8e32ec5e93b61912c.tar.gz
Fix up hash table.
We could sometimes loop infinitely. This is not recommended.
Diffstat (limited to 'libstd')
-rw-r--r--libstd/htab.myr23
1 files changed, 11 insertions, 12 deletions
diff --git a/libstd/htab.myr b/libstd/htab.myr
index e9880b9..3adac8e 100644
--- a/libstd/htab.myr
+++ b/libstd/htab.myr
@@ -76,20 +76,19 @@ generic idx = {ht, k
di = 0
h = hash(ht, k)
i = h & (ht.keys.len - 1)
- while true
- while ht.hashes[i] != 0 && !ht.dead[i] && ht.hashes[i] != h
- di++
- i = (h + di) & (ht.keys.len - 1)
- ;;
+ while ht.hashes[i] != 0 && !ht.dead[i] && ht.hashes[i] != h
+:searchmore
+ di++
+ i = (h + di) & (ht.keys.len - 1)
+ ;;
- if ht.hashes[i] == 0 || ht.dead[i]
- -> `None
- ;;
- if ht.eq(ht.keys[i], k)
- -> `Some i
- ;;
+ if ht.hashes[i] == 0 || ht.dead[i]
+ -> `None
+ ;;
+ if ht.eq(ht.keys[i], k)
+ goto searchmore
;;
- -> `None /* fixme; while true should flag this as unreachable */
+ -> `Some i
}
generic mkht = {h, eq