data-structure-typed 2.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/COMMANDS.md +17 -0
- package/benchmark/report.html +13 -77
- package/benchmark/report.json +145 -177
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
- package/dist/cjs/data-structures/base/linear-base.js +137 -274
- package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/cjs/data-structures/graph/map-graph.js +56 -59
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/cjs/data-structures/hash/hash-map.js +270 -457
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
- package/dist/cjs/data-structures/heap/heap.js +340 -349
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/cjs/data-structures/heap/max-heap.js +11 -66
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/cjs/data-structures/heap/min-heap.js +11 -66
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
- package/dist/cjs/data-structures/queue/deque.js +309 -348
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
- package/dist/cjs/data-structures/queue/queue.js +265 -248
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
- package/dist/cjs/data-structures/stack/stack.js +181 -125
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
- package/dist/cjs/data-structures/trie/trie.js +189 -172
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
- package/dist/cjs/interfaces/graph.d.ts +16 -0
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/cjs/types/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.d.ts +1 -1
- package/dist/cjs/utils/utils.js +2 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
- package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
- package/dist/esm/data-structures/base/linear-base.js +137 -274
- package/dist/esm/data-structures/base/linear-base.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
- package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
- package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
- package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
- package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/esm/data-structures/binary-tree/bst.js +507 -487
- package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
- package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
- package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
- package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
- package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
- package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/esm/data-structures/graph/directed-graph.js +145 -233
- package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/esm/data-structures/graph/map-graph.js +56 -59
- package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
- package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
- package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/esm/data-structures/hash/hash-map.js +270 -457
- package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
- package/dist/esm/data-structures/heap/heap.d.ts +214 -289
- package/dist/esm/data-structures/heap/heap.js +329 -349
- package/dist/esm/data-structures/heap/heap.js.map +1 -1
- package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/esm/data-structures/heap/max-heap.js +11 -66
- package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
- package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/esm/data-structures/heap/min-heap.js +11 -66
- package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
- package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
- package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
- package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/esm/data-structures/queue/deque.d.ts +227 -254
- package/dist/esm/data-structures/queue/deque.js +313 -348
- package/dist/esm/data-structures/queue/deque.js.map +1 -1
- package/dist/esm/data-structures/queue/queue.d.ts +180 -201
- package/dist/esm/data-structures/queue/queue.js +263 -248
- package/dist/esm/data-structures/queue/queue.js.map +1 -1
- package/dist/esm/data-structures/stack/stack.d.ts +124 -102
- package/dist/esm/data-structures/stack/stack.js +181 -125
- package/dist/esm/data-structures/stack/stack.js.map +1 -1
- package/dist/esm/data-structures/trie/trie.d.ts +164 -165
- package/dist/esm/data-structures/trie/trie.js +193 -172
- package/dist/esm/data-structures/trie/trie.js.map +1 -1
- package/dist/esm/interfaces/binary-tree.d.ts +56 -6
- package/dist/esm/interfaces/graph.d.ts +16 -0
- package/dist/esm/types/data-structures/base/base.d.ts +1 -1
- package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/esm/types/utils/utils.d.ts +1 -0
- package/dist/esm/utils/utils.d.ts +1 -1
- package/dist/esm/utils/utils.js +2 -1
- package/dist/esm/utils/utils.js.map +1 -1
- package/dist/umd/data-structure-typed.js +4685 -6477
- package/dist/umd/data-structure-typed.min.js +8 -6
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +3 -4
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
- package/src/data-structures/binary-tree/avl-tree.ts +239 -206
- package/src/data-structures/binary-tree/binary-tree.ts +660 -889
- package/src/data-structures/binary-tree/bst.ts +568 -570
- package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
- package/src/data-structures/binary-tree/tree-counter.ts +199 -218
- package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
- package/test/integration/index.html +1 -1
- package/test/performance/benchmark-runner.ts +528 -0
- package/test/performance/reportor.mjs +43 -43
- package/test/performance/runner-config.json +39 -0
- package/test/performance/single-suite-runner.ts +69 -0
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
- package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
- package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +14 -21
- package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
- package/test/unit/data-structures/queue/queue.test.ts +4 -5
- package/test/unit/utils/utils.test.ts +0 -1
- package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
- package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterable view over key-value entries.
|
|
3
|
+
* @template K - Key type.
|
|
4
|
+
* @template V - Value type.
|
|
5
|
+
* @remarks Time O(1), Space O(1)
|
|
6
|
+
*/
|
|
1
7
|
export class IterableEntryBase {
|
|
2
8
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
|
|
7
|
-
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
8
|
-
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
9
|
-
* parameter is used to pass any additional arguments to the `_getIterator` method.
|
|
9
|
+
* Default iterator yielding `[key, value]` entries.
|
|
10
|
+
* @returns Iterator of `[K, V]`.
|
|
11
|
+
* @remarks Time O(n) to iterate, Space O(1)
|
|
10
12
|
*/
|
|
11
13
|
*[Symbol.iterator](...args) {
|
|
12
14
|
yield* this._getIterator(...args);
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* The function returns an iterator that yields key-value pairs from the object, where the value can
|
|
19
|
-
* be undefined.
|
|
17
|
+
* Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
18
|
+
* @returns Iterator of `[K, V | undefined]`.
|
|
19
|
+
* @remarks Time O(n), Space O(1)
|
|
20
20
|
*/
|
|
21
21
|
*entries() {
|
|
22
22
|
for (const item of this) {
|
|
@@ -24,10 +24,9 @@ export class IterableEntryBase {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* The function returns an iterator that yields the keys of a data structure.
|
|
27
|
+
* Iterate over keys only.
|
|
28
|
+
* @returns Iterator of keys.
|
|
29
|
+
* @remarks Time O(n), Space O(1)
|
|
31
30
|
*/
|
|
32
31
|
*keys() {
|
|
33
32
|
for (const item of this) {
|
|
@@ -35,10 +34,9 @@ export class IterableEntryBase {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* The function returns an iterator that yields the values of a collection.
|
|
37
|
+
* Iterate over values only.
|
|
38
|
+
* @returns Iterator of values.
|
|
39
|
+
* @remarks Time O(n), Space O(1)
|
|
42
40
|
*/
|
|
43
41
|
*values() {
|
|
44
42
|
for (const item of this) {
|
|
@@ -46,18 +44,11 @@ export class IterableEntryBase {
|
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
54
|
-
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
55
|
-
* met for the current element in the iteration.
|
|
56
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
57
|
-
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
58
|
-
* passed as the first argument to the `predicate` function. If `thisArg` is not provided
|
|
59
|
-
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
60
|
-
* the collection satisfies the provided predicate function, and `false` otherwise.
|
|
47
|
+
* Test whether all entries satisfy the predicate.
|
|
48
|
+
* @param predicate - `(key, value, index, self) => boolean`.
|
|
49
|
+
* @param thisArg - Optional `this` for callback.
|
|
50
|
+
* @returns `true` if all pass; otherwise `false`.
|
|
51
|
+
* @remarks Time O(n), Space O(1)
|
|
61
52
|
*/
|
|
62
53
|
every(predicate, thisArg) {
|
|
63
54
|
let index = 0;
|
|
@@ -69,19 +60,11 @@ export class IterableEntryBase {
|
|
|
69
60
|
return true;
|
|
70
61
|
}
|
|
71
62
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
78
|
-
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
79
|
-
* met for the current element in the iteration.
|
|
80
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
81
|
-
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
82
|
-
* it will be passed as the first argument to the `predicate` function. If `thisArg` is
|
|
83
|
-
* @returns a boolean value. It returns true if the predicate function returns true for any pair in
|
|
84
|
-
* the collection, and false otherwise.
|
|
63
|
+
* Test whether any entry satisfies the predicate.
|
|
64
|
+
* @param predicate - `(key, value, index, self) => boolean`.
|
|
65
|
+
* @param thisArg - Optional `this` for callback.
|
|
66
|
+
* @returns `true` if any passes; otherwise `false`.
|
|
67
|
+
* @remarks Time O(n), Space O(1)
|
|
85
68
|
*/
|
|
86
69
|
some(predicate, thisArg) {
|
|
87
70
|
let index = 0;
|
|
@@ -93,17 +76,10 @@ export class IterableEntryBase {
|
|
|
93
76
|
return false;
|
|
94
77
|
}
|
|
95
78
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* function for each pair.
|
|
101
|
-
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
102
|
-
* It takes four parameters: the value of the current element, the key of the current element, the
|
|
103
|
-
* index of the current element, and the collection itself.
|
|
104
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
105
|
-
* specify the value of `this` within the callback function. If `thisArg` is provided, it will be
|
|
106
|
-
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
79
|
+
* Visit each entry, left-to-right.
|
|
80
|
+
* @param callbackfn - `(key, value, index, self) => void`.
|
|
81
|
+
* @param thisArg - Optional `this` for callback.
|
|
82
|
+
* @remarks Time O(n), Space O(1)
|
|
107
83
|
*/
|
|
108
84
|
forEach(callbackfn, thisArg) {
|
|
109
85
|
let index = 0;
|
|
@@ -113,21 +89,11 @@ export class IterableEntryBase {
|
|
|
113
89
|
}
|
|
114
90
|
}
|
|
115
91
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* @param callbackfn - The callback function that will be called for each entry in the collection. It
|
|
122
|
-
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
|
|
123
|
-
* the collection. It should return a boolean value indicating whether the current entry matches the
|
|
124
|
-
* desired condition.
|
|
125
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
126
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
127
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
128
|
-
* @returns The method `find` returns the value of the first element in the iterable that satisfies
|
|
129
|
-
* the provided callback function. If no element satisfies the callback function, `undefined` is
|
|
130
|
-
* returned.
|
|
92
|
+
* Find the first entry that matches a predicate.
|
|
93
|
+
* @param callbackfn - `(key, value, index, self) => boolean`.
|
|
94
|
+
* @param thisArg - Optional `this` for callback.
|
|
95
|
+
* @returns Matching `[key, value]` or `undefined`.
|
|
96
|
+
* @remarks Time O(n), Space O(1)
|
|
131
97
|
*/
|
|
132
98
|
find(callbackfn, thisArg) {
|
|
133
99
|
let index = 0;
|
|
@@ -139,14 +105,10 @@ export class IterableEntryBase {
|
|
|
139
105
|
return;
|
|
140
106
|
}
|
|
141
107
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
|
|
147
|
-
* the key that we want to check for existence in the data structure.
|
|
148
|
-
* @returns a boolean value. It returns true if the key is found in the collection, and false
|
|
149
|
-
* otherwise.
|
|
108
|
+
* Whether the given key exists.
|
|
109
|
+
* @param key - Key to test.
|
|
110
|
+
* @returns `true` if found; otherwise `false`.
|
|
111
|
+
* @remarks Time O(n) generic, Space O(1)
|
|
150
112
|
*/
|
|
151
113
|
has(key) {
|
|
152
114
|
for (const item of this) {
|
|
@@ -157,13 +119,10 @@ export class IterableEntryBase {
|
|
|
157
119
|
return false;
|
|
158
120
|
}
|
|
159
121
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
|
|
165
|
-
* collection.
|
|
166
|
-
* @returns a boolean value, either true or false.
|
|
122
|
+
* Whether there exists an entry with the given value.
|
|
123
|
+
* @param value - Value to test.
|
|
124
|
+
* @returns `true` if found; otherwise `false`.
|
|
125
|
+
* @remarks Time O(n), Space O(1)
|
|
167
126
|
*/
|
|
168
127
|
hasValue(value) {
|
|
169
128
|
for (const [, elementValue] of this) {
|
|
@@ -173,14 +132,10 @@ export class IterableEntryBase {
|
|
|
173
132
|
return false;
|
|
174
133
|
}
|
|
175
134
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
|
|
181
|
-
* searched for in the collection.
|
|
182
|
-
* @returns The `get` method returns the value associated with the specified key if it exists in the
|
|
183
|
-
* collection, otherwise it returns `undefined`.
|
|
135
|
+
* Get the value under a key.
|
|
136
|
+
* @param key - Key to look up.
|
|
137
|
+
* @returns Value or `undefined`.
|
|
138
|
+
* @remarks Time O(n) generic, Space O(1)
|
|
184
139
|
*/
|
|
185
140
|
get(key) {
|
|
186
141
|
for (const item of this) {
|
|
@@ -191,20 +146,11 @@ export class IterableEntryBase {
|
|
|
191
146
|
return;
|
|
192
147
|
}
|
|
193
148
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
200
|
-
* It takes four arguments: the current accumulator value, the current value of the element, the key
|
|
201
|
-
* of the element, and the index of the element in the collection. It should return the updated
|
|
202
|
-
* accumulator value.
|
|
203
|
-
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
204
|
-
* is the value that will be used as the first argument to the `callbackfn` function when reducing
|
|
205
|
-
* the elements of the collection.
|
|
206
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
207
|
-
* all the elements in the collection.
|
|
149
|
+
* Reduce entries into a single accumulator.
|
|
150
|
+
* @param callbackfn - `(acc, value, key, index, self) => acc`.
|
|
151
|
+
* @param initialValue - Initial accumulator.
|
|
152
|
+
* @returns Final accumulator.
|
|
153
|
+
* @remarks Time O(n), Space O(1)
|
|
208
154
|
*/
|
|
209
155
|
reduce(callbackfn, initialValue) {
|
|
210
156
|
let accumulator = initialValue;
|
|
@@ -216,19 +162,16 @@ export class IterableEntryBase {
|
|
|
216
162
|
return accumulator;
|
|
217
163
|
}
|
|
218
164
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* The print function logs the elements of an array to the console.
|
|
165
|
+
* Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
|
|
166
|
+
* @returns Array of entries (default) or a string.
|
|
167
|
+
* @remarks Time O(n), Space O(n)
|
|
223
168
|
*/
|
|
224
169
|
toVisual() {
|
|
225
170
|
return [...this];
|
|
226
171
|
}
|
|
227
172
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
* The print function logs the elements of an array to the console.
|
|
173
|
+
* Print a human-friendly representation to the console.
|
|
174
|
+
* @remarks Time O(n), Space O(n)
|
|
232
175
|
*/
|
|
233
176
|
print() {
|
|
234
177
|
console.log(this.toVisual());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-entry-base.js","sourceRoot":"","sources":["../../../../src/data-structures/base/iterable-entry-base.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,iBAAiB;
|
|
1
|
+
{"version":3,"file":"iterable-entry-base.js","sourceRoot":"","sources":["../../../../src/data-structures/base/iterable-entry-base.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAgB,iBAAiB;IAQrC;;;;OAIG;IACH,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAW;QAC/B,KAAK,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,CAAC,OAAO;QACN,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,CAAC,IAAI;QACH,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,CAAC,MAAM;QACL,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAuC,EAAE,OAAa;QAC1D,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;gBAC9D,OAAO,KAAK,CAAC;YACf,CAAC;QACH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