data-structure-typed 1.52.6 → 1.52.7

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 (178) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +33 -30
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +156 -156
  5. package/dist/cjs/constants/index.d.ts +4 -0
  6. package/dist/cjs/constants/index.js +9 -0
  7. package/dist/cjs/constants/index.js.map +1 -0
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
  12. package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js +668 -597
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
  25. package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
  26. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
  29. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
  31. package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
  32. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  33. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
  34. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  35. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
  36. package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
  37. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  39. package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
  40. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
  42. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  43. package/dist/cjs/data-structures/hash/hash-map.js +1 -1
  44. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  45. package/dist/cjs/data-structures/heap/heap.js +3 -3
  46. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  53. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  54. package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
  55. package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
  56. package/dist/cjs/data-structures/matrix/navigator.js +4 -2
  57. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
  59. package/dist/cjs/data-structures/queue/deque.js +29 -29
  60. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  61. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  62. package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
  63. package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
  64. package/dist/cjs/data-structures/trie/trie.js +1 -1
  65. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  66. package/dist/cjs/index.d.ts +1 -0
  67. package/dist/cjs/index.js +1 -0
  68. package/dist/cjs/index.js.map +1 -1
  69. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  70. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  71. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
  72. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  73. package/dist/mjs/constants/index.d.ts +4 -0
  74. package/dist/mjs/constants/index.js +5 -0
  75. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
  76. package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
  77. package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
  78. package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
  79. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
  80. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
  81. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
  82. package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
  83. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
  84. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
  85. package/dist/mjs/data-structures/binary-tree/binary-tree.js +667 -591
  86. package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
  87. package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
  88. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
  89. package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
  90. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
  91. package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
  92. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
  93. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
  94. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
  95. package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
  96. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  97. package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
  98. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
  99. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  100. package/dist/mjs/data-structures/hash/hash-map.js +1 -1
  101. package/dist/mjs/data-structures/heap/heap.js +3 -3
  102. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  103. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
  104. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  105. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
  106. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
  107. package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
  108. package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
  109. package/dist/mjs/data-structures/matrix/navigator.js +4 -2
  110. package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
  111. package/dist/mjs/data-structures/queue/deque.js +29 -29
  112. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  113. package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
  114. package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
  115. package/dist/mjs/data-structures/trie/trie.js +1 -1
  116. package/dist/mjs/index.d.ts +1 -0
  117. package/dist/mjs/index.js +1 -0
  118. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  119. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
  120. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
  121. package/dist/umd/data-structure-typed.js +1343 -1615
  122. package/dist/umd/data-structure-typed.min.js +10 -3
  123. package/dist/umd/data-structure-typed.min.js.map +1 -1
  124. package/eslint.config.mjs +69 -0
  125. package/package.json +30 -28
  126. package/src/constants/index.ts +4 -0
  127. package/src/data-structures/base/iterable-element-base.ts +11 -1
  128. package/src/data-structures/base/iterable-entry-base.ts +11 -19
  129. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
  130. package/src/data-structures/binary-tree/avl-tree.ts +69 -71
  131. package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
  132. package/src/data-structures/binary-tree/binary-tree.ts +697 -725
  133. package/src/data-structures/binary-tree/bst.ts +123 -129
  134. package/src/data-structures/binary-tree/rb-tree.ts +44 -46
  135. package/src/data-structures/binary-tree/segment-tree.ts +2 -2
  136. package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
  137. package/src/data-structures/graph/abstract-graph.ts +6 -6
  138. package/src/data-structures/graph/directed-graph.ts +4 -4
  139. package/src/data-structures/graph/undirected-graph.ts +2 -2
  140. package/src/data-structures/hash/hash-map.ts +3 -3
  141. package/src/data-structures/heap/heap.ts +3 -3
  142. package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
  143. package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
  144. package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
  145. package/src/data-structures/matrix/matrix.ts +2 -2
  146. package/src/data-structures/matrix/navigator.ts +4 -4
  147. package/src/data-structures/queue/deque.ts +31 -31
  148. package/src/data-structures/queue/queue.ts +1 -1
  149. package/src/data-structures/stack/stack.ts +2 -2
  150. package/src/data-structures/trie/trie.ts +3 -3
  151. package/src/index.ts +1 -0
  152. package/src/interfaces/binary-tree.ts +3 -3
  153. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
  154. package/test/config.ts +1 -7
  155. package/test/integration/all-in-one.test.ts +2 -2
  156. package/test/integration/avl-tree.test.ts +2 -2
  157. package/test/integration/bst.test.ts +17 -16
  158. package/test/integration/heap.test.js +6 -1
  159. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
  160. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
  161. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +51 -26
  162. package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
  163. package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
  164. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
  165. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
  166. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
  167. package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
  168. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  169. package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
  170. package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
  171. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
  172. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  173. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  174. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
  175. package/test/unit/data-structures/stack/stack.test.ts +6 -0
  176. package/test/unit/unrestricted-interconversion.test.ts +24 -24
  177. package/test/utils/big-o.ts +5 -4
  178. package/.eslintrc.js +0 -64
@@ -242,7 +242,7 @@ export class DoublyLinkedList extends IterableElementBase {
242
242
  * or the linked list is empty, it will return undefined.
243
243
  */
244
244
  at(index) {
245
- if (index < 0 || index >= this.size)
245
+ if (index < 0 || index >= this._size)
246
246
  return undefined;
247
247
  let current = this.head;
248
248
  for (let i = 0; i < index; i++) {
@@ -262,7 +262,7 @@ export class DoublyLinkedList extends IterableElementBase {
262
262
  * valid range of the linked list, otherwise it returns `undefined`.
263
263
  */
264
264
  getNodeAt(index) {
265
- if (index < 0 || index >= this.size)
265
+ if (index < 0 || index >= this._size)
266
266
  return undefined;
267
267
  let current = this.head;
268
268
  for (let i = 0; i < index; i++) {
@@ -303,13 +303,13 @@ export class DoublyLinkedList extends IterableElementBase {
303
303
  * if the index is out of bounds.
304
304
  */
305
305
  addAt(index, value) {
306
- if (index < 0 || index > this.size)
306
+ if (index < 0 || index > this._size)
307
307
  return false;
308
308
  if (index === 0) {
309
309
  this.unshift(value);
310
310
  return true;
311
311
  }
312
- if (index === this.size) {
312
+ if (index === this._size) {
313
313
  this.push(value);
314
314
  return true;
315
315
  }
@@ -407,13 +407,13 @@ export class DoublyLinkedList extends IterableElementBase {
407
407
  * bounds.
408
408
  */
409
409
  deleteAt(index) {
410
- if (index < 0 || index >= this.size)
410
+ if (index < 0 || index >= this._size)
411
411
  return false;
412
412
  if (index === 0) {
413
413
  this.shift();
414
414
  return true;
415
415
  }
416
- if (index === this.size - 1) {
416
+ if (index === this._size - 1) {
417
417
  this.pop();
418
418
  return true;
419
419
  }
@@ -469,7 +469,7 @@ export class DoublyLinkedList extends IterableElementBase {
469
469
  * @returns A boolean value is being returned.
470
470
  */
471
471
  isEmpty() {
472
- return this.size === 0;
472
+ return this._size === 0;
473
473
  }
474
474
  /**
475
475
  * Time Complexity: O(1)
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, SinglyLinkedListOptions } from '../../types';
@@ -211,7 +211,7 @@ export class SinglyLinkedList extends IterableElementBase {
211
211
  * `undefined` if the index is out of bounds.
212
212
  */
213
213
  at(index) {
214
- if (index < 0 || index >= this.size)
214
+ if (index < 0 || index >= this._size)
215
215
  return undefined;
216
216
  let current = this.head;
217
217
  for (let i = 0; i < index; i++) {
@@ -247,13 +247,13 @@ export class SinglyLinkedList extends IterableElementBase {
247
247
  * bounds.
248
248
  */
249
249
  deleteAt(index) {
250
- if (index < 0 || index >= this.size)
250
+ if (index < 0 || index >= this._size)
251
251
  return false;
252
252
  if (index === 0) {
253
253
  this.shift();
254
254
  return true;
255
255
  }
256
- if (index === this.size - 1) {
256
+ if (index === this._size - 1) {
257
257
  this.pop();
258
258
  return true;
259
259
  }
@@ -319,13 +319,13 @@ export class SinglyLinkedList extends IterableElementBase {
319
319
  * if the index is out of bounds.
320
320
  */
321
321
  addAt(index, value) {
322
- if (index < 0 || index > this.size)
322
+ if (index < 0 || index > this._size)
323
323
  return false;
324
324
  if (index === 0) {
325
325
  this.unshift(value);
326
326
  return true;
327
327
  }
328
- if (index === this.size) {
328
+ if (index === this._size) {
329
329
  this.push(value);
330
330
  return true;
331
331
  }
@@ -342,7 +342,7 @@ export class SinglyLinkedList extends IterableElementBase {
342
342
  * @returns A boolean value indicating whether the length of the object is equal to 0.
343
343
  */
344
344
  isEmpty() {
345
- return this.size === 0;
345
+ return this._size === 0;
346
346
  }
347
347
  /**
348
348
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { SkipLinkedListOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { MatrixOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { Direction, NavigatorParams, Turning } from '../../types';
@@ -30,7 +30,8 @@ export class Navigator {
30
30
  this._cur = cur;
31
31
  this._character = new Character(charDir, turning);
32
32
  this.onMove = onMove;
33
- this.onMove && this.onMove(this._cur);
33
+ if (this.onMove)
34
+ this.onMove(this._cur);
34
35
  this._VISITED = VISITED;
35
36
  this._matrix[this._cur[0]][this._cur[1]] = this._VISITED;
36
37
  }
@@ -103,6 +104,7 @@ export class Navigator {
103
104
  }
104
105
  const [i, j] = this._cur;
105
106
  this._matrix[i][j] = this._VISITED;
106
- this.onMove && this.onMove(this._cur);
107
+ if (this.onMove)
108
+ this.onMove(this._cur);
107
109
  }
108
110
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { DequeOptions, ElementCallback, IterableWithSizeOrLength } from '../../types';
@@ -287,7 +287,7 @@ export declare class Deque<E = any, R = any> extends IterableElementBase<E, R, D
287
287
  * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
288
288
  * memory usage.
289
289
  * @returns Nothing is being returned. The function is using the `return` statement to exit early if
290
- * `this.size` is 0, but it does not return any value.
290
+ * `this._size` is 0, but it does not return any value.
291
291
  */
292
292
  shrinkToFit(): void;
293
293
  /**
@@ -139,7 +139,7 @@ export class Deque extends IterableElementBase {
139
139
  * @returns The first element of the collection, of type E, is being returned.
140
140
  */
141
141
  get first() {
142
- if (this.size === 0)
142
+ if (this._size === 0)
143
143
  return;
144
144
  return this._buckets[this._bucketFirst][this._firstInBucket];
145
145
  }
@@ -148,7 +148,7 @@ export class Deque extends IterableElementBase {
148
148
  * @return The last element in the array
149
149
  */
150
150
  get last() {
151
- if (this.size === 0)
151
+ if (this._size === 0)
152
152
  return;
153
153
  return this._buckets[this._bucketLast][this._lastInBucket];
154
154
  }
@@ -162,7 +162,7 @@ export class Deque extends IterableElementBase {
162
162
  * @returns The size of the data structure after the element has been pushed.
163
163
  */
164
164
  push(element) {
165
- if (this.size) {
165
+ if (this._size) {
166
166
  if (this._lastInBucket < this._bucketSize - 1) {
167
167
  this._lastInBucket += 1;
168
168
  }
@@ -192,10 +192,10 @@ export class Deque extends IterableElementBase {
192
192
  * @returns The element that was removed from the data structure is being returned.
193
193
  */
194
194
  pop() {
195
- if (this.size === 0)
195
+ if (this._size === 0)
196
196
  return;
197
197
  const element = this._buckets[this._bucketLast][this._lastInBucket];
198
- if (this.size !== 1) {
198
+ if (this._size !== 1) {
199
199
  if (this._lastInBucket > 0) {
200
200
  this._lastInBucket -= 1;
201
201
  }
@@ -222,7 +222,7 @@ export class Deque extends IterableElementBase {
222
222
  * @returns The size of the data structure after the element has been added.
223
223
  */
224
224
  unshift(element) {
225
- if (this.size) {
225
+ if (this._size) {
226
226
  if (this._firstInBucket > 0) {
227
227
  this._firstInBucket -= 1;
228
228
  }
@@ -253,10 +253,10 @@ export class Deque extends IterableElementBase {
253
253
  * returned.
254
254
  */
255
255
  shift() {
256
- if (this.size === 0)
256
+ if (this._size === 0)
257
257
  return;
258
258
  const element = this._buckets[this._bucketFirst][this._firstInBucket];
259
- if (this.size !== 1) {
259
+ if (this._size !== 1) {
260
260
  if (this._firstInBucket < this._bucketSize - 1) {
261
261
  this._firstInBucket += 1;
262
262
  }
@@ -280,7 +280,7 @@ export class Deque extends IterableElementBase {
280
280
  * @returns A boolean value indicating whether the size of the object is 0 or not.
281
281
  */
282
282
  isEmpty() {
283
- return this.size === 0;
283
+ return this._size === 0;
284
284
  }
285
285
  /**
286
286
  * Time Complexity: O(1)
@@ -300,7 +300,7 @@ export class Deque extends IterableElementBase {
300
300
  */
301
301
  *begin() {
302
302
  let index = 0;
303
- while (index < this.size) {
303
+ while (index < this._size) {
304
304
  yield this.at(index);
305
305
  index++;
306
306
  }
@@ -310,7 +310,7 @@ export class Deque extends IterableElementBase {
310
310
  * the last element.
311
311
  */
312
312
  *reverseBegin() {
313
- let index = this.size - 1;
313
+ let index = this._size - 1;
314
314
  while (index >= 0) {
315
315
  yield this.at(index);
316
316
  index--;
@@ -327,7 +327,7 @@ export class Deque extends IterableElementBase {
327
327
  * @returns The element at the specified position in the data structure is being returned.
328
328
  */
329
329
  at(pos) {
330
- rangeCheck(pos, 0, this.size - 1);
330
+ rangeCheck(pos, 0, this._size - 1);
331
331
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
332
332
  return this._buckets[bucketIndex][indexInBucket];
333
333
  }
@@ -342,7 +342,7 @@ export class Deque extends IterableElementBase {
342
342
  * position in the data structure.
343
343
  */
344
344
  setAt(pos, element) {
345
- rangeCheck(pos, 0, this.size - 1);
345
+ rangeCheck(pos, 0, this._size - 1);
346
346
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
347
347
  this._buckets[bucketIndex][indexInBucket] = element;
348
348
  return true;
@@ -363,19 +363,19 @@ export class Deque extends IterableElementBase {
363
363
  * @returns The size of the array after the insertion is being returned.
364
364
  */
365
365
  addAt(pos, element, num = 1) {
366
- const length = this.size;
366
+ const length = this._size;
367
367
  rangeCheck(pos, 0, length);
368
368
  if (pos === 0) {
369
369
  while (num--)
370
370
  this.unshift(element);
371
371
  }
372
- else if (pos === this.size) {
372
+ else if (pos === this._size) {
373
373
  while (num--)
374
374
  this.push(element);
375
375
  }
376
376
  else {
377
377
  const arr = [];
378
- for (let i = pos; i < this.size; ++i) {
378
+ for (let i = pos; i < this._size; ++i) {
379
379
  arr.push(this.at(i));
380
380
  }
381
381
  this.cut(pos - 1, true);
@@ -447,7 +447,7 @@ export class Deque extends IterableElementBase {
447
447
  const newDeque = new Deque([], { bucketSize: this._bucketSize });
448
448
  if (pos < 0)
449
449
  pos = 0;
450
- for (let i = pos; i < this.size; i++) {
450
+ for (let i = pos; i < this._size; i++) {
451
451
  newDeque.push(this.at(i));
452
452
  }
453
453
  return newDeque;
@@ -465,13 +465,13 @@ export class Deque extends IterableElementBase {
465
465
  * @returns The size of the data structure after the deletion operation is performed.
466
466
  */
467
467
  deleteAt(pos) {
468
- rangeCheck(pos, 0, this.size - 1);
468
+ rangeCheck(pos, 0, this._size - 1);
469
469
  if (pos === 0)
470
470
  this.shift();
471
- else if (pos === this.size - 1)
471
+ else if (pos === this._size - 1)
472
472
  this.pop();
473
473
  else {
474
- const length = this.size - 1;
474
+ const length = this._size - 1;
475
475
  let { bucketIndex: curBucket, indexInBucket: curPointer } = this._getBucketAndPosition(pos);
476
476
  for (let i = pos; i < length; ++i) {
477
477
  const { bucketIndex: nextBucket, indexInBucket: nextPointer } = this._getBucketAndPosition(pos + 1);
@@ -494,7 +494,7 @@ export class Deque extends IterableElementBase {
494
494
  * @returns The size of the data structure after the element has been deleted.
495
495
  */
496
496
  delete(element) {
497
- const size = this.size;
497
+ const size = this._size;
498
498
  if (size === 0)
499
499
  return false;
500
500
  let i = 0;
@@ -539,12 +539,12 @@ export class Deque extends IterableElementBase {
539
539
  * @returns The size of the modified array is being returned.
540
540
  */
541
541
  unique() {
542
- if (this.size <= 1) {
542
+ if (this._size <= 1) {
543
543
  return this;
544
544
  }
545
545
  let index = 1;
546
546
  let prev = this.at(0);
547
- for (let i = 1; i < this.size; ++i) {
547
+ for (let i = 1; i < this._size; ++i) {
548
548
  const cur = this.at(i);
549
549
  if (cur !== prev) {
550
550
  prev = cur;
@@ -566,11 +566,11 @@ export class Deque extends IterableElementBase {
566
566
  */
567
567
  sort(comparator) {
568
568
  const arr = [];
569
- for (let i = 0; i < this.size; ++i) {
569
+ for (let i = 0; i < this._size; ++i) {
570
570
  arr.push(this.at(i));
571
571
  }
572
572
  arr.sort(comparator);
573
- for (let i = 0; i < this.size; ++i) {
573
+ for (let i = 0; i < this._size; ++i) {
574
574
  this.setAt(i, arr[i]);
575
575
  }
576
576
  return this;
@@ -582,10 +582,10 @@ export class Deque extends IterableElementBase {
582
582
  * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
583
583
  * memory usage.
584
584
  * @returns Nothing is being returned. The function is using the `return` statement to exit early if
585
- * `this.size` is 0, but it does not return any value.
585
+ * `this._size` is 0, but it does not return any value.
586
586
  */
587
587
  shrinkToFit() {
588
- if (this.size === 0)
588
+ if (this._size === 0)
589
589
  return;
590
590
  const newBuckets = [];
591
591
  if (this._bucketFirst === this._bucketLast)
@@ -619,7 +619,7 @@ export class Deque extends IterableElementBase {
619
619
  * in the data structure. If the element is not found, it returns -1.
620
620
  */
621
621
  indexOf(element) {
622
- for (let i = 0; i < this.size; ++i) {
622
+ for (let i = 0; i < this._size; ++i) {
623
623
  if (this.at(i) === element) {
624
624
  return i;
625
625
  }
@@ -710,7 +710,7 @@ export class Deque extends IterableElementBase {
710
710
  * object to be iterated over using a for...of loop.
711
711
  */
712
712
  *_getIterator() {
713
- for (let i = 0; i < this.size; ++i) {
713
+ for (let i = 0; i < this._size; ++i) {
714
714
  yield this.at(i);
715
715
  }
716
716
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license MIT
3
- * @copyright Tyler Zeng <zrwusa@gmail.com>
3
+ * @copyright Pablo Zeng <zrwusa@gmail.com>
4
4
  * @class
5
5
  */
6
6
  import type { ElementCallback, QueueOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, StackOptions } from '../../types';
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * data-structure-typed
3
3
  *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
8
  import type { ElementCallback, TrieOptions } from '../../types';
@@ -177,7 +177,7 @@ export class Trie extends IterableElementBase {
177
177
  * @return True if the size of the queue is 0
178
178
  */
179
179
  isEmpty() {
180
- return this.size === 0;
180
+ return this._size === 0;
181
181
  }
182
182
  /**
183
183
  * Time Complexity: O(1)
@@ -2,3 +2,4 @@ export * from './data-structures';
2
2
  export * from './utils';
3
3
  export * from './interfaces';
4
4
  export * from './types';
5
+ export * from './constants';
package/dist/mjs/index.js CHANGED
@@ -2,3 +2,4 @@ export * from './data-structures';
2
2
  export * from './utils';
3
3
  export * from './interfaces';
4
4
  export * from './types';
5
+ export * from './constants';
@@ -1,9 +1,9 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKeyOrNodeOrEntry } from '../types';
2
+ import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNKeyOrNodeOrEntry, BTNPredicate } from '../types';
3
3
  export interface IBinaryTree<K = any, V = any, R = [K, V], NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
4
4
  createNode(key: K, value?: NODE['value']): NODE;
5
5
  createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
6
6
  add(keyOrNodeOrEntryOrRawElement: BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
7
7
  addMany(nodes: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
8
- delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<NODE>[];
8
+ delete(predicate: R | BTNKeyOrNodeOrEntry<K, V, NODE> | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
9
9
  }
@@ -1,5 +1,6 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
2
2
  import { IterationType, OptValue } from '../../common';
3
+ import { DFSOperation } from "bst-typed";
3
4
  export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
5
  export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
6
  export type BinaryTreeOptions<K, V, R> = {
@@ -23,10 +24,7 @@ export type BinaryTreeDeleteResult<NODE> = {
23
24
  needBalanced: OptBTNOrNull<NODE>;
24
25
  };
25
26
  export type BTNCallback<NODE, D = any> = (node: NODE) => D;
26
- export declare enum DFSOperation {
27
- VISIT = 0,
28
- PROCESS = 1
29
- }
27
+ export type BTNPredicate<NODE> = (node: NODE) => boolean;
30
28
  export type DFSStackItem<NODE> = {
31
29
  opt: DFSOperation;
32
30
  node: OptBTNOrNull<NODE>;
@@ -1,5 +1 @@
1
- export var DFSOperation;
2
- (function (DFSOperation) {
3
- DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
4
- DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
5
- })(DFSOperation || (DFSOperation = {}));
1
+ export {};