diff --git a/lib/pure/collections/hashcommon.nim b/lib/pure/collections/hashcommon.nim index 31df5171cf00c..e591c6491b3f8 100644 --- a/lib/pure/collections/hashcommon.nim +++ b/lib/pure/collections/hashcommon.nim @@ -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 diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index b464fd2be5f5e..890ab5892f6f6 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -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>`_. @@ -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()