summary refs log tree commit diff stats
path: root/changelog.md
diff options
context:
space:
mode:
authorc-blake <c-blake@users.noreply.github.com>2020-07-28 17:48:50 -0400
committerGitHub <noreply@github.com>2020-07-28 23:48:50 +0200
commitb2a1944587bd23f87d05ed20cf33dd11c4c86e26 (patch)
tree2ee398e1308801eaea32cb99e09053efcf8f13da /changelog.md
parent86c9b7833917cd3deac912488e4dc18a1ca1223a (diff)
downloadNim-b2a1944587bd23f87d05ed20cf33dd11c4c86e26.tar.gz
Fulfill https://github.com/nim-lang/Nim/pull/14995#issuecomment-664914391 (#15104)
request.  This can be conceived as an alternate, more capable resolution of
  https://github.com/nim-lang/Nim/issues/12200
than
  https://github.com/nim-lang/Nim/pull/12208

The code re-org idea here is to upgrade tablimpl.nim:`delImpl`/`delImplIdx`
to abstract client code conventions for cell emptiness & cell hashing via
three new template arguments - `makeEmpty`, `cellEmpty`, `cellHash` which
all take a single integer argument and clear a cell, test if clear or
produce the hash of the key stored at that index in `.data[]`.

Then we update the 3 call sites (`Table`, `CountTable`, `SharedTable`) of
`delImpl`/`delImplIdx` by defining define those arguments just before the
first invocation as non-exported templates.

Because `CountTable` does not save hash() outputs as `.hcode`, it needs a
new tableimpl.nim:`delImplNoHCode` which simply in-lines the hash search
when no `.hcode` field is available for "prefix compare" acceleration.
It is conceivable this new template could be used by future variants, such
as one optimized for integer keys where `hash()` and `==` are fast and
`.hcode` is both wasted space & time (though a small change to interfaces
there for a sentinel key meaning "empty" is needed for maximum efficiency).

We also eliminate the old O(n) `proc remove(CountTable...)` in favor of
simply invoking the new `delImpl*` templates and take care to correctly
handle the case where `val` is either zero for non-existent keys in `inc`
or evolves to zero over time in `[]=` or `inc`.

The only user-visible changes from the +-42 delta here are speed, iteration
order post deletes, and relaxing the `Positive` constraint on `val` in
`proc inc` again, as indicated in the `changelog.md` entry.
Diffstat (limited to 'changelog.md')
-rw-r--r--changelog.md1
1 files changed, 1 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index 93c0797d3..d9eaa5823 100644
--- a/changelog.md
+++ b/changelog.md
@@ -140,6 +140,7 @@
 - Tables, HashSets, SharedTables and deques don't require anymore that the passed
   initial size must be a power of two - this is done internally.
   Proc `rightSize` for Tables and HashSets is deprecated, as it is not needed anymore.
+  `CountTable.inc` takes `val: int` again not `val: Positive`; I.e. it can "count down" again.
 - Removed deprecated symbols from `macros` module, deprecated as far back as `0.15`.