priority-queue-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.
Files changed (101) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +186 -83
  2. package/dist/data-structures/base/iterable-element-base.js +149 -107
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
  4. package/dist/data-structures/base/iterable-entry-base.js +59 -116
  5. package/dist/data-structures/base/linear-base.d.ts +250 -192
  6. package/dist/data-structures/base/linear-base.js +137 -274
  7. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  8. package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
  9. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  10. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  11. package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
  12. package/dist/data-structures/binary-tree/avl-tree.js +208 -195
  13. package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
  14. package/dist/data-structures/binary-tree/binary-tree.js +602 -873
  15. package/dist/data-structures/binary-tree/bst.d.ts +258 -306
  16. package/dist/data-structures/binary-tree/bst.js +505 -481
  17. package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  18. package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
  19. package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
  20. package/dist/data-structures/binary-tree/tree-counter.js +172 -203
  21. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  22. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
  23. package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
  24. package/dist/data-structures/graph/abstract-graph.js +267 -237
  25. package/dist/data-structures/graph/directed-graph.d.ts +108 -224
  26. package/dist/data-structures/graph/directed-graph.js +146 -233
  27. package/dist/data-structures/graph/map-graph.d.ts +49 -55
  28. package/dist/data-structures/graph/map-graph.js +56 -59
  29. package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
  30. package/dist/data-structures/graph/undirected-graph.js +129 -149
  31. package/dist/data-structures/hash/hash-map.d.ts +164 -338
  32. package/dist/data-structures/hash/hash-map.js +270 -457
  33. package/dist/data-structures/heap/heap.d.ts +214 -289
  34. package/dist/data-structures/heap/heap.js +340 -349
  35. package/dist/data-structures/heap/max-heap.d.ts +11 -47
  36. package/dist/data-structures/heap/max-heap.js +11 -66
  37. package/dist/data-structures/heap/min-heap.d.ts +12 -47
  38. package/dist/data-structures/heap/min-heap.js +11 -66
  39. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  40. package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
  41. package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  42. package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
  43. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  44. package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
  45. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  46. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
  47. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  48. package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
  49. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
  50. package/dist/data-structures/priority-queue/priority-queue.js +8 -83
  51. package/dist/data-structures/queue/deque.d.ts +227 -254
  52. package/dist/data-structures/queue/deque.js +309 -348
  53. package/dist/data-structures/queue/queue.d.ts +180 -201
  54. package/dist/data-structures/queue/queue.js +265 -248
  55. package/dist/data-structures/stack/stack.d.ts +124 -102
  56. package/dist/data-structures/stack/stack.js +181 -125
  57. package/dist/data-structures/trie/trie.d.ts +164 -165
  58. package/dist/data-structures/trie/trie.js +189 -172
  59. package/dist/interfaces/binary-tree.d.ts +56 -6
  60. package/dist/interfaces/graph.d.ts +16 -0
  61. package/dist/types/data-structures/base/base.d.ts +1 -1
  62. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
  63. package/dist/types/utils/utils.d.ts +1 -0
  64. package/dist/utils/utils.d.ts +1 -1
  65. package/dist/utils/utils.js +2 -1
  66. package/package.json +2 -2
  67. package/src/data-structures/base/iterable-element-base.ts +238 -115
  68. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  69. package/src/data-structures/base/linear-base.ts +271 -277
  70. package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
  71. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
  72. package/src/data-structures/binary-tree/avl-tree.ts +237 -206
  73. package/src/data-structures/binary-tree/binary-tree.ts +665 -896
  74. package/src/data-structures/binary-tree/bst.ts +565 -572
  75. package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
  76. package/src/data-structures/binary-tree/tree-counter.ts +195 -219
  77. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
  78. package/src/data-structures/graph/abstract-graph.ts +339 -264
  79. package/src/data-structures/graph/directed-graph.ts +146 -236
  80. package/src/data-structures/graph/map-graph.ts +63 -60
  81. package/src/data-structures/graph/undirected-graph.ts +129 -152
  82. package/src/data-structures/hash/hash-map.ts +274 -496
  83. package/src/data-structures/heap/heap.ts +389 -402
  84. package/src/data-structures/heap/max-heap.ts +12 -76
  85. package/src/data-structures/heap/min-heap.ts +13 -76
  86. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  87. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  88. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  89. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  90. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  91. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  92. package/src/data-structures/queue/deque.ts +381 -357
  93. package/src/data-structures/queue/queue.ts +310 -264
  94. package/src/data-structures/stack/stack.ts +217 -131
  95. package/src/data-structures/trie/trie.ts +240 -175
  96. package/src/interfaces/binary-tree.ts +240 -6
  97. package/src/interfaces/graph.ts +37 -0
  98. package/src/types/data-structures/base/base.ts +5 -5
  99. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  100. package/src/types/utils/utils.ts +2 -0
  101. 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
- * Time Complexity: O(n)
7
- * Space Complexity: O(1)
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
- * Time Complexity: O(n)
19
- * Space Complexity: O(n)
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
- * Time Complexity: O(n)
31
- * Space Complexity: O(n)
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
- * Time Complexity: O(n)
42
- * Space Complexity: O(n)
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
- * Time Complexity: O(n)
53
- * Space Complexity: O(1)
54
- *
55
- * The `every` function checks if every element in a collection satisfies a given condition.
56
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
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
- * Time Complexity: O(n)
76
- * Space Complexity: O(1)
77
- *
78
- * The "some" function iterates over a collection and returns true if at least one element satisfies
79
- * a given predicate.
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
- * Time Complexity: O(n)
100
- * Space Complexity: O(1)
101
- *
102
- * The `forEach` function iterates over each key-value pair in a collection and executes a callback
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
- * Time Complexity: O(n)
120
- * Space Complexity: O(1)
121
- *
122
- * The `find` function iterates over the entries of a collection and returns the first value for
123
- * which the callback function returns true.
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
- * Time Complexity: O(n)
146
- * Space Complexity: O(1)
147
- *
148
- * The function checks if a given key exists in a collection.
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
- * Time Complexity: O(n)
164
- * Space Complexity: O(1)
165
- *
166
- * The function checks if a given value exists in a collection.
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
- * Time Complexity: O(n)
180
- * Space Complexity: O(1)
181
- *
182
- * The `get` function retrieves the value associated with a given key from a collection.
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
- * Time Complexity: O(n)
198
- * Space Complexity: O(1)
199
- *
200
- * The `reduce` function iterates over key-value pairs and applies a callback function to each pair,
201
- * accumulating a single value.
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
- * Time Complexity: O(n)
223
- * Space Complexity: O(n)
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
- * Time Complexity: O(n)
232
- * Space Complexity: O(n)
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());