commit
9b4619235f
1 changed files with 28 additions and 12 deletions
|
|
@ -778,20 +778,22 @@ proc sort*[A, B](t: OrderedTableRef[A, B],
|
||||||
|
|
||||||
proc del*[A, B](t: var OrderedTable[A, B], key: A) =
|
proc del*[A, B](t: var OrderedTable[A, B], key: A) =
|
||||||
## deletes `key` from ordered hash table `t`. O(n) comlexity.
|
## deletes `key` from ordered hash table `t`. O(n) comlexity.
|
||||||
var prev = -1
|
var n: OrderedKeyValuePairSeq[A, B]
|
||||||
|
newSeq(n, len(t.data))
|
||||||
|
var h = t.first
|
||||||
|
t.first = -1
|
||||||
|
t.last = -1
|
||||||
|
swap(t.data, n)
|
||||||
let hc = genHash(key)
|
let hc = genHash(key)
|
||||||
forAllOrderedPairs:
|
while h >= 0:
|
||||||
if t.data[h].hcode == hc:
|
var nxt = n[h].next
|
||||||
if t.first == h:
|
if isFilled(n[h].hcode):
|
||||||
t.first = t.data[h].next
|
if n[h].hcode == hc and n[h].key == key:
|
||||||
|
dec t.counter
|
||||||
else:
|
else:
|
||||||
t.data[prev].next = t.data[h].next
|
var j = -1 - rawGetKnownHC(t, n[h].key, n[h].hcode)
|
||||||
var zeroValue : type(t.data[h])
|
rawInsert(t, t.data, n[h].key, n[h].val, n[h].hcode, j)
|
||||||
t.data[h] = zeroValue
|
h = nxt
|
||||||
dec t.counter
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
prev = h
|
|
||||||
|
|
||||||
proc del*[A, B](t: var OrderedTableRef[A, B], key: A) =
|
proc del*[A, B](t: var OrderedTableRef[A, B], key: A) =
|
||||||
## deletes `key` from ordered hash table `t`. O(n) comlexity.
|
## deletes `key` from ordered hash table `t`. O(n) comlexity.
|
||||||
|
|
@ -1157,6 +1159,20 @@ when isMainModule:
|
||||||
doAssert(prev < i)
|
doAssert(prev < i)
|
||||||
prev = i
|
prev = i
|
||||||
|
|
||||||
|
block: # Deletion from OrederedTable should account for collision groups. See issue #5057.
|
||||||
|
# The bug is reproducible only with exact keys
|
||||||
|
const key1 = "boy_jackpot.inGamma1"
|
||||||
|
const key2 = "boy_jackpot.outBlack2"
|
||||||
|
|
||||||
|
var t = {
|
||||||
|
key1: 0,
|
||||||
|
key2: 0
|
||||||
|
}.toOrderedTable()
|
||||||
|
|
||||||
|
t.del(key1)
|
||||||
|
assert(t.len == 1)
|
||||||
|
assert(key2 in t)
|
||||||
|
|
||||||
var
|
var
|
||||||
t1 = initCountTable[string]()
|
t1 = initCountTable[string]()
|
||||||
t2 = initCountTable[string]()
|
t2 = initCountTable[string]()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue