summary refs log tree commit diff stats
path: root/lib/pure/collections
Commit message (Collapse)AuthorAgeFilesLines
* Improve documentation for deques (#16589)konsumlamm2021-01-061-156/+106
|
* Improve sequtils documentation (#16559)konsumlamm2021-01-041-78/+79
| | | | | | | * Improve sequtils documentation Uncomment assertions in tests * Use present tense
* Improve documentation for critbits (#16568)konsumlamm2021-01-031-135/+107
|
* Fix #16554 (#16564)hlaaftana2021-01-031-2/+3
|
* O(1) concatenation of singly- and doubly linked lists. (#16362)Peter Salvi2020-12-201-1/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * O(1) concatenation of singly- and doubly linked lists. There is also new `toSinglyLinkedList` and `toDoublyLinkedList` functions for conversion from `openArray`s, similarly to `toHashSet` or `toTable`. * Add `sequtils` import to runnable examples with `toSeq`. * Added missing call to runnable examples. * Add .since annotation, changelog, and tests. * Rename `lists.concat` as an overload to `lists.append`. * Renamed `append` to `add` in lists. * Remove faulty `add` for `DoublyLinkedList`s. * Improved tests for lists. * `lists.add` moves the second list; added `lists.copy` for shallow copy. * More tests for `lists.add` and `lists.copy`. * More compact tests for lists with templates. * List concatenation with copying (`add`) and moving (tentatively `addMove`) * Renamed `addMove` to `addMoved`; renamed arguments according to the style guide. * Added extended example to `lists.copy`. * Corrected .since annotations to 1.6 * Add .since annotation, changelog, and tests. * Rename `lists.concat` as an overload to `lists.append`. * Renamed `append` to `add` in lists. * Remove faulty `add` for `DoublyLinkedList`s. * `lists.add` moves the second list; added `lists.copy` for shallow copy. * More tests for `lists.add` and `lists.copy`. * List concatenation with copying (`add`) and moving (tentatively `addMove`) * Renamed `addMove` to `addMoved`; renamed arguments according to the style guide. * Since declarations changed to (1,5,1). * Add .since annotation, changelog, and tests. * Rename `lists.concat` as an overload to `lists.append`. * Renamed `append` to `add` in lists. * Remove faulty `add` for `DoublyLinkedList`s. * `lists.add` moves the second list; added `lists.copy` for shallow copy. * More tests for `lists.add` and `lists.copy`. * List concatenation with copying (`add`) and moving (tentatively `addMove`) * Renamed `addMove` to `addMoved`; renamed arguments according to the style guide. * Changelog update. * Fix rebasing errors. * Self-adding with `lists.addMove` results in a cycle now. Added some extra tests.
* sequtils.nim: Change some `func` back to `proc` (#16309)ee72020-12-141-28/+28
| | | | | | | | | | | This commit changes the funcs that take a `proc` parameter back to procs. This reverts some of commit 6f57ebae349f: sequtils.nim: Use `func` (#16293) See also: - https://github.com/nim-lang/Nim/issues/16303 - https://github.com/nim-lang/Nim/pull/16304
* Fix broken links in docs (#16336)Elliot Waite2020-12-142-37/+37
| | | | | * Fix broken links in docs * Fix rand HSlice links
* clean the docs of sequtils (#16332)flywind2020-12-141-97/+89
|
* improve tests for collections (#16328)Timothee Cour2020-12-121-63/+45
| | | | | | | * improve tests for collections * remove remaining code blocks in deques.nim * improve runnableExamples
* sequtils.nim: Use `func` (#16293)ee72020-12-092-47/+47
| | | | | | | | | * sequtils.nim: proc -> func * sequtils.nim: proc -> func in links * sequtils.nim: proc -> func in non-link doc comments * test: add `sequtils` to strictFuncs test
* fixed article duplication typos (#16216)ihlec2020-12-021-1/+1
|
* fixes #15076 (#16143)Andreas Rumpf2020-11-261-5/+5
| | | | | | | | | * fixes #15076 * heapqueue: optimized for ARC * added another test case [backport:1.4] * code cleanup
* move tests to testament (#16101)flywind2020-11-242-377/+0
| | | | | | | | | * move tests to testament * minor * fix random * disable test random
* improve document for heapqueue (#16107)flywind2020-11-241-46/+69
|
* sets minor improvement (#16087)flywind2020-11-211-269/+1
|
* deques minor improvement (#16084)flywind2020-11-211-129/+18
|
* heapqueue minor improvement (#16088)flywind2020-11-211-62/+10
|
* Make IntSet a generic ordinal set OrdSet[A] (#15564)landerlo2020-11-131-687/+7
| | | | | | | | | | | | | | * Make IntSet an ordinal set OrdSet[A: Ordinal] Backward compatibility with IntSet is maintained. IntSet is an alias for OrdSet[int] * move ordsets to new file, intsets exports it * ordset, move to lib/std folder * Fix `$` for ordsets and test cleanup * Fix ordsets compilation in doc example * Rename ordsets to packedsets
* fix #15941 (#15948)flywind2020-11-131-4/+7
| | | | | | | * fix #15941 * add testcase * update
* Update tables documentation (#15807)Thomas Tay2020-11-021-0/+34
| | | | Added a case where a user might use mgetOrPut and create an accidental copy of a seq.
* Grammar fixesClyybber2020-10-301-4/+4
|
* promote `collect` macro as a map+filter replacement (#15788)Miran2020-10-301-0/+27
| | | | | * promote `collect` macro as a map+filter replacement * Update lib/pure/collections/sequtils.nim
* fix #15750narimiran2020-10-281-0/+2
|
* Tables, use sink val arguments more actively (#15625)cooldome2020-10-192-10/+10
|
* Fix doc for CountTable (#15561) [backport]Christopher Dunn2020-10-131-1/+1
|
* docs minor (#15550)flywind2020-10-111-2/+2
|
* Iterate over smaller set when computing intersection (#15497)Benjamin Lee2020-10-061-2/+9
| | | Closes #15496
* heapqueue.nim: Add `toHeapQueue` proc (#15459)ee72020-10-021-0/+18
| | | | | | | | | Similar to: - `critbits.toCritBitTree` - `deques.toDeque` - `sets.toHashSet` - `tables.toTable` Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* intsets.nim: Add `toIntSet` proc (#15460)ee72020-10-021-3/+25
| | | | | | | Similar to: - `critbits.toCritBitTree` - `deques.toDeque` - `sets.toHashSet` - `tables.toTable`
* Add critbits.toCritBitTree (#15444)Juan Carlos2020-10-011-8/+20
| | | | | * Add critbits.toCritBitTree * https://github.com/nim-lang/Nim/pull/15444#discussion_r498035342
* Add 1 overload to apply (#15439)Juan Carlos2020-10-011-0/+5
|
* string is not nil anymore (#15352)flywind2020-09-181-4/+1
|
* docs minor and #15335 (#15337)flywind2020-09-161-0/+7
|
* remove annoying messages when creating orderedTables (#15309)flywind2020-09-121-11/+11
| | | | | * nativesockets docs minor [backport: 1.2] * remove annoying messages
* fixes #15021Araq2020-09-111-2/+2
|
* Add some enhancements to `jsonutils.nim` (#15133)Ivan Bobev2020-09-092-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add some enhancements to `jsonutils.nim` * Use `jsonutils.nim` hookable API to add a possibility to deserialize JSON arrays directly to `HashSet` and `OrderedSet` types and respectively to serialize those types to JSON arrays. * Also add a possibility to deserialize JSON `null` objects to Nim option objects and respectively to serialize Nim option object to JSON object if some or to JSON `null` object if none. * Move serialization/deserialization functionality for `Table` and `OrderedTable` types from `jsonutils.nim` to `tables.nim` via the hookable API. * Add object `jsonutils.Joptions` and parameter from its type to `jsonutils.fromJson` procedure to control whether to allow deserializing JSON objects to Nim objects when the JSON has some extra or missing keys. * Add unit tests for the added functionalities to `tjsonutils.nim`. * improve fromJsonFields * Add changelog entry for the jsonutils enhancements * Add TODO in `jsonutils.nim` * Added an entry to "Future directions" section in `jsonutils.nim` as suggestion for future support of serialization and de-serialization of nested variant objects. * Added currently disabled test case in `tjsonutils.nim` for testing serialization and de-serialization of nested variant objects. * Move JSON hooks to `jsonutils.nim` Move `fromJsonHook` and `toJsonHook` procedures for different types to `jsonutils.nim` module to avoid a dependency of collections modules to the `json.nim` module. The hooks are removed from the following modules: * `tables.nim` * `sets.nim` * `options.nim` * `strtabs.nim` * Add some tests about `StringTableRef` Add tests for `StringTableRef`'s `fromJsonHook` and `toJsonHook` to `tjsonutils.nim`. * Disable a warning in `jsonutils.nim` Mark `fun` template in `jsonutils` module with `{.used.}` pragma in order to disable `[XDeclaredButNotUsed]` hint. The template is actually used by the `initCaseObject` macro in the same module. Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* fix in doc: incomplete output (#15222) [ci skip]Jon2020-08-241-1/+1
|
* deques.nim: Refactor the `toDeque` functionality (#15166)ee72020-08-071-5/+18
| | | | | | | | | | | | | | | | | | | | This commit polishes the new proc introduced by d9ed816b10a6. Changes: - Rename to `toDeque` for more consistency with well-known procs like `toHashSet` and `toTable`. - Rename the `openArray` parameter. The name `arr` was potentially less clear given that the proc can be used with a seq (or string). - Add a `since` annotation. - Reword the doc comment, and clarify that ordering is preserved. - Add runnableExamples. - Add "see also" cross linking between `initDeque` and `toDeque`. - Remove duplicate `nextPowerOfTwo`. The `initImpl` template already includes it. - Implement the proc using the `items` iterator, rather than indexing. This matches the implementation of `sets.toHashSet` and `tables.toTable`. - Add a test within `when isMainModule`. - Add a changelog entry.
* Added the ability to initialize a deque with an openArray (#15138)archnim2020-08-051-0/+6
| | | | | | | | | | | | * Add ability to initialize a deque with a sequence Example: var dq = initDeque[char](@['a', 'b', 'c']) * Update deques.nim * Optimized deque initialization * Sequence replaced by open array in deque initialization
* Fix tables.CountTable largest and smallest (#15115)treeform2020-07-291-4/+4
| | | It needs to have len defined first because of the assert .len > 0. I just moved it up a bit to make them work.
* fixes #14139 (#15107)flywind2020-07-291-3/+3
| | | | | | | * fix #14139 * Update lib/pure/collections/heapqueue.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Clyybber <darkmine956@gmail.com>
* 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-283-42/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#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.
* deprecate tables.allValues; continuation of #15047 (#15092)Miran2020-07-281-1/+2
|
* deprecate tables.add (#15047)Miran2020-07-251-4/+8
|
* 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>