mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 11:24:08 +00:00
committed by
Andreas Rumpf
parent
55c244400d
commit
cd51628f57
@@ -590,8 +590,11 @@ proc enlarge[A, B](t: var OrderedTable[A, B]) =
|
||||
swap(t.data, n)
|
||||
while h >= 0:
|
||||
var nxt = n[h].next
|
||||
if isFilled(n[h].hcode):
|
||||
var j = -1 - rawGetKnownHC(t, n[h].key, n[h].hcode)
|
||||
let eh = n[h].hcode
|
||||
if isFilled(eh):
|
||||
var j: Hash = eh and maxHash(t)
|
||||
while isFilled(t.data[j].hcode):
|
||||
j = nextTry(j, maxHash(t))
|
||||
rawInsert(t, t.data, n[h].key, n[h].val, n[h].hcode, j)
|
||||
h = nxt
|
||||
|
||||
|
||||
18
tests/stdlib/torderedtable.nim
Normal file
18
tests/stdlib/torderedtable.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
import tables, random
|
||||
var t = initOrderedTable[int,string]()
|
||||
|
||||
# this tests issue #5917
|
||||
var data = newSeq[int]()
|
||||
for i in 0..<1000:
|
||||
var x = random(1000)
|
||||
if x notin t: data.add(x)
|
||||
t[x] = "meh"
|
||||
|
||||
# this checks that keys are re-inserted
|
||||
# in order when table is enlarged.
|
||||
var i = 0
|
||||
for k, v in t:
|
||||
doAssert(k == data[i])
|
||||
doAssert(v == "meh")
|
||||
inc(i)
|
||||
|
||||
Reference in New Issue
Block a user