data-structure-typed 1.35.0 → 1.40.0-rc

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 (173) hide show
  1. package/.github/workflows/ci.yml +3 -0
  2. package/CHANGELOG.md +3 -1
  3. package/CONTRIBUTING.md +18 -0
  4. package/dist/data-structures/binary-tree/aa-tree.d.ts +2 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +527 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +323 -0
  7. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/avl-tree.d.ts +94 -0
  9. package/dist/data-structures/binary-tree/avl-tree.js +90 -3
  10. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/data-structures/binary-tree/b-tree.d.ts +2 -0
  12. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +46 -0
  13. package/dist/data-structures/binary-tree/binary-indexed-tree.js +36 -0
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  15. package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -0
  16. package/dist/data-structures/binary-tree/binary-tree.js +21 -0
  17. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  18. package/dist/data-structures/binary-tree/bst.d.ts +133 -0
  19. package/dist/data-structures/binary-tree/bst.js +114 -0
  20. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  21. package/dist/data-structures/binary-tree/index.d.ts +12 -0
  22. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  23. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  24. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  25. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
  26. package/dist/data-structures/binary-tree/splay-tree.d.ts +2 -0
  27. package/dist/data-structures/binary-tree/tree-multiset.d.ts +209 -0
  28. package/dist/data-structures/binary-tree/tree-multiset.js +178 -0
  29. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  30. package/dist/data-structures/binary-tree/two-three-tree.d.ts +2 -0
  31. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  32. package/dist/data-structures/graph/abstract-graph.js +269 -4
  33. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  34. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  35. package/dist/data-structures/graph/directed-graph.js +167 -0
  36. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  37. package/dist/data-structures/graph/index.d.ts +4 -0
  38. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  39. package/dist/data-structures/graph/map-graph.js +54 -0
  40. package/dist/data-structures/graph/map-graph.js.map +1 -1
  41. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  42. package/dist/data-structures/graph/undirected-graph.js +105 -0
  43. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  44. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  45. package/dist/data-structures/hash/coordinate-map.js +35 -0
  46. package/dist/data-structures/hash/coordinate-map.js.map +1 -1
  47. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  48. package/dist/data-structures/hash/coordinate-set.js +28 -0
  49. package/dist/data-structures/hash/coordinate-set.js.map +1 -1
  50. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  51. package/dist/data-structures/hash/hash-map.js +29 -1
  52. package/dist/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  54. package/dist/data-structures/hash/hash-table.js +88 -6
  55. package/dist/data-structures/hash/hash-table.js.map +1 -1
  56. package/dist/data-structures/hash/index.d.ts +7 -0
  57. package/dist/data-structures/hash/pair.d.ts +2 -0
  58. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  59. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  60. package/dist/data-structures/heap/heap.d.ts +83 -0
  61. package/dist/data-structures/heap/heap.js +62 -0
  62. package/dist/data-structures/heap/heap.js.map +1 -1
  63. package/dist/data-structures/heap/index.d.ts +3 -0
  64. package/dist/data-structures/heap/max-heap.d.ts +23 -0
  65. package/dist/data-structures/heap/max-heap.js +16 -0
  66. package/dist/data-structures/heap/max-heap.js.map +1 -1
  67. package/dist/data-structures/heap/min-heap.d.ts +24 -0
  68. package/dist/data-structures/heap/min-heap.js +17 -0
  69. package/dist/data-structures/heap/min-heap.js.map +1 -1
  70. package/dist/data-structures/index.d.ts +11 -0
  71. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  72. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -0
  73. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  74. package/dist/data-structures/linked-list/index.d.ts +3 -0
  75. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  76. package/dist/data-structures/linked-list/singly-linked-list.js +135 -0
  77. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
  78. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  79. package/dist/data-structures/linked-list/skip-linked-list.js +36 -0
  80. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  81. package/dist/data-structures/matrix/index.d.ts +4 -0
  82. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  83. package/dist/data-structures/matrix/matrix.js +15 -0
  84. package/dist/data-structures/matrix/matrix.js.map +1 -1
  85. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  86. package/dist/data-structures/matrix/matrix2d.js +91 -2
  87. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  88. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  89. package/dist/data-structures/matrix/navigator.js +28 -0
  90. package/dist/data-structures/matrix/navigator.js.map +1 -1
  91. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  92. package/dist/data-structures/matrix/vector2d.js +188 -1
  93. package/dist/data-structures/matrix/vector2d.js.map +1 -1
  94. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  95. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  96. package/dist/data-structures/priority-queue/max-priority-queue.js +18 -0
  97. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  98. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  99. package/dist/data-structures/priority-queue/min-priority-queue.js +19 -0
  100. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  101. package/dist/data-structures/priority-queue/priority-queue.d.ts +180 -0
  102. package/dist/data-structures/priority-queue/priority-queue.js +141 -0
  103. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  104. package/dist/data-structures/queue/deque.d.ts +165 -0
  105. package/dist/data-structures/queue/deque.js +124 -0
  106. package/dist/data-structures/queue/deque.js.map +1 -1
  107. package/dist/data-structures/queue/index.d.ts +2 -0
  108. package/dist/data-structures/queue/queue.d.ts +107 -0
  109. package/dist/data-structures/queue/queue.js +80 -0
  110. package/dist/data-structures/queue/queue.js.map +1 -1
  111. package/dist/data-structures/stack/index.d.ts +1 -0
  112. package/dist/data-structures/stack/stack.d.ts +63 -0
  113. package/dist/data-structures/stack/stack.js +50 -0
  114. package/dist/data-structures/stack/stack.js.map +1 -1
  115. package/dist/data-structures/tree/index.d.ts +1 -0
  116. package/dist/data-structures/tree/tree.d.ts +14 -0
  117. package/dist/data-structures/tree/tree.js +1 -0
  118. package/dist/data-structures/tree/tree.js.map +1 -1
  119. package/dist/data-structures/trie/index.d.ts +1 -0
  120. package/dist/data-structures/trie/trie.d.ts +61 -0
  121. package/dist/data-structures/trie/trie.js +36 -0
  122. package/dist/data-structures/trie/trie.js.map +1 -1
  123. package/dist/index.d.ts +4 -0
  124. package/dist/interfaces/abstract-binary-tree.d.ts +7 -0
  125. package/dist/interfaces/abstract-graph.d.ts +5 -0
  126. package/dist/interfaces/avl-tree.d.ts +7 -0
  127. package/dist/interfaces/binary-tree.d.ts +6 -0
  128. package/dist/interfaces/bst.d.ts +6 -0
  129. package/dist/interfaces/directed-graph.d.ts +3 -0
  130. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  131. package/dist/interfaces/heap.d.ts +1 -0
  132. package/dist/interfaces/index.d.ts +15 -0
  133. package/dist/interfaces/navigator.d.ts +1 -0
  134. package/dist/interfaces/priority-queue.d.ts +1 -0
  135. package/dist/interfaces/rb-tree.d.ts +6 -0
  136. package/dist/interfaces/segment-tree.d.ts +1 -0
  137. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  138. package/dist/interfaces/tree-multiset.d.ts +6 -0
  139. package/dist/interfaces/undirected-graph.d.ts +3 -0
  140. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  141. package/dist/types/data-structures/abstract-binary-tree.js +6 -0
  142. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
  143. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  144. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  145. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  146. package/dist/types/data-structures/bst.d.ts +13 -0
  147. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  148. package/dist/types/data-structures/doubly-linked-list.d.ts +1 -0
  149. package/dist/types/data-structures/hash.d.ts +1 -0
  150. package/dist/types/data-structures/heap.d.ts +3 -0
  151. package/dist/types/data-structures/index.d.ts +16 -0
  152. package/dist/types/data-structures/map-graph.d.ts +1 -0
  153. package/dist/types/data-structures/navigator.d.ts +14 -0
  154. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  155. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  156. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  157. package/dist/types/data-structures/singly-linked-list.d.ts +1 -0
  158. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  159. package/dist/types/helpers.d.ts +1 -0
  160. package/dist/types/index.d.ts +3 -0
  161. package/dist/types/utils/index.d.ts +2 -0
  162. package/dist/types/utils/utils.d.ts +7 -0
  163. package/dist/types/utils/validate-type.d.ts +19 -0
  164. package/dist/utils/index.d.ts +1 -0
  165. package/dist/utils/utils.d.ts +19 -0
  166. package/package.json +11 -7
  167. package/test/integration/avl-tree.test.ts +4 -4
  168. package/test/integration/bst.test.ts +8 -8
  169. package/test/unit/data-structures/graph/directed-graph.test.ts +5 -5
  170. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  171. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +1 -1
  172. package/test/unit/data-structures/graph/index.ts +0 -2
  173. package/test/unit/data-structures/linked-list/index.ts +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"binary-tree.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/binary-tree.ts"],"names":[],"mappings":";;;AASA,iEAAkF;AAGlF,MAAa,cACX,SAAQ,6CAAmC;IAG3C,YAAY,GAAsB,EAAE,GAAO;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAPD,wCAOC;AAED,MAAa,UACX,SAAQ,yCAAqB;IAS7B,YAAY,OAA2B;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAUD,UAAU,CAAC,GAAsB,EAAE,GAAc;QAC/C,OAAO,IAAI,cAAc,CAAc,GAAG,EAAE,GAAG,CAAM,CAAC;IACxD,CAAC;CACF;AAzBD,gCAyBC"}
1
+ {"version":3,"file":"binary-tree.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/binary-tree.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,iEAAkF;AAGlF,MAAa,cACX,SAAQ,6CAAmC;IAG3C,YAAY,GAAsB,EAAE,GAAO;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAPD,wCAOC;AAED,MAAa,UACX,SAAQ,yCAAqB;IAG7B;;;;;OAKG;IACH,YAAY,OAA2B;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,GAAsB,EAAE,GAAc;QAC/C,OAAO,IAAI,cAAc,CAAc,GAAG,EAAE,GAAG,CAAM,CAAC;IACxD,CAAC;CACF;AAzBD,gCAyBC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { BinaryTreeNodeKey, BinaryTreeNodePropertyName, BSTComparator, BSTNodeNested, BSTOptions } from '../../types';
9
+ import { CP } from '../../types';
10
+ import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
+ import { IBST, IBSTNode } from '../../interfaces';
12
+ export declare class BSTNode<V = any, NEIGHBOR extends BSTNode<V, NEIGHBOR> = BSTNodeNested<V>> extends BinaryTreeNode<V, NEIGHBOR> implements IBSTNode<V, NEIGHBOR> {
13
+ constructor(key: BinaryTreeNodeKey, val?: V);
14
+ }
15
+ export declare class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N> implements IBST<N> {
16
+ /**
17
+ * The constructor function initializes a binary search tree object with an optional comparator function.
18
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
19
+ */
20
+ constructor(options?: BSTOptions);
21
+ /**
22
+ * The function creates a new binary search tree node with the given key and value.
23
+ * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
24
+ * identify each node in the binary tree.
25
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
26
+ * that will be stored in the node.
27
+ * @returns a new instance of the BSTNode class with the specified key and value.
28
+ */
29
+ createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
30
+ /**
31
+ * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
32
+ * node with the same ID.
33
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
34
+ * (which represents a binary tree node) or `null`.
35
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
36
+ * being added to the binary search tree.
37
+ * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
38
+ */
39
+ add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
40
+ /**
41
+ * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
42
+ * manner.
43
+ * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
44
+ * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
45
+ * to the binary search tree.
46
+ * @param {N['val'][]} data - The values of tree nodes
47
+ * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
48
+ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
49
+ */
50
+ addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd?: boolean): (N | null | undefined)[];
51
+ /**
52
+ * The function returns the first node in a binary tree that matches the given property name and value.
53
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
54
+ * generic type `N`. It represents the property of the binary tree node that you want to search for.
55
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
56
+ * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
57
+ * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
58
+ */
59
+ get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
60
+ /**
61
+ * The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
62
+ * leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
63
+ * @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
64
+ * the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
65
+ * equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
66
+ */
67
+ lastKey(): BinaryTreeNodeKey;
68
+ /**
69
+ * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
70
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
71
+ * `N` type. It represents the property of the binary tree node that you want to compare with.
72
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
73
+ * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
74
+ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
75
+ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
76
+ * is set to `true`, the function will return an array with only one node (if
77
+ * @returns an array of nodes (type N).
78
+ */
79
+ getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
80
+ /**
81
+ * The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
82
+ * less than a given node.
83
+ * @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
84
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
85
+ * specifies the property name to use for calculating the sum. If not provided, it defaults to `'key'`.
86
+ * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
87
+ * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
88
+ */
89
+ lesserSum(beginNode: N | BinaryTreeNodeKey | null, propertyName?: BinaryTreeNodePropertyName): number;
90
+ /**
91
+ * The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
92
+ * have a greater value than a given node.
93
+ * @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type),
94
+ * `BinaryTreeNodeKey`, or `null`. It represents the node in the binary tree to which the delta value will be added.
95
+ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
96
+ * each greater node should be increased.
97
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
98
+ * specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
99
+ * 'key'.
100
+ * @returns a boolean value.
101
+ */
102
+ allGreaterNodesAdd(node: N | BinaryTreeNodeKey | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
103
+ /**
104
+ * Balancing Adjustment:
105
+ * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
106
+ * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
107
+ *
108
+ * Use Cases and Efficiency:
109
+ * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
110
+ * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
111
+ */
112
+ /**
113
+ * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
114
+ * constructs a balanced binary search tree using either a recursive or iterative approach.
115
+ * @returns The function `perfectlyBalance()` returns a boolean value.
116
+ */
117
+ perfectlyBalance(): boolean;
118
+ /**
119
+ * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
120
+ * @returns a boolean value.
121
+ */
122
+ isAVLBalanced(): boolean;
123
+ protected _comparator: BSTComparator;
124
+ /**
125
+ * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
126
+ * greater than, less than, or equal to the second ID.
127
+ * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
128
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
129
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
130
+ * than), or CP.eq (equal).
131
+ */
132
+ protected _compare(a: BinaryTreeNodeKey, b: BinaryTreeNodeKey): CP;
133
+ }
@@ -10,6 +10,10 @@ class BSTNode extends binary_tree_1.BinaryTreeNode {
10
10
  }
11
11
  exports.BSTNode = BSTNode;
12
12
  class BST extends binary_tree_1.BinaryTree {
13
+ /**
14
+ * The constructor function initializes a binary search tree object with an optional comparator function.
15
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
16
+ */
13
17
  constructor(options) {
14
18
  super(options);
15
19
  this._comparator = (a, b) => a - b;
@@ -20,10 +24,28 @@ class BST extends binary_tree_1.BinaryTree {
20
24
  }
21
25
  }
22
26
  }
27
+ /**
28
+ * The function creates a new binary search tree node with the given key and value.
29
+ * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
30
+ * identify each node in the binary tree.
31
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
32
+ * that will be stored in the node.
33
+ * @returns a new instance of the BSTNode class with the specified key and value.
34
+ */
23
35
  createNode(key, val) {
24
36
  return new BSTNode(key, val);
25
37
  }
38
+ /**
39
+ * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
40
+ * node with the same ID.
41
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
42
+ * (which represents a binary tree node) or `null`.
43
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
44
+ * being added to the binary search tree.
45
+ * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
46
+ */
26
47
  add(keyOrNode, val) {
48
+ // TODO support node as a param
27
49
  let inserted = null;
28
50
  let newNode = null;
29
51
  if (keyOrNode instanceof BSTNode) {
@@ -49,35 +71,42 @@ class BST extends binary_tree_1.BinaryTree {
49
71
  if (newNode) {
50
72
  cur.val = newNode.val;
51
73
  }
74
+ //Duplicates are not accepted.
52
75
  traversing = false;
53
76
  inserted = cur;
54
77
  }
55
78
  else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
79
+ // Traverse left of the node
56
80
  if (cur.left === undefined) {
57
81
  if (newNode) {
58
82
  newNode.parent = cur;
59
83
  }
84
+ //Add to the left of the current node
60
85
  cur.left = newNode;
61
86
  this._setSize(this.size + 1);
62
87
  traversing = false;
63
88
  inserted = cur.left;
64
89
  }
65
90
  else {
91
+ //Traverse the left of the current node
66
92
  if (cur.left)
67
93
  cur = cur.left;
68
94
  }
69
95
  }
70
96
  else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
97
+ // Traverse right of the node
71
98
  if (cur.right === undefined) {
72
99
  if (newNode) {
73
100
  newNode.parent = cur;
74
101
  }
102
+ //Add to the right of the current node
75
103
  cur.right = newNode;
76
104
  this._setSize(this.size + 1);
77
105
  traversing = false;
78
106
  inserted = cur.right;
79
107
  }
80
108
  else {
109
+ //Traverse the left of the current node
81
110
  if (cur.right)
82
111
  cur = cur.right;
83
112
  }
@@ -90,6 +119,16 @@ class BST extends binary_tree_1.BinaryTree {
90
119
  }
91
120
  return inserted;
92
121
  }
122
+ /**
123
+ * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
124
+ * manner.
125
+ * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
126
+ * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
127
+ * to the binary search tree.
128
+ * @param {N['val'][]} data - The values of tree nodes
129
+ * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
130
+ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
131
+ */
93
132
  addMany(keysOrNodes, data, isBalanceAdd = false) {
94
133
  function hasNoNull(arr) {
95
134
  return arr.indexOf(null) === -1;
@@ -158,10 +197,25 @@ class BST extends binary_tree_1.BinaryTree {
158
197
  }
159
198
  return inserted;
160
199
  }
200
+ /**
201
+ * The function returns the first node in a binary tree that matches the given property name and value.
202
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
203
+ * generic type `N`. It represents the property of the binary tree node that you want to search for.
204
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
205
+ * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
206
+ * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
207
+ */
161
208
  get(nodeProperty, propertyName = 'key') {
162
209
  var _a;
163
210
  return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
164
211
  }
212
+ /**
213
+ * The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
214
+ * leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
215
+ * @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
216
+ * the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
217
+ * equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
218
+ */
165
219
  lastKey() {
166
220
  var _a, _b, _c, _d, _e, _f;
167
221
  if (this._compare(0, 1) === types_1.CP.lt)
@@ -171,6 +225,17 @@ class BST extends binary_tree_1.BinaryTree {
171
225
  else
172
226
  return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
173
227
  }
228
+ /**
229
+ * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
230
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
231
+ * `N` type. It represents the property of the binary tree node that you want to compare with.
232
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
233
+ * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
234
+ * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
235
+ * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
236
+ * is set to `true`, the function will return an array with only one node (if
237
+ * @returns an array of nodes (type N).
238
+ */
174
239
  getNodes(nodeProperty, propertyName = 'key', onlyOne = false) {
175
240
  if (!this.root)
176
241
  return [];
@@ -216,6 +281,16 @@ class BST extends binary_tree_1.BinaryTree {
216
281
  }
217
282
  return result;
218
283
  }
284
+ // --- start additional functions
285
+ /**
286
+ * The `lesserSum` function calculates the sum of property values in a binary tree for nodes that have a property value
287
+ * less than a given node.
288
+ * @param {N | BinaryTreeNodeKey | null} beginNode - The `beginNode` parameter can be one of the following:
289
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
290
+ * specifies the property name to use for calculating the sum. If not provided, it defaults to `'key'`.
291
+ * @returns The function `lesserSum` returns a number, which represents the sum of the values of the nodes in the
292
+ * binary tree that have a lesser value than the specified `beginNode` based on the `propertyName`.
293
+ */
219
294
  lesserSum(beginNode, propertyName = 'key') {
220
295
  if (typeof beginNode === 'number')
221
296
  beginNode = this.get(beginNode, 'key');
@@ -275,6 +350,7 @@ class BST extends binary_tree_1.BinaryTree {
275
350
  return sum;
276
351
  }
277
352
  else if (compared === types_1.CP.lt) {
353
+ // todo maybe a bug
278
354
  if (cur.left)
279
355
  sum += this.subTreeSum(cur.left, propertyName);
280
356
  sum += getSumByPropertyName(cur);
@@ -294,6 +370,18 @@ class BST extends binary_tree_1.BinaryTree {
294
370
  }
295
371
  return sum;
296
372
  }
373
+ /**
374
+ * The `allGreaterNodesAdd` function adds a delta value to the specified property of all nodes in a binary tree that
375
+ * have a greater value than a given node.
376
+ * @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type),
377
+ * `BinaryTreeNodeKey`, or `null`. It represents the node in the binary tree to which the delta value will be added.
378
+ * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
379
+ * each greater node should be increased.
380
+ * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
381
+ * specifies the property name of the nodes in the binary tree that you want to update. If not provided, it defaults to
382
+ * 'key'.
383
+ * @returns a boolean value.
384
+ */
297
385
  allGreaterNodesAdd(node, delta, propertyName = 'key') {
298
386
  if (typeof node === 'number')
299
387
  node = this.get(node, 'key');
@@ -344,6 +432,20 @@ class BST extends binary_tree_1.BinaryTree {
344
432
  return true;
345
433
  }
346
434
  }
435
+ /**
436
+ * Balancing Adjustment:
437
+ * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
438
+ * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
439
+ *
440
+ * Use Cases and Efficiency:
441
+ * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
442
+ * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
443
+ */
444
+ /**
445
+ * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
446
+ * constructs a balanced binary search tree using either a recursive or iterative approach.
447
+ * @returns The function `perfectlyBalance()` returns a boolean value.
448
+ */
347
449
  perfectlyBalance() {
348
450
  const sorted = this.dfs('in', 'node'), n = sorted.length;
349
451
  this.clear();
@@ -380,6 +482,10 @@ class BST extends binary_tree_1.BinaryTree {
380
482
  return true;
381
483
  }
382
484
  }
485
+ /**
486
+ * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
487
+ * @returns a boolean value.
488
+ */
383
489
  isAVLBalanced() {
384
490
  var _a, _b;
385
491
  if (!this.root)
@@ -426,6 +532,14 @@ class BST extends binary_tree_1.BinaryTree {
426
532
  }
427
533
  return balanced;
428
534
  }
535
+ /**
536
+ * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
537
+ * greater than, less than, or equal to the second ID.
538
+ * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
539
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
540
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
541
+ * than), or CP.eq (equal).
542
+ */
429
543
  _compare(a, b) {
430
544
  const compared = this._comparator(a, b);
431
545
  if (compared > 0)
@@ -1 +1 @@
1
- {"version":3,"file":"bst.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/bst.ts"],"names":[],"mappings":";;;AAcA,uCAAyC;AACzC,+CAAyD;AAGzD,MAAa,OACX,SAAQ,4BAA2B;IAGnC,YAAY,GAAsB,EAAE,GAAO;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAPD,0BAOC;AAED,MAAa,GAA8C,SAAQ,wBAAa;IAK9E,YAAY,OAAoB;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAC;QA0eP,gBAAW,GAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAzerD,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,MAAM,EAAC,UAAU,EAAC,GAAG,OAAO,CAAC;YAC7B,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC5B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;aAC/B;SACF;IACH,CAAC;IAUQ,UAAU,CAAC,GAAsB,EAAE,GAAc;QACxD,OAAO,IAAI,OAAO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binary-indexed-tree';
5
+ export * from './segment-tree';
6
+ export * from './avl-tree';
7
+ export * from './b-tree';
8
+ export * from './rb-tree';
9
+ export * from './splay-tree';
10
+ export * from './aa-tree';
11
+ export * from './tree-multiset';
12
+ export * from './two-three-tree';
@@ -0,0 +1,13 @@
1
+ import { BinaryTreeNodeKey, RBColor, RBTreeNodeNested, RBTreeOptions } from '../../types';
2
+ import { IRBTree, IRBTreeNode } from '../../interfaces';
3
+ import { BST, BSTNode } from './bst';
4
+ export declare class RBTreeNode<V = any, NEIGHBOR extends RBTreeNode<V, NEIGHBOR> = RBTreeNodeNested<V>> extends BSTNode<V, NEIGHBOR> implements IRBTreeNode<V, NEIGHBOR> {
5
+ private _color;
6
+ constructor(key: BinaryTreeNodeKey, val?: V);
7
+ get color(): RBColor;
8
+ set color(value: RBColor);
9
+ }
10
+ export declare class RBTree<N extends RBTreeNode<N['val'], N> = RBTreeNode> extends BST<N> implements IRBTree<N> {
11
+ constructor(options?: RBTreeOptions);
12
+ createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
13
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { SegmentTreeNodeVal } from '../../types';
9
+ export declare class SegmentTreeNode {
10
+ constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
11
+ private _start;
12
+ get start(): number;
13
+ set start(v: number);
14
+ private _end;
15
+ get end(): number;
16
+ set end(v: number);
17
+ private _val;
18
+ get val(): SegmentTreeNodeVal | null;
19
+ set val(v: SegmentTreeNodeVal | null);
20
+ private _sum;
21
+ get sum(): number;
22
+ set sum(v: number);
23
+ private _left;
24
+ get left(): SegmentTreeNode | null;
25
+ set left(v: SegmentTreeNode | null);
26
+ private _right;
27
+ get right(): SegmentTreeNode | null;
28
+ set right(v: SegmentTreeNode | null);
29
+ }
30
+ export declare class SegmentTree {
31
+ /**
32
+ * The constructor initializes the values, start, end, and root properties of an object.
33
+ * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
34
+ * @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
35
+ * be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
36
+ * the beginning of the array.
37
+ * @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
38
+ * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
39
+ */
40
+ constructor(values: number[], start?: number, end?: number);
41
+ private _values;
42
+ get values(): number[];
43
+ private _start;
44
+ get start(): number;
45
+ private _end;
46
+ get end(): number;
47
+ private _root;
48
+ get root(): SegmentTreeNode | null;
49
+ /**
50
+ * The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
51
+ * the sum of values to each segment.
52
+ * @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
53
+ * building the segment tree.
54
+ * @param {number} end - The "end" parameter represents the ending index of the segment or range for which we want to
55
+ * build a segment tree.
56
+ * @returns a SegmentTreeNode object.
57
+ */
58
+ build(start: number, end: number): SegmentTreeNode;
59
+ /**
60
+ * The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
61
+ * @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
62
+ * updated.
63
+ * @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
64
+ * the `SegmentTreeNode` at the specified `index`.
65
+ * @param {SegmentTreeNodeVal} [val] - The `val` parameter is an optional value that can be assigned to the `val`
66
+ * property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
67
+ * cur.val = val;` and pass a value for `val` in the
68
+ * @returns The function does not return anything.
69
+ */
70
+ updateNode(index: number, sum: number, val?: SegmentTreeNodeVal): void;
71
+ /**
72
+ * The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
73
+ * @param {number} indexA - The starting index of the range for which you want to calculate the sum.
74
+ * @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
75
+ * calculate the sum.
76
+ * @returns The function `querySumByRange` returns a number.
77
+ */
78
+ querySumByRange(indexA: number, indexB: number): number;
79
+ protected _setValues(value: number[]): void;
80
+ protected _setStart(value: number): void;
81
+ protected _setEnd(value: number): void;
82
+ protected _setRoot(v: SegmentTreeNode | null): void;
83
+ }
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
+ /**
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.SegmentTree = exports.SegmentTreeNode = void 0;
4
11
  class SegmentTreeNode {
@@ -53,6 +60,15 @@ class SegmentTreeNode {
53
60
  }
54
61
  exports.SegmentTreeNode = SegmentTreeNode;
55
62
  class SegmentTree {
63
+ /**
64
+ * The constructor initializes the values, start, end, and root properties of an object.
65
+ * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
66
+ * @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
67
+ * be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
68
+ * the beginning of the array.
69
+ * @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
70
+ * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
71
+ */
56
72
  constructor(values, start, end) {
57
73
  this._values = [];
58
74
  this._start = 0;
@@ -81,6 +97,15 @@ class SegmentTree {
81
97
  get root() {
82
98
  return this._root;
83
99
  }
100
+ /**
101
+ * The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
102
+ * the sum of values to each segment.
103
+ * @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
104
+ * building the segment tree.
105
+ * @param {number} end - The "end" parameter represents the ending index of the segment or range for which we want to
106
+ * build a segment tree.
107
+ * @returns a SegmentTreeNode object.
108
+ */
84
109
  build(start, end) {
85
110
  if (start > end) {
86
111
  return new SegmentTreeNode(start, end, 0);
@@ -95,6 +120,17 @@ class SegmentTree {
95
120
  cur.right = right;
96
121
  return cur;
97
122
  }
123
+ /**
124
+ * The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
125
+ * @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
126
+ * updated.
127
+ * @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
128
+ * the `SegmentTreeNode` at the specified `index`.
129
+ * @param {SegmentTreeNodeVal} [val] - The `val` parameter is an optional value that can be assigned to the `val`
130
+ * property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
131
+ * cur.val = val;` and pass a value for `val` in the
132
+ * @returns The function does not return anything.
133
+ */
98
134
  updateNode(index, sum, val) {
99
135
  const root = this.root || null;
100
136
  if (!root) {
@@ -124,6 +160,13 @@ class SegmentTree {
124
160
  };
125
161
  dfs(root, index, sum, val);
126
162
  }
163
+ /**
164
+ * The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
165
+ * @param {number} indexA - The starting index of the range for which you want to calculate the sum.
166
+ * @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
167
+ * calculate the sum.
168
+ * @returns The function `querySumByRange` returns a number.
169
+ */
127
170
  querySumByRange(indexA, indexB) {
128
171
  const root = this.root || null;
129
172
  if (!root) {
@@ -134,6 +177,7 @@ class SegmentTree {
134
177
  }
135
178
  const dfs = (cur, i, j) => {
136
179
  if (i <= cur.start && j >= cur.end) {
180
+ // The range [i, j] completely covers the current node's range [cur.start, cur.end]
137
181
  return cur.sum;
138
182
  }
139
183
  const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
@@ -154,6 +198,7 @@ class SegmentTree {
154
198
  }
155
199
  }
156
200
  else {
201
+ // Query both left and right subtrees
157
202
  let leftSum = 0;
158
203
  let rightSum = 0;
159
204
  if (cur.left) {