ref: 6213b1e182c21e0903fcdae8e32ec5e93b61912c
parent: f09d58f381dee6f9f9cdea78a10651e3796e9831
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Jun 16 19:22:00 EDT 2015
Fix up hash table. We could sometimes loop infinitely. This is not recommended.
--- a/libstd/htab.myr
+++ b/libstd/htab.myr
@@ -76,20 +76,19 @@
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
;;
- -> `None /* fixme; while true should flag this as unreachable */
+ if ht.eq(ht.keys[i], k)
+ goto searchmore
+ ;;
+ -> `Some i
}
generic mkht = {h, eq