summary refs log tree commit diff stats
path: root/lib/pure/collections
Commit message (Collapse)AuthorAgeFilesLines
* Fix #14994 (#14996)Clyybber2020-07-151-1/+2
| | | | | | | * Fix #14994 * Revert misplaced "optimization" * Typo
* remove a condition that table size must be passed as power of 2 (#14926)Miran2020-07-087-92/+29
| | | | | | | | | | | | | | | * 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.
* tables.nim: Add named fields in `smallest` and `largest` (#14919)ee72020-07-061-2/+2
| | | | | | | | | | The `smallest` and `largest` procs for `CountTable` returned a tuple with named fields, but the same procs for `CountTableRef` returned an anonymous tuple. This commit makes those `CountTableRef` procs more consistent, and adds a test. Fixes: #14918
* Clean out sharedlists (#14857)Juan Carlos2020-07-021-6/+0
|
* Clean out sharedtables (#14858)Juan Carlos2020-06-301-10/+0
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Remove deprecated stuff from stdlib (#14699)Miran2020-06-172-45/+2
| | | | | | | * update to the latest Jester * remove deprecated procs from some stdlib modules * 'criterion' is not maintained anymore and relies on obsolete stuff
* Add `proc find` to `heapqueue` (#14628)c-blake2020-06-101-4/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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. * Add neglected API call `find` to heapqueue. * Add a changelog.md entry, `since` annotation and rename parameter to be `heap` like all the other procs for consistency. * Add missing import.
* remove isMainModule from json,os,sequtils (#14572)Timothee Cour2020-06-061-461/+0
| | | | | * move json.isMainModule => tjson * move isMainModule => tos,tsequtils
* fix #14404 foldr had the classic multiple evaluation bug (#14413)Timothee Cour2020-05-211-7/+7
|
* sequtils refactoring: prefer typeof over type (#14212)Andreas Rumpf2020-05-041-15/+15
|
* move since from inclrtl to std/private/since (#14188)hlaaftana2020-05-024-5/+5
| | | | * move since from inclrtl to std/private/since * move since import in system below for HCR
* change 'iff' to 'if' to stop "corrections" once and for all (#14182)Miran2020-05-012-5/+5
|
* JS unittest stacktrace fix, cleanup js repr and inclrtl includes (#14168)hlaaftana2020-04-301-2/+0
|
* Error -> Defect for defects (#13908)Jacek Sieka2020-04-281-12/+12
| | | | | | | | | | | | | | * Error -> Defect for defects The distinction between Error and Defect is subjective, context-dependent and somewhat arbitrary, so when looking at an exception, it's hard to guess what it is - this happens often when looking at a `raises` list _without_ opening the corresponding definition and digging through layers of inheritance. With the help of a little consistency in naming, it's at least possible to start disentangling the two error types and the standard lib can set a good example here.
* Add critbits.commonPrefixLen (#14072)Phil Krylov2020-04-241-0/+16
| | | | | | | * Add critbits.commonPrefixLen * add inline and since annotations, as well as a changelog entry Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Add deques.peekFirst/Last(var Deque[T]) -> var T (#13542)hlaaftana2020-04-211-0/+41
| | | | | | | * Add deques.peekFirst/Last(var Deque[T]) -> var T * Add changelog entry for deques.peekFirst/Last var T overloads * Add since annotation to peekFirst/peekLast Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fix mapIt issues #12625 & #12639 (#14041)Judd2020-04-211-14/+36
| | | | | | | | | | | | * fix mapIt issues #12625 & #12639: 1. fallback to call `map` when the result of `op` is a closure; 2. use `items(s)` in the for loop. * fix test errors. * add comments and InType is moved. * fix ident.
* Add runnableExamples to critbits module (#13994)jiro2020-04-181-25/+219
| | | | | * doc: critbit: add runnableExamples * doc: critbit: change to upper
* Add `hashWangYi1` (#13823)c-blake2020-04-151-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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. * This is an alternate resolution to https://github.com/nim-lang/Nim/issues/13393 (which arguably could be resolved outside the stdlib). Add version1 of Wang Yi's hash specialized to 8 byte integers. This gives simple help to users having trouble with overly colliding hash(key)s. I.e., A) `import hashes; proc hash(x: myInt): Hash = hashWangYi1(int(x))` in the instantiation context of a `HashSet` or `Table` or B) more globally, compile with `nim c -d:hashWangYi1`. No hash can be all things to all use cases, but this one is A) vetted to scramble well by the SMHasher test suite (a necessarily limited but far more thorough test than prior proposals here), B) only a few ALU ops on many common CPUs, and C) possesses an easy via "grade school multi-digit multiplication" fall back for weaker deployment contexts. Some people might want to stampede ahead unbridled, but my view is that a good plan is to A) include this in the stdlib for a release or three to let people try it on various key sets nim-core could realistically never access/test (maybe mentioning it in the changelog so people actually try it out), B) have them report problems (if any), C) if all seems good, make the stdlib more novice friendly by adding `hashIdentity(x)=x` and changing the default `hash() = hashWangYi1` with some `when defined` rearranging so users can `-d:hashIdentity` if they want the old behavior back. This plan is compatible with any number of competing integer hashes if people want to add them. I would strongly recommend they all *at least* pass the SMHasher suite since the idea here is to become more friendly to novices who do not generally understand hashing failure modes. * Re-organize to work around `when nimvm` limitations; Add some tests; Add a changelog.md entry. * Add less than 64-bit CPU when fork. * Fix decl instead of call typo. * First attempt at fixing range error on 32-bit platforms; Still do the arithmetic in doubled up 64-bit, but truncate the hash to the lower 32-bits, but then still return `uint64` to be the same. So, type correct but truncated hash value. Update `thashes.nim` as well. * A second try at making 32-bit mode CI work. * Use a more systematic identifier convention than Wang Yi's code. * Fix test that was wrong for as long as `toHashSet` used `rightSize` (a very long time, I think). `$a`/`$b` depend on iteration order which varies with table range reduced hash order which varies with range for some `hash()`. With 3 elements, 3!=6 is small and we've just gotten lucky with past experimental `hash()` changes. An alternate fix here would be to not stringify but use the HashSet operators, but it is not clear that doesn't alter the "spirit" of the test. * Fix another stringified test depending upon hash order. * Oops - revert the string-keyed test. * Fix another stringify test depending on hash order. * Add a better than always zero `defined(js)` branch. * It turns out to be easy to just work all in `BigInt` inside JS and thus guarantee the same low order bits of output hashes (for `isSafeInteger` input numbers). Since `hashWangYi1` output bits are equally random in all their bits, this means that tables will be safely scrambled for table sizes up to 2**32 or 4 gigaentries which is probably fine, as long as the integer keys are all < 2**53 (also likely fine). (I'm unsure why the infidelity with C/C++ back ends cut off is 32, not 53 bits.) Since HashSet & Table only use the low order bits, a quick corollary of this is that `$` on most int-keyed sets/tables will be the same in all the various back ends which seems a nice-to-have trait. * These string hash tests fail for me locally. Maybe this is what causes the CI hang for testament pcat collections? * Oops. That failure was from me manually patching string hash in hashes. Revert. * Import more test improvements from https://github.com/nim-lang/Nim/pull/13410 * Fix bug where I swapped order when reverting the test. Ack. * Oh, just accept either order like more and more hash tests. * Iterate in the same order. * `return` inside `emit` made us skip `popFrame` causing weird troubles. * Oops - do Windows branch also. * `nimV1hash` -> multiply-mnemonic, type-scoped `nimIntHash1` (mnemonic resolutions are "1 == identity", 1 for Nim Version 1, 1 for first/simplest/fastest in a series of possibilities. Should be very easy to remember.) * Re-organize `when nimvm` logic to be a strict `when`-`else`. * Merge other changes. * Lift constants to a common area. * Fall back to identity hash when `BigInt` is unavailable. * Increase timeout slightly (probably just real-time perturbation of CI system performance).
* return types must not be Natural for reasons I won't outline hereAraq2020-04-021-1/+1
|
* feature/count (#13837)Dean Eigenmann2020-04-021-0/+19
|
* revert stdlib changes which are not required anymoreAndreas Rumpf2020-04-012-10/+13
|
* Hrm, the new errors highlighted some code that seems to be brokenZahary Karadjov2020-04-012-13/+10
| | | | | | New issue: since `Table[A, B]` allocates its backing storage with `newSeq[KeyValuePair[A, B]]`, it's no longer legal to create a table with `not nil` types used as either keys or values.
* Unwind just the "pseudorandom probing" part of recent sets,tables changes ↵c-blake2020-03-317-174/+98
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#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.
* Add Documentation (#13811)Juan Carlos2020-03-311-0/+26
| | | | * Add more Docs and runnableExamples
* fix #13794 HashSet leak (#13800)Timothee Cour2020-03-291-1/+2
|
* add `move` to `tables` to prevent warnings when compiled with `--gc:arc` ↵Miran2020-03-191-4/+4
| | | | (#13684)
* fixes hash(HashSet) which was wrong as it didn't respect tombstones; refs #13649Araq2020-03-181-1/+2
|
* fix #13310, Deque misbehaves on VM (#13625)Miran2020-03-111-2/+15
| | | | * fix #13310, Deque misbehaves on VM * use 'when nimVM'
* tables/sharedtables/intsets/etc: fix #13496, #13504, #13505; add lots of ↵Timothee Cour2020-02-265-25/+44
| | | | | | | | | | | 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
* make unzip faster: seq[i]=val can be 7X faster than seq.add(elem) (#13448)Timothee Cour2020-02-211-5/+5
|
* Add `sequtils.unzip` to complement `sequtils.zip` (#13429)Kaushal Modi2020-02-201-0/+15
|
* Remove testutils (#13435) [backport]Clyybber2020-02-191-3/+4
|
* [backport] pseudorandom probing for hash collision (#13418)Timothee Cour2020-02-197-142/+209
|
* remove outplace version of 'merge' for CountTables (#13377)Miran2020-02-101-19/+13
| | | | | | * remove outplace version of 'merge' for CountTables * remove 'merge' tests
* [backport] remove 'CountTable.mget' (#13355)Miran2020-02-071-13/+0
| | | It didn't work, and it was an oversight to be included in v1.0.
* Idxmin & idxmax, continuation (#13208)Miran2020-01-201-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add idxmin() which returns the index of the minimum value * Add idxmax() which returns the index of the maximum value * Add tests for idxmin() * Add tests for idxmax() * Remove initialization of result = 0 * Adds overloading for arrays (no enums indexed arrays yet) * Add support for enum index arrays * Fix tests with enum * Fix tests for idxmax * Change names of the procedures to minIndex and maxIndex * address Araq's comments: - remove 'array' versions - add .since pragma - return 'int' instead of 'Natural' - add changelog entry Co-authored-by: Federico A. Corazza <20555025+Imperator26@users.noreply.github.com>
* [backport] fix #12813, fix #13079 (#13099)Miran2020-01-101-4/+14
| | | Correctly remove a key from CountTable when it is set to zero.
* Auto-initialize deques (#12879)Ico Doornekamp2019-12-211-3/+17
|
* remove unused import (#12900)Krzysztof Majk2019-12-151-1/+1
|
* fixes #12798 [backport]Araq2019-12-041-0/+1
|
* Fix sequtils.delete bug with out of bounds indexes (#12506)Oscar Nihlgård2019-11-291-1/+6
|
* Discussion both in (#12678)c-blake2019-11-201-31/+41
| | | | | | | | | | | https://github.com/nim-lang/Nim/pull/12600 and in https://forum.nim-lang.org/t/5499 indicates that everyone is happy/happier with ``pop``. This just renames the brand new ``take``s to ``pop`` and installs inline aliases/wrappers to preserve ``Table.take`` and ``TableRef.take``. Update apis.rst to try to maintain consistency of remove-and-return procs.
* remove long-deprecated 'mapIt'narimiran2019-11-131-7/+0
|
* .cursor implementation (#12637)Andreas Rumpf2019-11-121-4/+7
| | | | | | | | | | | * cursors: first implementation * added currently failing test * .cursor works for doubly linked lists * make -d:useMalloc work again * added code to nil out refs in a destructor * it's now called --gc:arc * renderer.nim: render nkBreakState properly * make simple closure iterators work without leaking
* fix #12519: introduce OrderedTable.take, CountTable.del, CountTable.take ↵Miran2019-11-081-4/+148
| | | | | | | | | | | | (#12600) * add OrderedTable.take * add CountTable.del and CountTable.take * add .since pragma to the introduced public procs * add changelog entry [ci skip]
* Make sequtils.zip return seq of anonymous tuples (#12575)Kaushal Modi2019-11-041-40/+64
| | | | | | | | | | * Make sequtils.zip return seq of anonymous tuples Earlier the tuples had named fields "a" and "b" and that made it difficult to assign the zip returned seqs to other vars which expected seqs of tuples with field names other than "a" and "b". * Make sequtils.zip backwards compatible with Nim 1.0.x
* fix several typos in documentation and comments (#12553)Nindaleth2019-10-302-2/+2
|
* sequtils: replace deprecated 'random' call within example (#12515) [backport]Jjp1372019-10-251-1/+1
|
* Fix word wrappingJjp1372019-10-222-5/+6
|