Commit Graph

30 Commits

Author SHA1 Message Date
flywind
eb8cc51bb8 tables module uses runnableExamples (#16994)
* tables module use runnableExamples
* disable the tests
2021-02-13 09:09:12 +01:00
flywind
d447c0fe3f use typeof instead type (#16962) 2021-02-08 09:46:07 +01:00
cooldome
04f8fcfbd0 Tables, use sink val arguments more actively (#15625) 2020-10-19 14:13:26 +02:00
c-blake
196e747df1 Attempt to explain better why delImplIdx is the way it is. Maybe this can (#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.)
2020-07-29 11:19:02 +02:00
c-blake
b2a1944587 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.
2020-07-28 23:48:50 +02:00
Miran
3de5296337 remove a condition that table size must be passed as power of 2 (#14926)
* 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.
2020-07-08 15:01:47 +02:00
c-blake
b1aa3b1eea Unwind just the "pseudorandom probing" part of recent sets,tables changes (#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.
2020-03-31 19:18:45 +02:00
Timothee Cour
42dad3a836 tables/sharedtables/intsets/etc: fix #13496, #13504, #13505; add lots of 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
2020-02-26 22:07:09 +01:00
Timothee Cour
8c22518d67 [backport] pseudorandom probing for hash collision (#13418) 2020-02-19 17:19:55 +01:00
Andreas Rumpf
60d64d1aef use system.move instead of system.shallowCopy if the GC mode requires it 2019-10-04 09:48:45 +02:00
narimiran
326e3ad09d [bugfix] fix #11588, don't check if SharedTable is initialized 2019-06-26 17:16:55 +02:00
Miran
45bbf1ef5b [bugfix] fix OrderedTable default initialization (#11549) 2019-06-20 21:03:11 +02:00
Andreas Rumpf
7215341190 make fullpaths the default in error messages and stack traces for mor… (#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
2019-06-05 08:02:54 +02:00
Miran
737fff5902 Initialized collections (#11094)
* 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
2019-04-29 08:13:52 +02:00
Andreas Rumpf
aed8766e84 stdlib: use system.default if it exists 2019-03-05 10:03:24 +01:00
narimiran
b40a637fac better docs: tables 2019-01-16 09:45:57 +01:00
Andreas Rumpf
6a3288a60e more replacements for the deprecated '<' 2017-10-29 08:55:30 +01:00
Arne Döring
000b8afd26 Remove expr/stmt (#5857) 2017-07-25 09:28:23 +02:00
Ruslan Mustakov
a81247dcbe Add compute proc for SharedTable (#5385) 2017-03-02 15:31:30 +01:00
Yuriy Glukhov
4423da465a Workaround for #5098 2016-12-05 23:44:55 +02:00
Felix Krause
93a998204c Fixes #5035 2016-11-18 23:42:15 +01:00
Andreas Rumpf
1e134aed49 Merge pull request #4367 from kierdavis/4365-tables-clear
Improvements to tables.clear()
2016-08-25 16:46:53 +02:00
Andreas Rumpf
a8edf67a28 make nim bootstrap again for older versions 2016-07-30 00:50:38 +02:00
Andreas Rumpf
60b187513e stdlib and compiler don't use .immediate anymore 2016-07-29 23:51:01 +02:00
Kier Davis
edb5a1a5c6 Fix clear() on CountTable
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.
2016-07-09 17:21:18 +01:00
Andreas Rumpf
5f83e869fa attempt to fix a critical memory leak in Nim's collections 2016-06-15 17:15:27 +02:00
Dominik Picheta
2b162c04b1 Implements tables.clear. 2016-06-02 18:25:10 +01:00
Yuriy Glukhov
308b7c0138 Fixed Table::del in JS 2016-03-21 13:35:54 +02:00
Araq
28de800d61 Merge branch 'more_concurrency' into devel
Conflicts:
	doc/tut1.txt
	lib/core/locks.nim
	lib/pure/collections/tables.nim
	lib/pure/selectors.nim
2015-06-30 12:50:24 +02:00
Araq
21ea8e6913 some progress on making async multithreaded 2015-05-28 12:49:08 +02:00