data-structure-typed 1.50.2 → 1.50.4
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.
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -13
- package/CHANGELOG.md +1 -1
- package/README.md +23 -21
- package/README_zh-CN.md +7 -7
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -155
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/cjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +50 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +400 -0
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/cjs/data-structures/hash/hash-map.js +196 -62
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/cjs/data-structures/heap/heap.js +29 -20
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/cjs/data-structures/queue/deque.js +100 -16
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/cjs/data-structures/queue/queue.js +65 -45
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/cjs/data-structures/stack/stack.js +36 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/cjs/data-structures/trie/trie.js +115 -36
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +3 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/cjs/types/data-structures/binary-tree/{tree-multimap.js → tree-multi-map.js} +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/mjs/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +46 -9
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +51 -20
- package/dist/mjs/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +91 -25
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +397 -0
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/mjs/data-structures/hash/hash-map.js +204 -70
- package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/mjs/data-structures/heap/heap.js +29 -20
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/mjs/data-structures/matrix/matrix.js +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/mjs/data-structures/queue/deque.js +105 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/mjs/data-structures/queue/queue.js +65 -45
- package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/mjs/data-structures/stack/stack.js +36 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/mjs/data-structures/trie/trie.js +118 -39
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/mjs/types/data-structures/binary-tree/index.js +2 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.js +1 -0
- package/dist/umd/data-structure-typed.js +1876 -656
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +59 -58
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/test/integration/index.html +2 -2
- package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/{tree-multimap.test.ts → avl-tree-multi-map.test.ts} +55 -55
- package/test/unit/data-structures/binary-tree/overall.test.ts +24 -25
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +706 -0
- package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/queue/queue.test.ts +2 -0
- package/test/unit/unrestricted-interconversion.test.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.js.map +0 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/mjs/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -7,10 +7,33 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
9
|
export class AVLTreeNode extends BSTNode {
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The constructor function initializes a new instance of a class with a key and an optional value,
|
|
12
|
+
* and sets the height property to 0.
|
|
13
|
+
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
14
|
+
* constructor. It is used to initialize the key property of the object being created.
|
|
15
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
16
|
+
* value associated with the key in the constructor.
|
|
17
|
+
*/
|
|
11
18
|
constructor(key, value) {
|
|
12
19
|
super(key, value);
|
|
13
|
-
this.
|
|
20
|
+
this._height = 0;
|
|
21
|
+
}
|
|
22
|
+
_height;
|
|
23
|
+
/**
|
|
24
|
+
* The function returns the value of the height property.
|
|
25
|
+
* @returns The height of the object.
|
|
26
|
+
*/
|
|
27
|
+
get height() {
|
|
28
|
+
return this._height;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The above function sets the value of the height property.
|
|
32
|
+
* @param {number} value - The value parameter is a number that represents the new height value to be
|
|
33
|
+
* set.
|
|
34
|
+
*/
|
|
35
|
+
set height(value) {
|
|
36
|
+
this._height = value;
|
|
14
37
|
}
|
|
15
38
|
}
|
|
16
39
|
/**
|
|
@@ -451,6 +474,15 @@ export class AVLTree extends BST {
|
|
|
451
474
|
// TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
|
|
452
475
|
}
|
|
453
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* The function replaces an old node with a new node while preserving the height of the old node.
|
|
479
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
|
|
480
|
+
* `newNode`.
|
|
481
|
+
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
482
|
+
* the data structure.
|
|
483
|
+
* @returns the result of calling the `_replaceNode` method on the superclass, passing in the
|
|
484
|
+
* `oldNode` and `newNode` as arguments.
|
|
485
|
+
*/
|
|
454
486
|
_replaceNode(oldNode, newNode) {
|
|
455
487
|
newNode.height = oldNode.height;
|
|
456
488
|
return super._replaceNode(oldNode, newNode);
|
|
@@ -12,12 +12,34 @@ export declare class BinaryIndexedTree {
|
|
|
12
12
|
max: number;
|
|
13
13
|
});
|
|
14
14
|
protected _freqMap: Record<number, number>;
|
|
15
|
+
/**
|
|
16
|
+
* The function returns the frequency map of numbers.
|
|
17
|
+
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
18
|
+
* returned.
|
|
19
|
+
*/
|
|
15
20
|
get freqMap(): Record<number, number>;
|
|
16
21
|
protected _msb: number;
|
|
22
|
+
/**
|
|
23
|
+
* The function returns the value of the _msb property.
|
|
24
|
+
* @returns The `_msb` property of the object.
|
|
25
|
+
*/
|
|
17
26
|
get msb(): number;
|
|
18
27
|
protected _negativeCount: number;
|
|
28
|
+
/**
|
|
29
|
+
* The function returns the value of the _negativeCount property.
|
|
30
|
+
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
31
|
+
* `number`.
|
|
32
|
+
*/
|
|
19
33
|
get negativeCount(): number;
|
|
34
|
+
/**
|
|
35
|
+
* The above function returns the value of the protected variable `_freq`.
|
|
36
|
+
* @returns The frequency value stored in the protected variable `_freq`.
|
|
37
|
+
*/
|
|
20
38
|
get freq(): number;
|
|
39
|
+
/**
|
|
40
|
+
* The above function returns the maximum value.
|
|
41
|
+
* @returns The maximum value stored in the variable `_max`.
|
|
42
|
+
*/
|
|
21
43
|
get max(): number;
|
|
22
44
|
/**
|
|
23
45
|
* The function "readSingle" reads a single number from a specified index.
|
|
@@ -23,20 +23,42 @@ export class BinaryIndexedTree {
|
|
|
23
23
|
this._negativeCount = frequency < 0 ? max : 0;
|
|
24
24
|
}
|
|
25
25
|
_freqMap;
|
|
26
|
+
/**
|
|
27
|
+
* The function returns the frequency map of numbers.
|
|
28
|
+
* @returns The `_freqMap` property, which is a record with number keys and number values, is being
|
|
29
|
+
* returned.
|
|
30
|
+
*/
|
|
26
31
|
get freqMap() {
|
|
27
32
|
return this._freqMap;
|
|
28
33
|
}
|
|
29
34
|
_msb;
|
|
35
|
+
/**
|
|
36
|
+
* The function returns the value of the _msb property.
|
|
37
|
+
* @returns The `_msb` property of the object.
|
|
38
|
+
*/
|
|
30
39
|
get msb() {
|
|
31
40
|
return this._msb;
|
|
32
41
|
}
|
|
33
42
|
_negativeCount;
|
|
43
|
+
/**
|
|
44
|
+
* The function returns the value of the _negativeCount property.
|
|
45
|
+
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
46
|
+
* `number`.
|
|
47
|
+
*/
|
|
34
48
|
get negativeCount() {
|
|
35
49
|
return this._negativeCount;
|
|
36
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The above function returns the value of the protected variable `_freq`.
|
|
53
|
+
* @returns The frequency value stored in the protected variable `_freq`.
|
|
54
|
+
*/
|
|
37
55
|
get freq() {
|
|
38
56
|
return this._freq;
|
|
39
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* The above function returns the maximum value.
|
|
60
|
+
* @returns The maximum value stored in the variable `_max`.
|
|
61
|
+
*/
|
|
40
62
|
get max() {
|
|
41
63
|
return this._max;
|
|
42
64
|
}
|
|
@@ -21,7 +21,7 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
21
21
|
/**
|
|
22
22
|
* The constructor function initializes an object with a key and an optional value.
|
|
23
23
|
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
24
|
-
* constructor. It is used to set the
|
|
24
|
+
* constructor. It is used to set the key property of the object being created.
|
|
25
25
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
26
26
|
* value associated with the key in the constructor.
|
|
27
27
|
*/
|
|
@@ -21,7 +21,7 @@ export class BinaryTreeNode {
|
|
|
21
21
|
/**
|
|
22
22
|
* The constructor function initializes an object with a key and an optional value.
|
|
23
23
|
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
24
|
-
* constructor. It is used to set the
|
|
24
|
+
* constructor. It is used to set the key property of the object being created.
|
|
25
25
|
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
26
26
|
* value associated with the key in the constructor.
|
|
27
27
|
*/
|
|
@@ -13,10 +13,29 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
|
|
|
13
13
|
parent?: NODE;
|
|
14
14
|
constructor(key: K, value?: V);
|
|
15
15
|
protected _left?: NODE;
|
|
16
|
+
/**
|
|
17
|
+
* The function returns the value of the `_left` property.
|
|
18
|
+
* @returns The `_left` property of the current object is being returned.
|
|
19
|
+
*/
|
|
16
20
|
get left(): NODE | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The function sets the left child of a node and updates the parent reference of the child.
|
|
23
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
|
|
24
|
+
* instance of the `NODE` class or `undefined`.
|
|
25
|
+
*/
|
|
17
26
|
set left(v: NODE | undefined);
|
|
18
27
|
protected _right?: NODE;
|
|
28
|
+
/**
|
|
29
|
+
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
30
|
+
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
31
|
+
* `undefined`.
|
|
32
|
+
*/
|
|
19
33
|
get right(): NODE | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The function sets the right child of a node and updates the parent reference of the child.
|
|
36
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
|
|
37
|
+
* `NODE` object or `undefined`.
|
|
38
|
+
*/
|
|
20
39
|
set right(v: NODE | undefined);
|
|
21
40
|
}
|
|
22
41
|
/**
|
|
@@ -30,33 +49,42 @@ export declare class BSTNode<K = any, V = any, NODE extends BSTNode<K, V, NODE>
|
|
|
30
49
|
*/
|
|
31
50
|
export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BSTNode<K, V, BSTNodeNested<K, V>>, TREE extends BST<K, V, NODE, TREE> = BST<K, V, NODE, BSTNested<K, V, NODE>>> extends BinaryTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
32
51
|
/**
|
|
33
|
-
* This is the constructor function for a
|
|
34
|
-
*
|
|
35
|
-
* @param
|
|
36
|
-
* binary search tree.
|
|
52
|
+
* This is the constructor function for a TypeScript class that initializes a binary search tree with
|
|
53
|
+
* optional keys or nodes or entries and options.
|
|
54
|
+
* @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
|
|
55
|
+
* to initialize the binary search tree with the provided keys, nodes, or entries.
|
|
37
56
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
38
57
|
* configuration options for the binary search tree. It can have the following properties:
|
|
39
58
|
*/
|
|
40
59
|
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BSTOptions<K>);
|
|
41
60
|
protected _root?: NODE;
|
|
61
|
+
/**
|
|
62
|
+
* The function returns the root node of a tree structure.
|
|
63
|
+
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
64
|
+
*/
|
|
42
65
|
get root(): NODE | undefined;
|
|
43
66
|
protected _variant: BSTVariant;
|
|
67
|
+
/**
|
|
68
|
+
* The function returns the value of the _variant property.
|
|
69
|
+
* @returns The value of the `_variant` property.
|
|
70
|
+
*/
|
|
44
71
|
get variant(): BSTVariant;
|
|
45
72
|
/**
|
|
46
|
-
* The function creates a new
|
|
47
|
-
* @param {K} key - The key parameter is the
|
|
48
|
-
*
|
|
49
|
-
* @param [value] - The parameter
|
|
50
|
-
*
|
|
51
|
-
* @returns a new instance of the BSTNode class
|
|
73
|
+
* The function creates a new BSTNode with the given key and value and returns it.
|
|
74
|
+
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
75
|
+
* being created.
|
|
76
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
77
|
+
* value associated with the key in the node being created.
|
|
78
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
|
|
52
79
|
*/
|
|
53
80
|
createNode(key: K, value?: V): NODE;
|
|
54
81
|
/**
|
|
55
82
|
* The function creates a new binary search tree with the specified options.
|
|
56
83
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
57
|
-
* behavior of the `createTree` method. It
|
|
58
|
-
*
|
|
59
|
-
* @returns a new instance of the BST class with the
|
|
84
|
+
* behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
|
|
85
|
+
* partial object of type `BSTOptions<K>`.
|
|
86
|
+
* @returns a new instance of the BST class, with the provided options merged with the default
|
|
87
|
+
* options. The returned value is casted as TREE.
|
|
60
88
|
*/
|
|
61
89
|
createTree(options?: Partial<BSTOptions<K>>): TREE;
|
|
62
90
|
/**
|
|
@@ -333,6 +361,11 @@ export declare class BST<K = any, V = any, NODE extends BSTNode<K, V, NODE> = BS
|
|
|
333
361
|
* @returns a boolean value.
|
|
334
362
|
*/
|
|
335
363
|
isAVLBalanced(iterationType?: IterationType): boolean;
|
|
364
|
+
/**
|
|
365
|
+
* The function sets the root property of an object and updates the parent property of the new root.
|
|
366
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
|
|
367
|
+
* can either be an object of type `NODE` or it can be `undefined`.
|
|
368
|
+
*/
|
|
336
369
|
protected _setRoot(v: NODE | undefined): void;
|
|
337
370
|
/**
|
|
338
371
|
* The function compares two values using a comparator function and returns whether the first value
|
|
@@ -10,9 +10,18 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
10
10
|
this._right = undefined;
|
|
11
11
|
}
|
|
12
12
|
_left;
|
|
13
|
+
/**
|
|
14
|
+
* The function returns the value of the `_left` property.
|
|
15
|
+
* @returns The `_left` property of the current object is being returned.
|
|
16
|
+
*/
|
|
13
17
|
get left() {
|
|
14
18
|
return this._left;
|
|
15
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* The function sets the left child of a node and updates the parent reference of the child.
|
|
22
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
|
|
23
|
+
* instance of the `NODE` class or `undefined`.
|
|
24
|
+
*/
|
|
16
25
|
set left(v) {
|
|
17
26
|
if (v) {
|
|
18
27
|
v.parent = this;
|
|
@@ -20,9 +29,19 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
20
29
|
this._left = v;
|
|
21
30
|
}
|
|
22
31
|
_right;
|
|
32
|
+
/**
|
|
33
|
+
* The function returns the right node of a binary tree or undefined if there is no right node.
|
|
34
|
+
* @returns The method is returning the value of the `_right` property, which is of type `NODE` or
|
|
35
|
+
* `undefined`.
|
|
36
|
+
*/
|
|
23
37
|
get right() {
|
|
24
38
|
return this._right;
|
|
25
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The function sets the right child of a node and updates the parent reference of the child.
|
|
42
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
|
|
43
|
+
* `NODE` object or `undefined`.
|
|
44
|
+
*/
|
|
26
45
|
set right(v) {
|
|
27
46
|
if (v) {
|
|
28
47
|
v.parent = this;
|
|
@@ -41,10 +60,10 @@ export class BSTNode extends BinaryTreeNode {
|
|
|
41
60
|
*/
|
|
42
61
|
export class BST extends BinaryTree {
|
|
43
62
|
/**
|
|
44
|
-
* This is the constructor function for a
|
|
45
|
-
*
|
|
46
|
-
* @param
|
|
47
|
-
* binary search tree.
|
|
63
|
+
* This is the constructor function for a TypeScript class that initializes a binary search tree with
|
|
64
|
+
* optional keys or nodes or entries and options.
|
|
65
|
+
* @param keysOrNodesOrEntries - An iterable object that contains keys, nodes, or entries. It is used
|
|
66
|
+
* to initialize the binary search tree with the provided keys, nodes, or entries.
|
|
48
67
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
49
68
|
* configuration options for the binary search tree. It can have the following properties:
|
|
50
69
|
*/
|
|
@@ -60,20 +79,28 @@ export class BST extends BinaryTree {
|
|
|
60
79
|
this.addMany(keysOrNodesOrEntries);
|
|
61
80
|
}
|
|
62
81
|
_root;
|
|
82
|
+
/**
|
|
83
|
+
* The function returns the root node of a tree structure.
|
|
84
|
+
* @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
|
|
85
|
+
*/
|
|
63
86
|
get root() {
|
|
64
87
|
return this._root;
|
|
65
88
|
}
|
|
66
89
|
_variant = BSTVariant.STANDARD;
|
|
90
|
+
/**
|
|
91
|
+
* The function returns the value of the _variant property.
|
|
92
|
+
* @returns The value of the `_variant` property.
|
|
93
|
+
*/
|
|
67
94
|
get variant() {
|
|
68
95
|
return this._variant;
|
|
69
96
|
}
|
|
70
97
|
/**
|
|
71
|
-
* The function creates a new
|
|
72
|
-
* @param {K} key - The key parameter is the
|
|
73
|
-
*
|
|
74
|
-
* @param [value] - The parameter
|
|
75
|
-
*
|
|
76
|
-
* @returns a new instance of the BSTNode class
|
|
98
|
+
* The function creates a new BSTNode with the given key and value and returns it.
|
|
99
|
+
* @param {K} key - The key parameter is of type K, which represents the type of the key for the node
|
|
100
|
+
* being created.
|
|
101
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
102
|
+
* value associated with the key in the node being created.
|
|
103
|
+
* @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
|
|
77
104
|
*/
|
|
78
105
|
createNode(key, value) {
|
|
79
106
|
return new BSTNode(key, value);
|
|
@@ -81,9 +108,10 @@ export class BST extends BinaryTree {
|
|
|
81
108
|
/**
|
|
82
109
|
* The function creates a new binary search tree with the specified options.
|
|
83
110
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
84
|
-
* behavior of the `createTree` method. It
|
|
85
|
-
*
|
|
86
|
-
* @returns a new instance of the BST class with the
|
|
111
|
+
* behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
|
|
112
|
+
* partial object of type `BSTOptions<K>`.
|
|
113
|
+
* @returns a new instance of the BST class, with the provided options merged with the default
|
|
114
|
+
* options. The returned value is casted as TREE.
|
|
87
115
|
*/
|
|
88
116
|
createTree(options) {
|
|
89
117
|
return new BST([], {
|
|
@@ -600,11 +628,9 @@ export class BST extends BinaryTree {
|
|
|
600
628
|
const compared = this._compare(cur.key, targetKey);
|
|
601
629
|
if (compared === lesserOrGreater)
|
|
602
630
|
ans.push(callback(cur));
|
|
603
|
-
if (
|
|
604
|
-
return;
|
|
605
|
-
if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater)
|
|
631
|
+
if (this.isRealNode(cur.left))
|
|
606
632
|
_traverse(cur.left);
|
|
607
|
-
if (
|
|
633
|
+
if (this.isRealNode(cur.right))
|
|
608
634
|
_traverse(cur.right);
|
|
609
635
|
};
|
|
610
636
|
_traverse(this.root);
|
|
@@ -614,13 +640,13 @@ export class BST extends BinaryTree {
|
|
|
614
640
|
const queue = new Queue([this.root]);
|
|
615
641
|
while (queue.size > 0) {
|
|
616
642
|
const cur = queue.shift();
|
|
617
|
-
if (cur) {
|
|
643
|
+
if (this.isRealNode(cur)) {
|
|
618
644
|
const compared = this._compare(cur.key, targetKey);
|
|
619
645
|
if (compared === lesserOrGreater)
|
|
620
646
|
ans.push(callback(cur));
|
|
621
|
-
if (
|
|
647
|
+
if (this.isRealNode(cur.left))
|
|
622
648
|
queue.push(cur.left);
|
|
623
|
-
if (
|
|
649
|
+
if (this.isRealNode(cur.right))
|
|
624
650
|
queue.push(cur.right);
|
|
625
651
|
}
|
|
626
652
|
}
|
|
@@ -745,6 +771,11 @@ export class BST extends BinaryTree {
|
|
|
745
771
|
}
|
|
746
772
|
return balanced;
|
|
747
773
|
}
|
|
774
|
+
/**
|
|
775
|
+
* The function sets the root property of an object and updates the parent property of the new root.
|
|
776
|
+
* @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
|
|
777
|
+
* can either be an object of type `NODE` or it can be `undefined`.
|
|
778
|
+
*/
|
|
748
779
|
_setRoot(v) {
|
|
749
780
|
if (v) {
|
|
750
781
|
v.parent = undefined;
|
|
@@ -9,8 +9,29 @@ import { BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry, R
|
|
|
9
9
|
import { BST, BSTNode } from './bst';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
|
|
14
|
+
* color.
|
|
15
|
+
* @param {K} key - The key parameter is of type K and represents the key of the node in the
|
|
16
|
+
* Red-Black Tree.
|
|
17
|
+
* @param {V} [value] - The `value` parameter is an optional parameter that represents the value
|
|
18
|
+
* associated with the key in the Red-Black Tree Node. It is not required and can be omitted when
|
|
19
|
+
* creating a new instance of the Red-Black Tree Node.
|
|
20
|
+
* @param {RBTNColor} color - The `color` parameter is used to specify the color of the Red-Black
|
|
21
|
+
* Tree Node. It is an optional parameter with a default value of `RBTNColor.BLACK`.
|
|
22
|
+
*/
|
|
13
23
|
constructor(key: K, value?: V, color?: RBTNColor);
|
|
24
|
+
protected _color: RBTNColor;
|
|
25
|
+
/**
|
|
26
|
+
* The function returns the color value of a variable.
|
|
27
|
+
* @returns The color value stored in the protected variable `_color`.
|
|
28
|
+
*/
|
|
29
|
+
get color(): RBTNColor;
|
|
30
|
+
/**
|
|
31
|
+
* The function sets the color property to the specified value.
|
|
32
|
+
* @param {RBTNColor} value - The value parameter is of type RBTNColor.
|
|
33
|
+
*/
|
|
34
|
+
set color(value: RBTNColor);
|
|
14
35
|
}
|
|
15
36
|
/**
|
|
16
37
|
* 1. Each node is either red or black.
|
|
@@ -20,7 +41,6 @@ export declare class RedBlackTreeNode<K = any, V = any, NODE extends RedBlackTre
|
|
|
20
41
|
* 5. Black balance: Every path from any node to each of its leaf nodes contains the same number of black nodes.
|
|
21
42
|
*/
|
|
22
43
|
export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNode<K, V, NODE> = RedBlackTreeNode<K, V, RedBlackTreeNodeNested<K, V>>, TREE extends RedBlackTree<K, V, NODE, TREE> = RedBlackTree<K, V, NODE, RedBlackTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
23
|
-
Sentinel: NODE;
|
|
24
44
|
/**
|
|
25
45
|
* This is the constructor function for a Red-Black Tree data structure in TypeScript, which
|
|
26
46
|
* initializes the tree with optional nodes and options.
|
|
@@ -33,9 +53,23 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
33
53
|
* only a subset of the properties defined in the `RBTreeOptions` interface.
|
|
34
54
|
*/
|
|
35
55
|
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: RBTreeOptions<K>);
|
|
56
|
+
protected _Sentinel: NODE;
|
|
57
|
+
/**
|
|
58
|
+
* The function returns the value of the `_Sentinel` property.
|
|
59
|
+
* @returns The method is returning the value of the `_Sentinel` property.
|
|
60
|
+
*/
|
|
61
|
+
get Sentinel(): NODE;
|
|
36
62
|
protected _root: NODE;
|
|
63
|
+
/**
|
|
64
|
+
* The function returns the root node.
|
|
65
|
+
* @returns The root node of the data structure.
|
|
66
|
+
*/
|
|
37
67
|
get root(): NODE;
|
|
38
68
|
protected _size: number;
|
|
69
|
+
/**
|
|
70
|
+
* The function returns the size of an object.
|
|
71
|
+
* @returns The size of the object, which is a number.
|
|
72
|
+
*/
|
|
39
73
|
get size(): number;
|
|
40
74
|
/**
|
|
41
75
|
* The function creates a new Red-Black Tree node with the specified key, value, and color.
|
|
@@ -74,6 +108,12 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
74
108
|
* class.
|
|
75
109
|
*/
|
|
76
110
|
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
111
|
+
/**
|
|
112
|
+
* The function checks if a given node is a real node in a Red-Black Tree.
|
|
113
|
+
* @param {NODE | undefined} node - The `node` parameter is of type `NODE | undefined`, which means
|
|
114
|
+
* it can either be of type `NODE` or `undefined`.
|
|
115
|
+
* @returns a boolean value.
|
|
116
|
+
*/
|
|
77
117
|
isRealNode(node: NODE | undefined): node is NODE;
|
|
78
118
|
/**
|
|
79
119
|
* Time Complexity: O(log n)
|
|
@@ -143,6 +183,12 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
143
183
|
* Time Complexity: O(1)
|
|
144
184
|
* Space Complexity: O(1)
|
|
145
185
|
*/
|
|
186
|
+
/**
|
|
187
|
+
* Time Complexity: O(1)
|
|
188
|
+
* Space Complexity: O(1)
|
|
189
|
+
*
|
|
190
|
+
* The "clear" function sets the root node to the sentinel node and resets the size to 0.
|
|
191
|
+
*/
|
|
146
192
|
clear(): void;
|
|
147
193
|
/**
|
|
148
194
|
* Time Complexity: O(log n)
|
|
@@ -158,6 +204,12 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
|
|
|
158
204
|
* @returns the predecessor of the given RedBlackTreeNode 'x'.
|
|
159
205
|
*/
|
|
160
206
|
getPredecessor(x: NODE): NODE;
|
|
207
|
+
/**
|
|
208
|
+
* The function sets the root node of a tree structure and updates the parent property of the new
|
|
209
|
+
* root node.
|
|
210
|
+
* @param {NODE} v - The parameter "v" is of type "NODE", which represents a node in a data
|
|
211
|
+
* structure.
|
|
212
|
+
*/
|
|
161
213
|
protected _setRoot(v: NODE): void;
|
|
162
214
|
/**
|
|
163
215
|
* Time Complexity: O(1)
|