bst-typed 2.0.5 → 2.1.1
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/dist/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +602 -873
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- 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 +196 -217
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
- package/src/data-structures/binary-tree/avl-tree.ts +237 -206
- package/src/data-structures/binary-tree/binary-tree.ts +665 -896
- package/src/data-structures/binary-tree/bst.ts +565 -572
- package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
- package/src/data-structures/binary-tree/tree-counter.ts +195 -219
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
- 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
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IterableEntryBase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Iterable view over key-value entries.
|
|
6
|
+
* @template K - Key type.
|
|
7
|
+
* @template V - Value type.
|
|
8
|
+
* @remarks Time O(1), Space O(1)
|
|
9
|
+
*/
|
|
4
10
|
class IterableEntryBase {
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* The function is an implementation of the Symbol.iterator method that returns an iterable iterator.
|
|
10
|
-
* @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
|
|
11
|
-
* allows the function to accept any number of arguments as an array. In this case, the `args`
|
|
12
|
-
* parameter is used to pass any additional arguments to the `_getIterator` method.
|
|
12
|
+
* Default iterator yielding `[key, value]` entries.
|
|
13
|
+
* @returns Iterator of `[K, V]`.
|
|
14
|
+
* @remarks Time O(n) to iterate, Space O(1)
|
|
13
15
|
*/
|
|
14
16
|
*[Symbol.iterator](...args) {
|
|
15
17
|
yield* this._getIterator(...args);
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* The function returns an iterator that yields key-value pairs from the object, where the value can
|
|
22
|
-
* be undefined.
|
|
20
|
+
* Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
21
|
+
* @returns Iterator of `[K, V | undefined]`.
|
|
22
|
+
* @remarks Time O(n), Space O(1)
|
|
23
23
|
*/
|
|
24
24
|
*entries() {
|
|
25
25
|
for (const item of this) {
|
|
@@ -27,10 +27,9 @@ class IterableEntryBase {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* The function returns an iterator that yields the keys of a data structure.
|
|
30
|
+
* Iterate over keys only.
|
|
31
|
+
* @returns Iterator of keys.
|
|
32
|
+
* @remarks Time O(n), Space O(1)
|
|
34
33
|
*/
|
|
35
34
|
*keys() {
|
|
36
35
|
for (const item of this) {
|
|
@@ -38,10 +37,9 @@ class IterableEntryBase {
|
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* The function returns an iterator that yields the values of a collection.
|
|
40
|
+
* Iterate over values only.
|
|
41
|
+
* @returns Iterator of values.
|
|
42
|
+
* @remarks Time O(n), Space O(1)
|
|
45
43
|
*/
|
|
46
44
|
*values() {
|
|
47
45
|
for (const item of this) {
|
|
@@ -49,18 +47,11 @@ class IterableEntryBase {
|
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
58
|
-
* met for the current element in the iteration.
|
|
59
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
60
|
-
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
61
|
-
* passed as the first argument to the `predicate` function. If `thisArg` is not provided
|
|
62
|
-
* @returns The `every` method is returning a boolean value. It returns `true` if every element in
|
|
63
|
-
* the collection satisfies the provided predicate function, and `false` otherwise.
|
|
50
|
+
* Test whether all entries satisfy the predicate.
|
|
51
|
+
* @param predicate - `(key, value, index, self) => boolean`.
|
|
52
|
+
* @param thisArg - Optional `this` for callback.
|
|
53
|
+
* @returns `true` if all pass; otherwise `false`.
|
|
54
|
+
* @remarks Time O(n), Space O(1)
|
|
64
55
|
*/
|
|
65
56
|
every(predicate, thisArg) {
|
|
66
57
|
let index = 0;
|
|
@@ -72,19 +63,11 @@ class IterableEntryBase {
|
|
|
72
63
|
return true;
|
|
73
64
|
}
|
|
74
65
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
81
|
-
* `value`, `key`, and `index`. It should return a boolean value indicating whether the condition is
|
|
82
|
-
* met for the current element in the iteration.
|
|
83
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
84
|
-
* to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
|
|
85
|
-
* it will be passed as the first argument to the `predicate` function. If `thisArg` is
|
|
86
|
-
* @returns a boolean value. It returns true if the predicate function returns true for any pair in
|
|
87
|
-
* the collection, and false otherwise.
|
|
66
|
+
* Test whether any entry satisfies the predicate.
|
|
67
|
+
* @param predicate - `(key, value, index, self) => boolean`.
|
|
68
|
+
* @param thisArg - Optional `this` for callback.
|
|
69
|
+
* @returns `true` if any passes; otherwise `false`.
|
|
70
|
+
* @remarks Time O(n), Space O(1)
|
|
88
71
|
*/
|
|
89
72
|
some(predicate, thisArg) {
|
|
90
73
|
let index = 0;
|
|
@@ -96,17 +79,10 @@ class IterableEntryBase {
|
|
|
96
79
|
return false;
|
|
97
80
|
}
|
|
98
81
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* function for each pair.
|
|
104
|
-
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
105
|
-
* It takes four parameters: the value of the current element, the key of the current element, the
|
|
106
|
-
* index of the current element, and the collection itself.
|
|
107
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
108
|
-
* specify the value of `this` within the callback function. If `thisArg` is provided, it will be
|
|
109
|
-
* used as the `this` value when calling the callback function. If `thisArg` is not provided, `
|
|
82
|
+
* Visit each entry, left-to-right.
|
|
83
|
+
* @param callbackfn - `(key, value, index, self) => void`.
|
|
84
|
+
* @param thisArg - Optional `this` for callback.
|
|
85
|
+
* @remarks Time O(n), Space O(1)
|
|
110
86
|
*/
|
|
111
87
|
forEach(callbackfn, thisArg) {
|
|
112
88
|
let index = 0;
|
|
@@ -116,21 +92,11 @@ class IterableEntryBase {
|
|
|
116
92
|
}
|
|
117
93
|
}
|
|
118
94
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @param callbackfn - The callback function that will be called for each entry in the collection. It
|
|
125
|
-
* takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
|
|
126
|
-
* the collection. It should return a boolean value indicating whether the current entry matches the
|
|
127
|
-
* desired condition.
|
|
128
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
129
|
-
* to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
|
|
130
|
-
* be passed as the `this` value to the `callbackfn` function. If `thisArg
|
|
131
|
-
* @returns The method `find` returns the value of the first element in the iterable that satisfies
|
|
132
|
-
* the provided callback function. If no element satisfies the callback function, `undefined` is
|
|
133
|
-
* returned.
|
|
95
|
+
* Find the first entry that matches a predicate.
|
|
96
|
+
* @param callbackfn - `(key, value, index, self) => boolean`.
|
|
97
|
+
* @param thisArg - Optional `this` for callback.
|
|
98
|
+
* @returns Matching `[key, value]` or `undefined`.
|
|
99
|
+
* @remarks Time O(n), Space O(1)
|
|
134
100
|
*/
|
|
135
101
|
find(callbackfn, thisArg) {
|
|
136
102
|
let index = 0;
|
|
@@ -142,14 +108,10 @@ class IterableEntryBase {
|
|
|
142
108
|
return;
|
|
143
109
|
}
|
|
144
110
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
|
|
150
|
-
* the key that we want to check for existence in the data structure.
|
|
151
|
-
* @returns a boolean value. It returns true if the key is found in the collection, and false
|
|
152
|
-
* otherwise.
|
|
111
|
+
* Whether the given key exists.
|
|
112
|
+
* @param key - Key to test.
|
|
113
|
+
* @returns `true` if found; otherwise `false`.
|
|
114
|
+
* @remarks Time O(n) generic, Space O(1)
|
|
153
115
|
*/
|
|
154
116
|
has(key) {
|
|
155
117
|
for (const item of this) {
|
|
@@ -160,13 +122,10 @@ class IterableEntryBase {
|
|
|
160
122
|
return false;
|
|
161
123
|
}
|
|
162
124
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
* @param {V} value - The parameter "value" is the value that we want to check if it exists in the
|
|
168
|
-
* collection.
|
|
169
|
-
* @returns a boolean value, either true or false.
|
|
125
|
+
* Whether there exists an entry with the given value.
|
|
126
|
+
* @param value - Value to test.
|
|
127
|
+
* @returns `true` if found; otherwise `false`.
|
|
128
|
+
* @remarks Time O(n), Space O(1)
|
|
170
129
|
*/
|
|
171
130
|
hasValue(value) {
|
|
172
131
|
for (const [, elementValue] of this) {
|
|
@@ -176,14 +135,10 @@ class IterableEntryBase {
|
|
|
176
135
|
return false;
|
|
177
136
|
}
|
|
178
137
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @param {K} key - K (the type of the key) - This parameter represents the key that is being
|
|
184
|
-
* searched for in the collection.
|
|
185
|
-
* @returns The `get` method returns the value associated with the specified key if it exists in the
|
|
186
|
-
* collection, otherwise it returns `undefined`.
|
|
138
|
+
* Get the value under a key.
|
|
139
|
+
* @param key - Key to look up.
|
|
140
|
+
* @returns Value or `undefined`.
|
|
141
|
+
* @remarks Time O(n) generic, Space O(1)
|
|
187
142
|
*/
|
|
188
143
|
get(key) {
|
|
189
144
|
for (const item of this) {
|
|
@@ -194,20 +149,11 @@ class IterableEntryBase {
|
|
|
194
149
|
return;
|
|
195
150
|
}
|
|
196
151
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* @param callbackfn - The callback function that will be called for each element in the collection.
|
|
203
|
-
* It takes four arguments: the current accumulator value, the current value of the element, the key
|
|
204
|
-
* of the element, and the index of the element in the collection. It should return the updated
|
|
205
|
-
* accumulator value.
|
|
206
|
-
* @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
207
|
-
* is the value that will be used as the first argument to the `callbackfn` function when reducing
|
|
208
|
-
* the elements of the collection.
|
|
209
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
210
|
-
* all the elements in the collection.
|
|
152
|
+
* Reduce entries into a single accumulator.
|
|
153
|
+
* @param callbackfn - `(acc, value, key, index, self) => acc`.
|
|
154
|
+
* @param initialValue - Initial accumulator.
|
|
155
|
+
* @returns Final accumulator.
|
|
156
|
+
* @remarks Time O(n), Space O(1)
|
|
211
157
|
*/
|
|
212
158
|
reduce(callbackfn, initialValue) {
|
|
213
159
|
let accumulator = initialValue;
|
|
@@ -219,19 +165,16 @@ class IterableEntryBase {
|
|
|
219
165
|
return accumulator;
|
|
220
166
|
}
|
|
221
167
|
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* The print function logs the elements of an array to the console.
|
|
168
|
+
* Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
|
|
169
|
+
* @returns Array of entries (default) or a string.
|
|
170
|
+
* @remarks Time O(n), Space O(n)
|
|
226
171
|
*/
|
|
227
172
|
toVisual() {
|
|
228
173
|
return [...this];
|
|
229
174
|
}
|
|
230
175
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* The print function logs the elements of an array to the console.
|
|
176
|
+
* Print a human-friendly representation to the console.
|
|
177
|
+
* @remarks Time O(n), Space O(n)
|
|
235
178
|
*/
|
|
236
179
|
print() {
|
|
237
180
|
console.log(this.toVisual());
|