@@ -781,18 +781,17 @@ iterator allValues*[A, B](t: Table[A, B]; key: A): B =
781
781
doAssert sortedItems (a.allValues ('z' )) == @ [10 , 20 , 30 ]
782
782
783
783
let hc = genHash (key)
784
- var h: Hash = hc and high (t.data)
785
784
let L = len (t)
786
- var perturb = t.getPerturb (hc)
787
-
788
- var num = 0
789
785
var cache: seq [Hash ]
790
- while isFilled (t.data[h].hcode): # `isFilledAndValid` would be incorrect, see test for `allValues`
791
- if t.data[h].hcode == hc and t.data[h].key == key:
792
- if not hasKeyOrPutCache (cache, h):
793
- yield t.data[h].val
794
- assert (len (t) == L, " the length of the table changed while iterating over it" )
795
- h = nextTry (h, high (t.data), perturb)
786
+ template mustNextTry (cell, index): bool =
787
+ if isFilled (cell.hcode):
788
+ if cell.hcode == hc and cell.key == key:
789
+ if not hasKeyOrPutCache (cache, index):
790
+ yield cell.val
791
+ assert (len (t) == L, " the length of the table changed while iterating over it" )
792
+ true
793
+ else : false
794
+ let index = findCell (t, hc, mustNextTry)
796
795
797
796
798
797
@@ -1267,10 +1266,8 @@ proc enlarge[A, B](t: var OrderedTable[A, B]) =
1267
1266
var nxt = n[h].next
1268
1267
let eh = n[h].hcode
1269
1268
if isFilledAndValid (eh):
1270
- var j: Hash = eh and maxHash (t)
1271
- var perturb = t.getPerturb (eh)
1272
- while isFilled (t.data[j].hcode):
1273
- j = nextTry (j, maxHash (t), perturb)
1269
+ template mustNextTry (cell, index): bool = isFilled (cell.hcode)
1270
+ let j = findCell (t, eh, mustNextTry)
1274
1271
rawInsert (t, t.data, n[h].key, n[h].val, n[h].hcode, j)
1275
1272
h = nxt
1276
1273
0 commit comments