Skip to content

Commit

Permalink
fix CountTable
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Feb 20, 2020
1 parent 51c1921 commit 55050e0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2233,9 +2233,9 @@ type
proc ctRawInsert[A](t: CountTable[A], data: var seq[tuple[key: A, val: int]],
key: A, val: int) =
let hc = hash(key)
var perturb = t.getPerturb(hc)
var h: Hash = hc and high(data)
while data[h].val != 0: h = nextTry(h, high(data), perturb) # TODO: handle deletedMarker
# TODO: handle deletedMarker
template mustNextTry(cell, index): bool = cell.val != 0
let h = findCell(t, hc, mustNextTry)
data[h].key = key
data[h].val = val

Expand All @@ -2262,12 +2262,15 @@ proc remove[A](t: var CountTable[A], key: A) =
proc rawGet[A](t: CountTable[A], key: A): int =
if t.data.len == 0:
return -1
template mustNextTry(cell, index): bool =
# TODO: may need to handle cell.hcode == deletedMarker?
if cell.val != 0:
if cell.key == key: return index
true
else: false
let hc = hash(key)
var perturb = t.getPerturb(hc)
var h: Hash = hc and high(t.data) # start with real hash value
while t.data[h].val != 0: # TODO: may need to handle t.data[h].hcode == deletedMarker?
if t.data[h].key == key: return h
h = nextTry(h, high(t.data), perturb)
let h = findCell(t, hc, mustNextTry)

result = -1 - h # < 0 => MISSING; insert idx = -1 - result

template ctget(t, key, default: untyped): untyped =
Expand Down

0 comments on commit 55050e0

Please sign in to comment.