summary refs log tree commit diff stats
path: root/lib/pure/collections/tableimpl.nim
Commit message (Collapse)AuthorAgeFilesLines
* Attempt to explain better why delImplIdx is the way it is. Maybe this can ↵c-blake2020-07-291-0/+30
| | | | | | | (#15108) avoid future implementation mischief. (Maybe not. Sometimes, general distrust of theory leads people to distrust simple reasoning over times from CPUs trying as hard as possible to mask DRAM latency via pre-fetch.)
* Fulfill https://github.com/nim-lang/Nim/pull/14995#issuecomment-664914391 ↵c-blake2020-07-281-7/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#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.
* remove a condition that table size must be passed as power of 2 (#14926)Miran2020-07-081-3/+3
| | | | | | | | | | | | | | | * remove a condition that table size must be passed as power of 2 * remove power-of-2 condition from sets and sharedtables * remove power-of-2 condition from deques * use 'correctSize' for both branches * prettify changelog.md and fix typos * add a changelog entry * fix double-call of 'right-size' * fix the same thing in sets.nim * introduce a new internal proc `slotsNeeded` Deprecate the public proc `rightSize`, which is not needed anymore. Now it is an identity function, allowing the old code to work correctly and without extra allocations.
* Unwind just the "pseudorandom probing" part of recent sets,tables changes ↵c-blake2020-03-311-18/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#13816) * Unwind just the "pseudorandom probing" (whole hash-code-keyed variable stride double hashing) part of recent sets & tables changes (which has still been causing bugs over a month later (e.g., two days ago https://github.com/nim-lang/Nim/issues/13794) as well as still having several "figure this out" implementation question comments in them (see just diffs of this PR). This topic has been discussed in many places: https://github.com/nim-lang/Nim/issues/13393 https://github.com/nim-lang/Nim/pull/13418 https://github.com/nim-lang/Nim/pull/13440 https://github.com/nim-lang/Nim/issues/13794 Alternative/non-mandatory stronger integer hashes (or vice-versa opt-in identity hashes) are a better solution that is more general (no illusion of one hard-coded sequence solving all problems) while retaining the virtues of linear probing such as cache obliviousness and age-less tables under delete-heavy workloads (still untested after a month of this change). The only real solution for truly adversarial keys is a hash keyed off of data unobservable to attackers. That all fits better with a few families of user-pluggable/define-switchable hashes which can be provided in a separate PR more about `hashes.nim`. This PR carefully preserves the better (but still hard coded!) probing of the `intsets` and other recent fixes like `move` annotations, hash order invariant tests, `intsets.missingOrExcl` fixing, and the move of `rightSize` into `hashcommon.nim`. * Fix `data.len` -> `dataLen` problem.
* tables/sharedtables/intsets/etc: fix #13496, #13504, #13505; add lots of ↵Timothee Cour2020-02-261-6/+16
| | | | | | | | | | | tests (#13498) [backport] * fix #13496 handle tombstones * add test * more tests * fix #13504; add SharedTable tests * fix #https://github.com/nim-lang/Nim/issues/13505 intsets.missingOrExcl silently gave wrong results sometimes * add test for tintsets
* [backport] pseudorandom probing for hash collision (#13418)Timothee Cour2020-02-191-27/+20
|
* use system.move instead of system.shallowCopy if the GC mode requires itAndreas Rumpf2019-10-041-1/+1
|
* [bugfix] fix #11588, don't check if SharedTable is initializednarimiran2019-06-261-10/+10
|
* [bugfix] fix OrderedTable default initialization (#11549)Miran2019-06-201-0/+3
|
* make fullpaths the default in error messages and stack traces for mor… ↵Andreas Rumpf2019-06-051-1/+1
| | | | | | | | | | | | (#11385) * make fullpaths the default in error messages and stack traces for more convenient development * split up -d:release into -d:release and -d:danger flags * workaround a Nim config parser bug * fixes an old nim config parser bug * make megatest green again * make nimpretty tests work again * make nimsuggest green
* Initialized collections (#11094)Miran2019-04-291-55/+56
| | | | | | | | | | | | * tables: initialized by default * sets: initialized by default * DRY: extract shared functionality * add a changelog entry * fix errors * don't test include files * make it work for sharedtables * fix discovered bugs * add exhaustive tests
* stdlib: use system.default if it existsAndreas Rumpf2019-03-051-3/+4
|
* better docs: tablesnarimiran2019-01-161-1/+1
|
* more replacements for the deprecated '<'Andreas Rumpf2017-10-291-1/+1
|
* Remove expr/stmt (#5857)Arne Döring2017-07-251-2/+2
|
* Add compute proc for SharedTable (#5385)Ruslan Mustakov2017-03-021-3/+6
|
* Workaround for #5098Yuriy Glukhov2016-12-051-4/+3
|
* Fixes #5035Felix Krause2016-11-181-4/+10
|
* Merge pull request #4367 from kierdavis/4365-tables-clearAndreas Rumpf2016-08-251-1/+2
|\ | | | | Improvements to tables.clear()
| * Fix clear() on CountTableKier Davis2016-07-091-1/+2
| | | | | | | | | | | | The record tuples used in CountData.data don't contain an 'hcode' member, unlike Table and OrderedTable, causing the existing clearImpl() implementation to break when attempting to assign to t.data[i].hcode.
* | make nim bootstrap again for older versionsAndreas Rumpf2016-07-301-2/+2
| |
* | stdlib and compiler don't use .immediate anymoreAndreas Rumpf2016-07-291-7/+7
|/
* attempt to fix a critical memory leak in Nim's collectionsAndreas Rumpf2016-06-151-0/+8
|
* Implements tables.clear.Dominik Picheta2016-06-021-0/+5
|
* Fixed Table::del in JSYuriy Glukhov2016-03-211-1/+4
|
* Merge branch 'more_concurrency' into develAraq2015-06-301-15/+15
| | | | | | | | Conflicts: doc/tut1.txt lib/core/locks.nim lib/pure/collections/tables.nim lib/pure/selectors.nim
* some progress on making async multithreadedAraq2015-05-281-0/+132