data-structure-typed 1.49.5 → 1.49.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 (222) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +17 -23
  3. package/README_zh-CN.md +2 -0
  4. package/benchmark/report.html +14 -23
  5. package/benchmark/report.json +158 -251
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js +194 -153
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
  13. package/dist/cjs/data-structures/binary-tree/bst.js +114 -91
  14. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +58 -51
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/hash-map.d.ts +24 -27
  22. package/dist/cjs/data-structures/hash/hash-map.js +35 -35
  23. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  24. package/dist/cjs/data-structures/hash/index.d.ts +0 -1
  25. package/dist/cjs/data-structures/hash/index.js +0 -1
  26. package/dist/cjs/data-structures/hash/index.js.map +1 -1
  27. package/dist/cjs/data-structures/heap/heap.d.ts +2 -1
  28. package/dist/cjs/data-structures/heap/heap.js +13 -13
  29. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  30. package/dist/cjs/data-structures/heap/max-heap.js +1 -1
  31. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/min-heap.js +1 -1
  33. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  34. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +1 -1
  35. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +1 -3
  37. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  39. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +15 -18
  40. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  41. package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -7
  42. package/dist/cjs/data-structures/matrix/matrix.js +0 -7
  43. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  44. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +1 -1
  45. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  46. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +1 -1
  47. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  48. package/dist/cjs/data-structures/priority-queue/priority-queue.js +1 -1
  49. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  50. package/dist/cjs/data-structures/queue/deque.d.ts +2 -11
  51. package/dist/cjs/data-structures/queue/deque.js +9 -13
  52. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  53. package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
  54. package/dist/cjs/data-structures/queue/queue.js +29 -25
  55. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  56. package/dist/cjs/data-structures/stack/stack.js +2 -3
  57. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  58. package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
  59. package/dist/cjs/data-structures/trie/trie.js +9 -5
  60. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  61. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  62. package/dist/cjs/types/common.d.ts +3 -3
  63. package/dist/cjs/types/common.js +2 -2
  64. package/dist/cjs/types/common.js.map +1 -1
  65. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  66. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  67. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  68. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +5 -2
  69. package/dist/cjs/types/data-structures/hash/index.d.ts +0 -1
  70. package/dist/cjs/types/data-structures/hash/index.js +0 -1
  71. package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
  72. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  73. package/dist/cjs/types/data-structures/linked-list/index.d.ts +1 -0
  74. package/dist/cjs/types/data-structures/linked-list/index.js +1 -0
  75. package/dist/cjs/types/data-structures/linked-list/index.js.map +1 -1
  76. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  77. package/dist/cjs/types/data-structures/matrix/index.d.ts +1 -0
  78. package/dist/cjs/types/data-structures/matrix/index.js +1 -0
  79. package/dist/cjs/types/data-structures/matrix/index.js.map +1 -1
  80. package/dist/cjs/types/data-structures/matrix/matrix.d.ts +7 -1
  81. package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -1
  82. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -1
  83. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  84. package/dist/mjs/data-structures/binary-tree/avl-tree.js +55 -49
  85. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
  86. package/dist/mjs/data-structures/binary-tree/binary-tree.js +194 -153
  87. package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
  88. package/dist/mjs/data-structures/binary-tree/bst.js +114 -91
  89. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  90. package/dist/mjs/data-structures/binary-tree/rb-tree.js +62 -59
  91. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
  92. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +58 -51
  93. package/dist/mjs/data-structures/hash/hash-map.d.ts +24 -27
  94. package/dist/mjs/data-structures/hash/hash-map.js +35 -37
  95. package/dist/mjs/data-structures/hash/index.d.ts +0 -1
  96. package/dist/mjs/data-structures/hash/index.js +0 -1
  97. package/dist/mjs/data-structures/heap/heap.d.ts +2 -1
  98. package/dist/mjs/data-structures/heap/heap.js +19 -20
  99. package/dist/mjs/data-structures/heap/max-heap.js +1 -1
  100. package/dist/mjs/data-structures/heap/min-heap.js +1 -1
  101. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +1 -1
  102. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -5
  103. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -8
  104. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +16 -23
  105. package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -7
  106. package/dist/mjs/data-structures/matrix/matrix.js +0 -7
  107. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +1 -1
  108. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +1 -1
  109. package/dist/mjs/data-structures/priority-queue/priority-queue.js +1 -1
  110. package/dist/mjs/data-structures/queue/deque.d.ts +2 -11
  111. package/dist/mjs/data-structures/queue/deque.js +9 -14
  112. package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
  113. package/dist/mjs/data-structures/queue/queue.js +30 -28
  114. package/dist/mjs/data-structures/stack/stack.js +3 -5
  115. package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
  116. package/dist/mjs/data-structures/trie/trie.js +10 -9
  117. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  118. package/dist/mjs/types/common.d.ts +3 -3
  119. package/dist/mjs/types/common.js +2 -2
  120. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
  121. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  122. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
  123. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +5 -2
  124. package/dist/mjs/types/data-structures/hash/index.d.ts +0 -1
  125. package/dist/mjs/types/data-structures/hash/index.js +0 -1
  126. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  127. package/dist/mjs/types/data-structures/linked-list/index.d.ts +1 -0
  128. package/dist/mjs/types/data-structures/linked-list/index.js +1 -0
  129. package/dist/mjs/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
  130. package/dist/mjs/types/data-structures/matrix/index.d.ts +1 -0
  131. package/dist/mjs/types/data-structures/matrix/index.js +1 -0
  132. package/dist/mjs/types/data-structures/matrix/matrix.d.ts +7 -1
  133. package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -1
  134. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -1
  135. package/dist/umd/data-structure-typed.js +620 -823
  136. package/dist/umd/data-structure-typed.min.js +2 -2
  137. package/dist/umd/data-structure-typed.min.js.map +1 -1
  138. package/package.json +1 -1
  139. package/src/data-structures/binary-tree/avl-tree.ts +58 -53
  140. package/src/data-structures/binary-tree/binary-tree.ts +255 -211
  141. package/src/data-structures/binary-tree/bst.ts +126 -107
  142. package/src/data-structures/binary-tree/rb-tree.ts +66 -64
  143. package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
  144. package/src/data-structures/hash/hash-map.ts +46 -50
  145. package/src/data-structures/hash/index.ts +0 -1
  146. package/src/data-structures/heap/heap.ts +20 -19
  147. package/src/data-structures/heap/max-heap.ts +1 -1
  148. package/src/data-structures/heap/min-heap.ts +1 -1
  149. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  150. package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
  151. package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
  152. package/src/data-structures/matrix/matrix.ts +2 -10
  153. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  154. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  155. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  156. package/src/data-structures/queue/deque.ts +11 -15
  157. package/src/data-structures/queue/queue.ts +29 -28
  158. package/src/data-structures/stack/stack.ts +3 -6
  159. package/src/data-structures/trie/trie.ts +10 -11
  160. package/src/interfaces/binary-tree.ts +3 -3
  161. package/src/types/common.ts +3 -3
  162. package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
  163. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  164. package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
  165. package/src/types/data-structures/hash/hash-map.ts +6 -2
  166. package/src/types/data-structures/hash/index.ts +0 -1
  167. package/src/types/data-structures/heap/heap.ts +1 -1
  168. package/src/types/data-structures/linked-list/index.ts +1 -0
  169. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
  170. package/src/types/data-structures/matrix/index.ts +1 -0
  171. package/src/types/data-structures/matrix/matrix.ts +7 -1
  172. package/src/types/data-structures/queue/deque.ts +1 -1
  173. package/src/types/data-structures/trie/trie.ts +1 -1
  174. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
  175. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
  176. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
  177. package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
  178. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -15
  179. package/test/performance/data-structures/comparison/comparison.test.ts +13 -36
  180. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
  181. package/test/performance/data-structures/hash/hash-map.test.ts +11 -34
  182. package/test/performance/data-structures/heap/heap.test.ts +5 -18
  183. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
  184. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
  185. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
  186. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
  187. package/test/performance/data-structures/queue/queue.test.ts +8 -25
  188. package/test/performance/data-structures/stack/stack.test.ts +6 -18
  189. package/test/performance/data-structures/trie/trie.test.ts +2 -6
  190. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -5
  191. package/test/unit/data-structures/binary-tree/bst.test.ts +17 -1
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  193. package/test/unit/data-structures/queue/deque.test.ts +5 -5
  194. package/test/unit/data-structures/trie/trie.test.ts +1 -1
  195. package/dist/cjs/data-structures/hash/hash-table.d.ts +0 -108
  196. package/dist/cjs/data-structures/hash/hash-table.js +0 -282
  197. package/dist/cjs/data-structures/hash/hash-table.js.map +0 -1
  198. package/dist/cjs/types/data-structures/hash/hash-table.d.ts +0 -1
  199. package/dist/cjs/types/data-structures/hash/hash-table.js +0 -3
  200. package/dist/cjs/types/data-structures/hash/hash-table.js.map +0 -1
  201. package/dist/cjs/types/data-structures/matrix/matrix2d.d.ts +0 -1
  202. package/dist/cjs/types/data-structures/matrix/matrix2d.js +0 -3
  203. package/dist/cjs/types/data-structures/matrix/matrix2d.js.map +0 -1
  204. package/dist/cjs/types/data-structures/matrix/vector2d.d.ts +0 -1
  205. package/dist/cjs/types/data-structures/matrix/vector2d.js +0 -3
  206. package/dist/cjs/types/data-structures/matrix/vector2d.js.map +0 -1
  207. package/dist/mjs/data-structures/hash/hash-table.d.ts +0 -108
  208. package/dist/mjs/data-structures/hash/hash-table.js +0 -283
  209. package/dist/mjs/types/data-structures/hash/hash-table.d.ts +0 -1
  210. package/dist/mjs/types/data-structures/hash/hash-table.js +0 -1
  211. package/dist/mjs/types/data-structures/matrix/matrix2d.d.ts +0 -1
  212. package/dist/mjs/types/data-structures/matrix/matrix2d.js +0 -1
  213. package/dist/mjs/types/data-structures/matrix/vector2d.d.ts +0 -1
  214. package/dist/mjs/types/data-structures/matrix/vector2d.js +0 -1
  215. package/src/data-structures/hash/hash-table.ts +0 -318
  216. package/src/types/data-structures/hash/hash-table.ts +0 -1
  217. package/src/types/data-structures/matrix/matrix2d.ts +0 -1
  218. package/src/types/data-structures/matrix/vector2d.ts +0 -1
  219. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  220. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  221. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  222. package/test/unit/data-structures/hash/hash-table.test.ts +0 -238
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./hash-map"), exports);
18
- __exportStar(require("./hash-table"), exports);
19
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/hash/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/hash/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B"}
@@ -1,4 +1,4 @@
1
1
  import { Comparator } from '../../common';
2
2
  export type HeapOptions<T> = {
3
- comparator: Comparator<T>;
3
+ comparator?: Comparator<T>;
4
4
  };
@@ -1,2 +1,3 @@
1
1
  export * from './singly-linked-list';
2
2
  export * from './doubly-linked-list';
3
+ export * from './skip-linked-list';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./singly-linked-list"), exports);
18
18
  __exportStar(require("./doubly-linked-list"), exports);
19
+ __exportStar(require("./skip-linked-list"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/linked-list/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,uDAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/linked-list/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,uDAAqC;AACrC,qDAAmC"}
@@ -1 +1,4 @@
1
- export {};
1
+ export type SkipLinkedListOptions = {
2
+ maxLevel?: number;
3
+ probability?: number;
4
+ };
@@ -1 +1,2 @@
1
1
  export * from './navigator';
2
+ export * from './matrix';
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./navigator"), exports);
18
+ __exportStar(require("./matrix"), exports);
18
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/matrix/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/matrix/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB"}
@@ -1 +1,7 @@
1
- export {};
1
+ export type MatrixOptions = {
2
+ rows?: number;
3
+ cols?: number;
4
+ addFn?: (a: number, b: number) => any;
5
+ subtractFn?: (a: number, b: number) => any;
6
+ multiplyFn?: (a: number, b: number) => any;
7
+ };
@@ -1 +1,3 @@
1
- export {};
1
+ export type DequeOptions = {
2
+ bucketSize?: number;
3
+ };
@@ -1 +1,3 @@
1
- export {};
1
+ export type TrieOptions = {
2
+ caseSensitive?: boolean;
3
+ };
@@ -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 keysOrNodesOrEntries and options.
27
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` 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(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: 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 keysOrNodesOrEntries and options.
28
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` 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(keysOrNodesOrEntries = [], options) {
36
36
  super([], options);
37
- if (elements)
38
- super.addMany(elements);
37
+ if (keysOrNodesOrEntries)
38
+ super.addMany(keysOrNodesOrEntries);
39
39
  }
40
40
  /**
41
41
  * The function creates a new AVL tree node with the specified key and value.
@@ -64,12 +64,12 @@ export class AVLTree extends BST {
64
64
  });
65
65
  }
66
66
  /**
67
- * The function checks if an exemplar is an instance of AVLTreeNode.
68
- * @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`.
69
- * @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.
70
70
  */
71
- isNode(exemplar) {
72
- return exemplar instanceof AVLTreeNode;
71
+ isNode(keyOrNodeOrEntry) {
72
+ return keyOrNodeOrEntry instanceof AVLTreeNode;
73
73
  }
74
74
  /**
75
75
  * The function "isNotNodeInstance" checks if a potential key is a K.
@@ -81,12 +81,13 @@ export class AVLTree extends BST {
81
81
  return !(potentialKey instanceof AVLTreeNode);
82
82
  }
83
83
  /**
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.
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.
86
87
  */
87
88
  /**
88
- * 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.
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 add method of a binary tree node and balances the tree after inserting
92
93
  * a new node.
@@ -98,19 +99,19 @@ export class AVLTree extends BST {
98
99
  */
99
100
  add(keyOrNodeOrEntry, value) {
100
101
  if (keyOrNodeOrEntry === null)
101
- return undefined;
102
+ return false;
102
103
  const inserted = super.add(keyOrNodeOrEntry, value);
103
104
  if (inserted)
104
- this._balancePath(inserted);
105
+ this._balancePath(keyOrNodeOrEntry);
105
106
  return inserted;
106
107
  }
107
108
  /**
108
- * 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.
109
- * 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)
110
111
  */
111
112
  /**
112
- * 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.
113
- * 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)
114
115
  *
115
116
  * The function overrides the delete method of a binary tree, performs the deletion, and then
116
117
  * balances the tree if necessary.
@@ -164,12 +165,13 @@ export class AVLTree extends BST {
164
165
  return undefined;
165
166
  }
166
167
  /**
167
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
168
- * 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.
169
171
  */
170
172
  /**
171
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
172
- * 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)
173
175
  *
174
176
  * The function calculates the balance factor of a node in a binary tree.
175
177
  * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
@@ -187,12 +189,13 @@ export class AVLTree extends BST {
187
189
  return node.right.height - node.left.height;
188
190
  }
189
191
  /**
190
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
191
- * 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.
192
195
  */
193
196
  /**
194
- * Time Complexity: O(1) - constant time, as it performs a fixed number of operations.
195
- * 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)
196
199
  *
197
200
  * The function updates the height of a node in a binary tree based on the heights of its left and
198
201
  * right children.
@@ -211,12 +214,13 @@ export class AVLTree extends BST {
211
214
  node.height = 1 + Math.max(node.right.height, node.left.height);
212
215
  }
213
216
  /**
214
- * 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.
215
- * 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.
216
220
  */
217
221
  /**
218
- * 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.
219
- * 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)
220
224
  *
221
225
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
222
226
  * to restore balance in an AVL tree after inserting a node.
@@ -224,6 +228,7 @@ export class AVLTree extends BST {
224
228
  * AVL tree that needs to be balanced.
225
229
  */
226
230
  _balancePath(node) {
231
+ node = this.ensureNode(node);
227
232
  const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
228
233
  for (let i = 0; i < path.length; i++) {
229
234
  // second O(log n)
@@ -263,12 +268,13 @@ export class AVLTree extends BST {
263
268
  }
264
269
  }
265
270
  /**
266
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
267
- * 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.
268
274
  */
269
275
  /**
270
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
271
- * 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)
272
278
  *
273
279
  * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
274
280
  * @param {N} A - A is a node in a binary tree.
@@ -304,12 +310,12 @@ export class AVLTree extends BST {
304
310
  this._updateHeight(B);
305
311
  }
306
312
  /**
307
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
308
- * 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)
309
315
  */
310
316
  /**
311
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
312
- * 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)
313
319
  *
314
320
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
315
321
  * @param {N} A - A is a node in a binary tree.
@@ -360,12 +366,12 @@ export class AVLTree extends BST {
360
366
  C && this._updateHeight(C);
361
367
  }
362
368
  /**
363
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
364
- * 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)
365
371
  */
366
372
  /**
367
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
368
- * 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)
369
375
  *
370
376
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
371
377
  * @param {N} A - A is a node in a binary tree.
@@ -402,12 +408,12 @@ export class AVLTree extends BST {
402
408
  B && this._updateHeight(B);
403
409
  }
404
410
  /**
405
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
406
- * 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)
407
413
  */
408
414
  /**
409
- * Time Complexity: O(1) - constant time, as these methods perform a fixed number of operations.
410
- * 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)
411
417
  *
412
418
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
413
419
  * @param {N} A - A is a node in a binary tree.