Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Mar 18, 2020
1 parent 18f35de commit a0684d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
22 changes: 11 additions & 11 deletions lib/pure/collections/hashcommon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ template findCell(t: typed, hc, mustNextTry): int =
var perturb = getPerturb(t, hc)
var depth = 0

## PARAM: this param can affect performance and could be exposed to users whoe
## need to optimize for their specific key distribution. If clusters are to be
## expected, it's better to set it low; for really random data, it's better to
## set it high. We pick a sensible default that works across a range of key
## distributions.
##
## depthThres=0 will just use pseudorandom probing
## depthThres=int.high will just use linear probing
## depthThres in between will switch
# PARAM: `depthThres` can affect performance and could be exposed to users who
# need to optimize for their specific key distribution. If clusters are to be
# expected, it's better to set it low; for really random data, it's better to
# set it high. We pick a sensible default that works across a range of key
# distributions.
#
# depthThres=0 will just use pseudorandom probing
# depthThres=int.high will just use linear probing
# depthThres in between will switch
const depthThres = 20

while mustNextTry(t.data[index], index):
depth.inc
if depth <= depthThres:
## linear probing, cache friendly
# linear probing, cache friendly
index = (index + 1) and m
else:
## pseudorandom probing, "bad" case was detected
# pseudorandom probing, "bad" case was detected
index = nextTry(index, m, perturb)
index

Expand Down
9 changes: 5 additions & 4 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2226,9 +2226,10 @@ type
counter: int
countDeleted: int
# using this and creating tombstones as in `Table` would make `remove`
# amortized O(1) instead of O(n); this requires updating remove,
# and changing `val != 0` to what's used in Table. Or simply make CountTable
# a thin wrapper around Table (which would also enable `dec`, etc)
# amortized O(1) instead of O(n); this requires updating `remove`,
# and changing `val != 0` to what's used in Table. Or we could simply make
# CountTable a thin wrapper around Table (which would also enable lifting
# restrictions on CountTable, eg lack of `dec`, allowing `0` counts, etc).
isSorted: bool
CountTableRef*[A] = ref CountTable[A] ## Ref version of
## `CountTable<#CountTable>`_.
Expand Down Expand Up @@ -2360,7 +2361,7 @@ proc inc*[A](t: var CountTable[A], key: A, val: Positive = 1) =
var index = rawGet(t, key)
if index >= 0:
inc(t.data[index].val, val)
if t.data[index].val == 0: dec(t.counter) # how could this happen?
assert t.data[index].val != 0
else:
insertImpl()

Expand Down

0 comments on commit a0684d6

Please sign in to comment.