data-structure-typed 1.49.4 → 1.49.6

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 (186) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +15 -26
  3. package/README_zh-CN.md +1 -1
  4. package/benchmark/report.html +14 -23
  5. package/benchmark/report.json +163 -256
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +211 -198
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
  15. package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +59 -94
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  30. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  31. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.js +2 -3
  33. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  34. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  37. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  39. package/dist/cjs/data-structures/matrix/index.js +0 -2
  40. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  41. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  42. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  43. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  44. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  45. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  46. package/dist/cjs/data-structures/queue/deque.js +5 -7
  47. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  48. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  49. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  50. package/dist/cjs/types/common.d.ts +3 -3
  51. package/dist/cjs/types/common.js +2 -2
  52. package/dist/cjs/types/common.js.map +1 -1
  53. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  54. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  55. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  56. package/dist/cjs/utils/utils.d.ts +1 -0
  57. package/dist/cjs/utils/utils.js +6 -1
  58. package/dist/cjs/utils/utils.js.map +1 -1
  59. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  60. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  61. package/dist/mjs/data-structures/binary-tree/avl-tree.js +57 -50
  62. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  63. package/dist/mjs/data-structures/binary-tree/binary-tree.js +212 -199
  64. package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
  65. package/dist/mjs/data-structures/binary-tree/bst.js +115 -90
  66. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  67. package/dist/mjs/data-structures/binary-tree/rb-tree.js +64 -60
  68. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  69. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +61 -95
  70. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  71. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
  72. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  73. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  74. package/dist/mjs/data-structures/heap/heap.js +2 -3
  75. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  76. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  77. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  78. package/dist/mjs/data-structures/matrix/index.js +0 -2
  79. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  80. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  81. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  82. package/dist/mjs/data-structures/queue/deque.js +7 -9
  83. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  84. package/dist/mjs/data-structures/queue/queue.js +1 -1
  85. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  86. package/dist/mjs/types/common.d.ts +3 -3
  87. package/dist/mjs/types/common.js +2 -2
  88. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  89. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  90. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  91. package/dist/mjs/utils/utils.d.ts +1 -0
  92. package/dist/mjs/utils/utils.js +4 -0
  93. package/dist/umd/data-structure-typed.js +853 -943
  94. package/dist/umd/data-structure-typed.min.js +2 -2
  95. package/dist/umd/data-structure-typed.min.js.map +1 -1
  96. package/package.json +4 -3
  97. package/src/data-structures/base/index.ts +1 -1
  98. package/src/data-structures/base/iterable-base.ts +7 -10
  99. package/src/data-structures/binary-tree/avl-tree.ts +73 -61
  100. package/src/data-structures/binary-tree/binary-tree.ts +301 -270
  101. package/src/data-structures/binary-tree/bst.ts +139 -115
  102. package/src/data-structures/binary-tree/rb-tree.ts +81 -73
  103. package/src/data-structures/binary-tree/tree-multimap.ts +72 -103
  104. package/src/data-structures/graph/abstract-graph.ts +13 -11
  105. package/src/data-structures/graph/directed-graph.ts +1 -3
  106. package/src/data-structures/graph/map-graph.ts +6 -1
  107. package/src/data-structures/graph/undirected-graph.ts +3 -6
  108. package/src/data-structures/hash/hash-map.ts +18 -16
  109. package/src/data-structures/heap/heap.ts +7 -10
  110. package/src/data-structures/heap/max-heap.ts +2 -1
  111. package/src/data-structures/heap/min-heap.ts +2 -1
  112. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  113. package/src/data-structures/matrix/index.ts +0 -2
  114. package/src/data-structures/matrix/matrix.ts +442 -13
  115. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  116. package/src/data-structures/queue/deque.ts +18 -39
  117. package/src/data-structures/queue/queue.ts +1 -1
  118. package/src/interfaces/binary-tree.ts +9 -4
  119. package/src/types/common.ts +5 -5
  120. package/src/types/data-structures/base/base.ts +14 -3
  121. package/src/types/data-structures/base/index.ts +1 -1
  122. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  123. package/src/types/data-structures/hash/hash-map.ts +3 -3
  124. package/src/types/data-structures/heap/heap.ts +2 -2
  125. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  126. package/src/utils/utils.ts +7 -1
  127. package/test/integration/avl-tree.test.ts +18 -1
  128. package/test/integration/bst.test.ts +2 -2
  129. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
  130. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
  131. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
  132. package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
  133. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -16
  134. package/test/performance/data-structures/comparison/comparison.test.ts +19 -47
  135. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
  136. package/test/performance/data-structures/hash/hash-map.test.ts +14 -38
  137. package/test/performance/data-structures/heap/heap.test.ts +5 -18
  138. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -2
  139. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
  140. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
  141. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
  142. package/test/performance/data-structures/queue/deque.test.ts +6 -7
  143. package/test/performance/data-structures/queue/queue.test.ts +13 -29
  144. package/test/performance/data-structures/stack/stack.test.ts +6 -18
  145. package/test/performance/data-structures/trie/trie.test.ts +2 -6
  146. package/test/performance/reportor.ts +14 -15
  147. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  148. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -29
  149. package/test/unit/data-structures/binary-tree/bst.test.ts +69 -27
  150. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  151. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  152. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  153. package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
  154. package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
  155. package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
  156. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  157. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  158. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  159. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
  160. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  161. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  162. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  163. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  164. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  165. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  166. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  167. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  168. package/test/utils/performanc.ts +1 -1
  169. package/typedoc.json +30 -0
  170. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  171. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  172. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  173. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  174. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  175. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  176. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  177. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  178. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  179. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  180. package/src/data-structures/matrix/matrix2d.ts +0 -211
  181. package/src/data-structures/matrix/vector2d.ts +0 -315
  182. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  183. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  184. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  185. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  186. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -1,4 +1,4 @@
1
- import { IterableElementBase, IterableEntryBase } from "../../../data-structures";
1
+ import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
2
  export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
3
3
  export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
4
4
  export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
@@ -1,4 +1,4 @@
1
- import { Comparator } from "../../common";
1
+ import { Comparator } from '../../common';
2
2
  export type HeapOptions<T> = {
3
3
  comparator: Comparator<T>;
4
4
  };
@@ -1,2 +1,2 @@
1
- import { HeapOptions } from "../heap";
1
+ import { HeapOptions } from '../heap';
2
2
  export type PriorityQueueOptions<T> = HeapOptions<T> & {};
@@ -22,3 +22,4 @@ export declare const rangeCheck: (index: number, min: number, max: number, messa
22
22
  export declare const throwRangeError: (message?: string) => void;
23
23
  export declare const isWeakKey: (input: unknown) => input is object;
24
24
  export declare const calcMinUnitsRequired: (totalQuantity: number, unitSize: number) => number;
25
+ export declare const roundFixed: (num: number, digit?: number) => number;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
12
+ exports.roundFixed = exports.calcMinUnitsRequired = exports.isWeakKey = exports.throwRangeError = exports.rangeCheck = exports.getMSB = exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
13
13
  const uuidV4 = function () {
14
14
  return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
15
15
  const r = (Math.random() * 16) | 0, v = c == 'x' ? r : (r & 0x3) | 0x8;
@@ -87,4 +87,9 @@ const isWeakKey = (input) => {
87
87
  exports.isWeakKey = isWeakKey;
88
88
  const calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
89
89
  exports.calcMinUnitsRequired = calcMinUnitsRequired;
90
+ const roundFixed = (num, digit = 10) => {
91
+ const multiplier = Math.pow(10, digit);
92
+ return Math.round(num * multiplier) / multiplier;
93
+ };
94
+ exports.roundFixed = roundFixed;
90
95
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AASO,MAAM,MAAM,GAAG;IACpB,OAAO,sCAAsC,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC;QACvE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAChC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;QACrC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,MAAM,UAMjB;AAEK,MAAM,WAAW,GAAG,UAAa,KAAU,EAAE,SAA0D;IAC5G,IAAI,CAAC,GAAG,CAAC,CAAC,EACR,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,OAAO,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,SAAS,CAAC,KAAK,EAAE,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CAAC,CAAC;AAChE,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAEK,MAAM,eAAe,GAAG,CAAC,OAAO,GAAG,0BAA0B,EAAQ,EAAE;IAC5E,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAEK,MAAM,SAAS,GAAG,CAAC,KAAc,EAAmB,EAAE;IAC3D,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC;IAC/B,OAAO,CAAC,SAAS,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,SAAS,KAAK,UAAU,CAAC;AAChF,CAAC,CAAC;AAHW,QAAA,SAAS,aAGpB;AAEK,MAAM,oBAAoB,GAAG,CAAC,aAAqB,EAAE,QAAgB,EAAE,EAAE,CAC9E,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC;AAD3C,QAAA,oBAAoB,wBACuB;AAEjD,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,QAAgB,EAAE,EAAE,EAAE;IAC5D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;AACnD,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB"}
@@ -1,4 +1,4 @@
1
- import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from "../../types";
1
+ import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';
2
2
  export declare abstract class IterableEntryBase<K = any, V = any> {
3
3
  /**
4
4
  * Time Complexity: O(n)
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, BTNExemplar, BTNKeyOrNode } from '../../types';
9
+ import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
12
12
  height: number;
@@ -23,15 +23,15 @@ export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N
23
23
  */
24
24
  export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
25
25
  /**
26
- * The constructor function initializes an AVLTree object with optional elements and options.
27
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
28
- * objects. It represents a collection of elements that will be added to the AVL tree during
26
+ * The constructor function initializes an AVLTree object with optional nodes and options.
27
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
28
+ * objects. It represents a collection of nodes that will be added to the AVL tree during
29
29
  * initialization.
30
30
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
31
31
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
32
32
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
33
33
  */
34
- constructor(elements?: Iterable<BTNExemplar<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
34
+ constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
35
35
  /**
36
36
  * The function creates a new AVL tree node with the specified key and value.
37
37
  * @param {K} key - The key parameter is the key value that will be associated with
@@ -51,25 +51,26 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
51
51
  */
52
52
  createTree(options?: AVLTreeOptions<K>): TREE;
53
53
  /**
54
- * The function checks if an exemplar is an instance of AVLTreeNode.
55
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
56
- * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
54
+ * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
55
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
56
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
57
57
  */
58
- isNode(exemplar: BTNExemplar<K, V, N>): exemplar is N;
58
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
59
59
  /**
60
60
  * The function "isNotNodeInstance" checks if a potential key is a K.
61
61
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
62
62
  * data type.
63
63
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
64
64
  */
65
- isNotNodeInstance(potentialKey: BTNKeyOrNode<K, N>): potentialKey is K;
65
+ isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
66
66
  /**
67
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
68
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
67
+ * Time Complexity: O(log n)
68
+ * Space Complexity: O(1)
69
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
69
70
  */
70
71
  /**
71
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
72
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
72
+ * Time Complexity: O(log n)
73
+ * Space Complexity: O(1)
73
74
  *
74
75
  * The function overrides the add method of a binary tree node and balances the tree after inserting
75
76
  * a new node.
@@ -79,14 +80,14 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
79
80
  * being added to the binary tree.
80
81
  * @returns The method is returning either the inserted node or undefined.
81
82
  */
82
- add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V): N | undefined;
83
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
83
84
  /**
84
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
85
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
85
+ * Time Complexity: O(log n)
86
+ * Space Complexity: O(1)
86
87
  */
87
88
  /**
88
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
89
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
89
+ * Time Complexity: O(log n)
90
+ * Space Complexity: O(1)
90
91
  *
91
92
  * The function overrides the delete method of a binary tree, performs the deletion, and then
92
93
  * balances the tree if necessary.
@@ -112,12 +113,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
112
113
  */
113
114
  protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
114
115
  /**
115
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
116
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
116
+ * Time Complexity: O(1)
117
+ * Space Complexity: O(1)
118
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
117
119
  */
118
120
  /**
119
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
120
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
121
+ * Time Complexity: O(1)
122
+ * Space Complexity: O(1)
121
123
  *
122
124
  * The function calculates the balance factor of a node in a binary tree.
123
125
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -126,12 +128,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
126
128
  */
127
129
  protected _balanceFactor(node: N): number;
128
130
  /**
129
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
130
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
131
+ * Time Complexity: O(1)
132
+ * Space Complexity: O(1)
133
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
131
134
  */
132
135
  /**
133
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
134
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
136
+ * Time Complexity: O(1)
137
+ * Space Complexity: O(1)
135
138
  *
136
139
  * The function updates the height of a node in a binary tree based on the heights of its left and
137
140
  * right children.
@@ -139,62 +142,64 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
139
142
  */
140
143
  protected _updateHeight(node: N): void;
141
144
  /**
142
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
143
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
145
+ * Time Complexity: O(log n)
146
+ * Space Complexity: O(1)
147
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
144
148
  */
145
149
  /**
146
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
147
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
150
+ * Time Complexity: O(log n)
151
+ * Space Complexity: O(1)
148
152
  *
149
153
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
150
154
  * to restore balance in an AVL tree after inserting a node.
151
155
  * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
152
156
  * AVL tree that needs to be balanced.
153
157
  */
154
- protected _balancePath(node: N): void;
158
+ protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void;
155
159
  /**
156
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
157
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
160
+ * Time Complexity: O(1)
161
+ * Space Complexity: O(1)
162
+ * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
158
163
  */
159
164
  /**
160
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
161
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
165
+ * Time Complexity: O(1)
166
+ * Space Complexity: O(1)
162
167
  *
163
168
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
164
169
  * @param {N} A - A is a node in a binary tree.
165
170
  */
166
171
  protected _balanceLL(A: N): void;
167
172
  /**
168
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
169
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
173
+ * Time Complexity: O(1)
174
+ * Space Complexity: O(1)
170
175
  */
171
176
  /**
172
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
173
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
177
+ * Time Complexity: O(1)
178
+ * Space Complexity: O(1)
174
179
  *
175
180
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
176
181
  * @param {N} A - A is a node in a binary tree.
177
182
  */
178
183
  protected _balanceLR(A: N): void;
179
184
  /**
180
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
181
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
185
+ * Time Complexity: O(1)
186
+ * Space Complexity: O(1)
182
187
  */
183
188
  /**
184
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
185
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
189
+ * Time Complexity: O(1)
190
+ * Space Complexity: O(1)
186
191
  *
187
192
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
188
193
  * @param {N} A - A is a node in a binary tree.
189
194
  */
190
195
  protected _balanceRR(A: N): void;
191
196
  /**
192
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
193
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
197
+ * Time Complexity: O(1)
198
+ * Space Complexity: O(1)
194
199
  */
195
200
  /**
196
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
197
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
201
+ * Time Complexity: O(1)
202
+ * Space Complexity: O(1)
198
203
  *
199
204
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
200
205
  * @param {N} A - A is a node in a binary tree.
@@ -24,18 +24,18 @@ export class AVLTreeNode extends BSTNode {
24
24
  */
25
25
  export class AVLTree extends BST {
26
26
  /**
27
- * The constructor function initializes an AVLTree object with optional elements and options.
28
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNExemplar<K, V, N>`
29
- * objects. It represents a collection of elements that will be added to the AVL tree during
27
+ * The constructor function initializes an AVLTree object with optional nodes and options.
28
+ * @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
29
+ * objects. It represents a collection of nodes that will be added to the AVL tree during
30
30
  * initialization.
31
31
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
32
32
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
33
33
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
34
34
  */
35
- constructor(elements, options) {
35
+ constructor(nodes, options) {
36
36
  super([], options);
37
- if (elements)
38
- super.addMany(elements);
37
+ if (nodes)
38
+ super.addMany(nodes);
39
39
  }
40
40
  /**
41
41
  * The function creates a new AVL tree node with the specified key and value.
@@ -59,16 +59,17 @@ export class AVLTree extends BST {
59
59
  createTree(options) {
60
60
  return new AVLTree([], {
61
61
  iterationType: this.iterationType,
62
- variant: this.variant, ...options
62
+ variant: this.variant,
63
+ ...options
63
64
  });
64
65
  }
65
66
  /**
66
- * The function checks if an exemplar is an instance of AVLTreeNode.
67
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
68
- * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
67
+ * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
68
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
69
+ * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
69
70
  */
70
- isNode(exemplar) {
71
- return exemplar instanceof AVLTreeNode;
71
+ isNode(keyOrNodeOrEntry) {
72
+ return keyOrNodeOrEntry instanceof AVLTreeNode;
72
73
  }
73
74
  /**
74
75
  * The function "isNotNodeInstance" checks if a potential key is a K.
@@ -80,12 +81,13 @@ export class AVLTree extends BST {
80
81
  return !(potentialKey instanceof AVLTreeNode);
81
82
  }
82
83
  /**
83
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
84
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
84
+ * Time Complexity: O(log n)
85
+ * Space Complexity: O(1)
86
+ * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
85
87
  */
86
88
  /**
87
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
88
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
89
+ * Time Complexity: O(log n)
90
+ * Space Complexity: O(1)
89
91
  *
90
92
  * The function overrides the add method of a binary tree node and balances the tree after inserting
91
93
  * a new node.
@@ -97,19 +99,19 @@ export class AVLTree extends BST {
97
99
  */
98
100
  add(keyOrNodeOrEntry, value) {
99
101
  if (keyOrNodeOrEntry === null)
100
- return undefined;
102
+ return false;
101
103
  const inserted = super.add(keyOrNodeOrEntry, value);
102
104
  if (inserted)
103
- this._balancePath(inserted);
105
+ this._balancePath(keyOrNodeOrEntry);
104
106
  return inserted;
105
107
  }
106
108
  /**
107
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
108
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
109
+ * Time Complexity: O(log n)
110
+ * Space Complexity: O(1)
109
111
  */
110
112
  /**
111
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The delete method of the superclass (BST) has logarithmic time complexity.
112
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
113
+ * Time Complexity: O(log n)
114
+ * Space Complexity: O(1)
113
115
  *
114
116
  * The function overrides the delete method of a binary tree, performs the deletion, and then
115
117
  * balances the tree if necessary.
@@ -163,12 +165,13 @@ export class AVLTree extends BST {
163
165
  return undefined;
164
166
  }
165
167
  /**
166
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
167
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
168
+ * Time Complexity: O(1)
169
+ * Space Complexity: O(1)
170
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
168
171
  */
169
172
  /**
170
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
171
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
173
+ * Time Complexity: O(1)
174
+ * Space Complexity: O(1)
172
175
  *
173
176
  * The function calculates the balance factor of a node in a binary tree.
174
177
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -186,12 +189,13 @@ export class AVLTree extends BST {
186
189
  return node.right.height - node.left.height;
187
190
  }
188
191
  /**
189
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
190
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
192
+ * Time Complexity: O(1)
193
+ * Space Complexity: O(1)
194
+ * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
191
195
  */
192
196
  /**
193
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
194
- * Space Complexity: O(1) - constant space, as it only uses a constant amount of memory.
197
+ * Time Complexity: O(1)
198
+ * Space Complexity: O(1)
195
199
  *
196
200
  * The function updates the height of a node in a binary tree based on the heights of its left and
197
201
  * right children.
@@ -210,12 +214,13 @@ export class AVLTree extends BST {
210
214
  node.height = 1 + Math.max(node.right.height, node.left.height);
211
215
  }
212
216
  /**
213
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
214
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
217
+ * Time Complexity: O(log n)
218
+ * Space Complexity: O(1)
219
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
215
220
  */
216
221
  /**
217
- * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root.
218
- * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
222
+ * Time Complexity: O(log n)
223
+ * Space Complexity: O(1)
219
224
  *
220
225
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
221
226
  * to restore balance in an AVL tree after inserting a node.
@@ -223,6 +228,7 @@ export class AVLTree extends BST {
223
228
  * AVL tree that needs to be balanced.
224
229
  */
225
230
  _balancePath(node) {
231
+ node = this.ensureNode(node);
226
232
  const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
227
233
  for (let i = 0; i < path.length; i++) {
228
234
  // second O(log n)
@@ -262,12 +268,13 @@ export class AVLTree extends BST {
262
268
  }
263
269
  }
264
270
  /**
265
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
266
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
271
+ * Time Complexity: O(1)
272
+ * Space Complexity: O(1)
273
+ * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
267
274
  */
268
275
  /**
269
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
270
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
276
+ * Time Complexity: O(1)
277
+ * Space Complexity: O(1)
271
278
  *
272
279
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
273
280
  * @param {N} A - A is a node in a binary tree.
@@ -303,12 +310,12 @@ export class AVLTree extends BST {
303
310
  this._updateHeight(B);
304
311
  }
305
312
  /**
306
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
307
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
313
+ * Time Complexity: O(1)
314
+ * Space Complexity: O(1)
308
315
  */
309
316
  /**
310
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
311
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
317
+ * Time Complexity: O(1)
318
+ * Space Complexity: O(1)
312
319
  *
313
320
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
314
321
  * @param {N} A - A is a node in a binary tree.
@@ -359,12 +366,12 @@ export class AVLTree extends BST {
359
366
  C && this._updateHeight(C);
360
367
  }
361
368
  /**
362
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
363
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
369
+ * Time Complexity: O(1)
370
+ * Space Complexity: O(1)
364
371
  */
365
372
  /**
366
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
367
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
373
+ * Time Complexity: O(1)
374
+ * Space Complexity: O(1)
368
375
  *
369
376
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
370
377
  * @param {N} A - A is a node in a binary tree.
@@ -401,12 +408,12 @@ export class AVLTree extends BST {
401
408
  B && this._updateHeight(B);
402
409
  }
403
410
  /**
404
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
405
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
411
+ * Time Complexity: O(1)
412
+ * Space Complexity: O(1)
406
413
  */
407
414
  /**
408
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
409
- * Space Complexity: O(1) - constant space, as they only use a constant amount of memory.
415
+ * Time Complexity: O(1)
416
+ * Space Complexity: O(1)
410
417
  *
411
418
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
412
419
  * @param {N} A - A is a node in a binary tree.