linked-list-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/dist/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +51 -20
- package/dist/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/data-structures/binary-tree/index.js +2 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +90 -24
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +200 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/index.js +2 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
- package/package.json +2 -2
- 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/dist/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/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -198,7 +198,10 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
198
198
|
*/
|
|
199
199
|
print(): void;
|
|
200
200
|
abstract isEmpty(): boolean;
|
|
201
|
+
abstract clear(): void;
|
|
201
202
|
abstract clone(): any;
|
|
203
|
+
abstract map(...args: any[]): any;
|
|
204
|
+
abstract filter(...args: any[]): any;
|
|
202
205
|
protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
|
|
203
206
|
}
|
|
204
207
|
export declare abstract class IterableElementBase<E = any, C = any> {
|
|
@@ -343,6 +346,9 @@ export declare abstract class IterableElementBase<E = any, C = any> {
|
|
|
343
346
|
*/
|
|
344
347
|
print(): void;
|
|
345
348
|
abstract isEmpty(): boolean;
|
|
349
|
+
abstract clear(): void;
|
|
346
350
|
abstract clone(): C;
|
|
351
|
+
abstract map(...args: any[]): any;
|
|
352
|
+
abstract filter(...args: any[]): any;
|
|
347
353
|
protected abstract _getIterator(...args: any[]): IterableIterator<E>;
|
|
348
354
|
}
|
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
|
|
9
9
|
import { IterationType } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
|
-
export declare class
|
|
13
|
-
count: number;
|
|
12
|
+
export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
14
13
|
/**
|
|
15
14
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
16
15
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -22,13 +21,30 @@ export declare class TreeMultimapNode<K = any, V = any, NODE extends TreeMultima
|
|
|
22
21
|
* parameter when creating a new instance of the `BinaryTreeNode` class.
|
|
23
22
|
*/
|
|
24
23
|
constructor(key: K, value?: V, count?: number);
|
|
24
|
+
protected _count: number;
|
|
25
|
+
/**
|
|
26
|
+
* The function returns the value of the protected variable _count.
|
|
27
|
+
* @returns The count property of the object, which is of type number.
|
|
28
|
+
*/
|
|
29
|
+
get count(): number;
|
|
30
|
+
/**
|
|
31
|
+
* The above function sets the value of the count property.
|
|
32
|
+
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
33
|
+
* numeric value.
|
|
34
|
+
*/
|
|
35
|
+
set count(value: number);
|
|
25
36
|
}
|
|
26
37
|
/**
|
|
27
|
-
* The only distinction between a
|
|
38
|
+
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
28
39
|
*/
|
|
29
|
-
export declare class
|
|
30
|
-
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?:
|
|
31
|
-
|
|
40
|
+
export declare class AVLTreeMultiMap<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, NODE, TREE> = AVLTreeMultiMap<K, V, NODE, AVLTreeMultiMapNested<K, V, NODE>>> extends AVLTree<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
|
|
41
|
+
constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K>);
|
|
42
|
+
protected _count: number;
|
|
43
|
+
/**
|
|
44
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
45
|
+
* search.
|
|
46
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
47
|
+
*/
|
|
32
48
|
get count(): number;
|
|
33
49
|
/**
|
|
34
50
|
* The function creates a new BSTNode with the given key, value, and count.
|
|
@@ -40,7 +56,16 @@ export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNod
|
|
|
40
56
|
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
|
|
41
57
|
*/
|
|
42
58
|
createNode(key: K, value?: V, count?: number): NODE;
|
|
43
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
61
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
62
|
+
* configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
|
|
63
|
+
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
64
|
+
* the tree, respectively. These properties can be
|
|
65
|
+
* @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
|
|
66
|
+
* default options. The returned value is casted as `TREE`.
|
|
67
|
+
*/
|
|
68
|
+
createTree(options?: AVLTreeMultiMapOptions<K>): TREE;
|
|
44
69
|
/**
|
|
45
70
|
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
46
71
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
|
|
@@ -54,9 +79,9 @@ export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNod
|
|
|
54
79
|
*/
|
|
55
80
|
keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): NODE | undefined;
|
|
56
81
|
/**
|
|
57
|
-
* The function checks if an keyOrNodeOrEntry is an instance of the
|
|
82
|
+
* The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
|
|
58
83
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
59
|
-
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the
|
|
84
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
|
|
60
85
|
* class.
|
|
61
86
|
*/
|
|
62
87
|
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
|
|
@@ -154,5 +179,13 @@ export declare class TreeMultimap<K = any, V = any, NODE extends TreeMultimapNod
|
|
|
154
179
|
* if either `srcNode` or `destNode` is undefined.
|
|
155
180
|
*/
|
|
156
181
|
protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
184
|
+
* @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
|
|
185
|
+
* needs to be replaced in a data structure.
|
|
186
|
+
* @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
|
|
187
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
188
|
+
* superclass, after updating the `count` property of the `newNode` object.
|
|
189
|
+
*/
|
|
157
190
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
158
191
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AVLTreeMultiMap = exports.AVLTreeMultiMapNode = void 0;
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const avl_tree_1 = require("./avl-tree");
|
|
6
|
-
class
|
|
6
|
+
class AVLTreeMultiMapNode extends avl_tree_1.AVLTreeNode {
|
|
7
7
|
/**
|
|
8
8
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
9
9
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -16,14 +16,30 @@ class TreeMultimapNode extends avl_tree_1.AVLTreeNode {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(key, value, count = 1) {
|
|
18
18
|
super(key, value);
|
|
19
|
+
this._count = 1;
|
|
19
20
|
this.count = count;
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* The function returns the value of the protected variable _count.
|
|
24
|
+
* @returns The count property of the object, which is of type number.
|
|
25
|
+
*/
|
|
26
|
+
get count() {
|
|
27
|
+
return this._count;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The above function sets the value of the count property.
|
|
31
|
+
* @param {number} value - The value parameter is of type number, which means it can accept any
|
|
32
|
+
* numeric value.
|
|
33
|
+
*/
|
|
34
|
+
set count(value) {
|
|
35
|
+
this._count = value;
|
|
36
|
+
}
|
|
21
37
|
}
|
|
22
|
-
exports.
|
|
38
|
+
exports.AVLTreeMultiMapNode = AVLTreeMultiMapNode;
|
|
23
39
|
/**
|
|
24
|
-
* The only distinction between a
|
|
40
|
+
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
25
41
|
*/
|
|
26
|
-
class
|
|
42
|
+
class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
27
43
|
constructor(keysOrNodesOrEntries = [], options) {
|
|
28
44
|
super([], options);
|
|
29
45
|
this._count = 0;
|
|
@@ -31,6 +47,11 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
31
47
|
this.addMany(keysOrNodesOrEntries);
|
|
32
48
|
}
|
|
33
49
|
// TODO the _count is not accurate after nodes count modified
|
|
50
|
+
/**
|
|
51
|
+
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
52
|
+
* search.
|
|
53
|
+
* @returns the sum of the count property of all nodes in the tree.
|
|
54
|
+
*/
|
|
34
55
|
get count() {
|
|
35
56
|
let sum = 0;
|
|
36
57
|
this.dfs(node => (sum += node.count));
|
|
@@ -46,10 +67,19 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
46
67
|
* @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
|
|
47
68
|
*/
|
|
48
69
|
createNode(key, value, count) {
|
|
49
|
-
return new
|
|
70
|
+
return new AVLTreeMultiMapNode(key, value, count);
|
|
50
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* The function creates a new AVLTreeMultiMap object with the specified options and returns it.
|
|
74
|
+
* @param [options] - The `options` parameter is an optional object that contains additional
|
|
75
|
+
* configuration options for creating the `AVLTreeMultiMap` object. It can include properties such as
|
|
76
|
+
* `iterationType` and `variant`, which are used to specify the type of iteration and the variant of
|
|
77
|
+
* the tree, respectively. These properties can be
|
|
78
|
+
* @returns a new instance of the `AVLTreeMultiMap` class, with the provided options merged with the
|
|
79
|
+
* default options. The returned value is casted as `TREE`.
|
|
80
|
+
*/
|
|
51
81
|
createTree(options) {
|
|
52
|
-
return new
|
|
82
|
+
return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
|
|
53
83
|
}
|
|
54
84
|
/**
|
|
55
85
|
* The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
@@ -88,13 +118,13 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
88
118
|
return node;
|
|
89
119
|
}
|
|
90
120
|
/**
|
|
91
|
-
* The function checks if an keyOrNodeOrEntry is an instance of the
|
|
121
|
+
* The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
|
|
92
122
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
93
|
-
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the
|
|
123
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
|
|
94
124
|
* class.
|
|
95
125
|
*/
|
|
96
126
|
isNode(keyOrNodeOrEntry) {
|
|
97
|
-
return keyOrNodeOrEntry instanceof
|
|
127
|
+
return keyOrNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
98
128
|
}
|
|
99
129
|
/**
|
|
100
130
|
* Time Complexity: O(log n)
|
|
@@ -319,9 +349,17 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
319
349
|
}
|
|
320
350
|
return undefined;
|
|
321
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* The function replaces an old node with a new node and updates the count property of the new node.
|
|
354
|
+
* @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
|
|
355
|
+
* needs to be replaced in a data structure.
|
|
356
|
+
* @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
|
|
357
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
358
|
+
* superclass, after updating the `count` property of the `newNode` object.
|
|
359
|
+
*/
|
|
322
360
|
_replaceNode(oldNode, newNode) {
|
|
323
361
|
newNode.count = oldNode.count + newNode.count;
|
|
324
362
|
return super._replaceNode(oldNode, newNode);
|
|
325
363
|
}
|
|
326
364
|
}
|
|
327
|
-
exports.
|
|
365
|
+
exports.AVLTreeMultiMap = AVLTreeMultiMap;
|
|
@@ -9,8 +9,27 @@ import { BST, BSTNode } from './bst';
|
|
|
9
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, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The constructor function initializes a new instance of a class with a key and an optional value,
|
|
14
|
+
* and sets the height property to 0.
|
|
15
|
+
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
16
|
+
* constructor. It is used to initialize the key property of the object being created.
|
|
17
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
18
|
+
* value associated with the key in the constructor.
|
|
19
|
+
*/
|
|
13
20
|
constructor(key: K, value?: V);
|
|
21
|
+
protected _height: number;
|
|
22
|
+
/**
|
|
23
|
+
* The function returns the value of the height property.
|
|
24
|
+
* @returns The height of the object.
|
|
25
|
+
*/
|
|
26
|
+
get height(): number;
|
|
27
|
+
/**
|
|
28
|
+
* The above function sets the value of the height property.
|
|
29
|
+
* @param {number} value - The value parameter is a number that represents the new height value to be
|
|
30
|
+
* set.
|
|
31
|
+
*/
|
|
32
|
+
set height(value: number);
|
|
14
33
|
}
|
|
15
34
|
/**
|
|
16
35
|
* 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
|
|
@@ -195,5 +214,14 @@ export declare class AVLTree<K = any, V = any, NODE extends AVLTreeNode<K, V, NO
|
|
|
195
214
|
* AVL tree that needs to be balanced.
|
|
196
215
|
*/
|
|
197
216
|
protected _balancePath(node: KeyOrNodeOrEntry<K, V, NODE>): void;
|
|
217
|
+
/**
|
|
218
|
+
* The function replaces an old node with a new node while preserving the height of the old node.
|
|
219
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
|
|
220
|
+
* `newNode`.
|
|
221
|
+
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
222
|
+
* the data structure.
|
|
223
|
+
* @returns the result of calling the `_replaceNode` method on the superclass, passing in the
|
|
224
|
+
* `oldNode` and `newNode` as arguments.
|
|
225
|
+
*/
|
|
198
226
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
199
227
|
}
|
|
@@ -10,9 +10,32 @@ exports.AVLTree = exports.AVLTreeNode = void 0;
|
|
|
10
10
|
*/
|
|
11
11
|
const bst_1 = require("./bst");
|
|
12
12
|
class AVLTreeNode extends bst_1.BSTNode {
|
|
13
|
+
/**
|
|
14
|
+
* The constructor function initializes a new instance of a class with a key and an optional value,
|
|
15
|
+
* and sets the height property to 0.
|
|
16
|
+
* @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
|
|
17
|
+
* constructor. It is used to initialize the key property of the object being created.
|
|
18
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
19
|
+
* value associated with the key in the constructor.
|
|
20
|
+
*/
|
|
13
21
|
constructor(key, value) {
|
|
14
22
|
super(key, value);
|
|
15
|
-
this.
|
|
23
|
+
this._height = 0;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The function returns the value of the height property.
|
|
27
|
+
* @returns The height of the object.
|
|
28
|
+
*/
|
|
29
|
+
get height() {
|
|
30
|
+
return this._height;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The above function sets the value of the height property.
|
|
34
|
+
* @param {number} value - The value parameter is a number that represents the new height value to be
|
|
35
|
+
* set.
|
|
36
|
+
*/
|
|
37
|
+
set height(value) {
|
|
38
|
+
this._height = value;
|
|
16
39
|
}
|
|
17
40
|
}
|
|
18
41
|
exports.AVLTreeNode = AVLTreeNode;
|
|
@@ -450,6 +473,15 @@ class AVLTree extends bst_1.BST {
|
|
|
450
473
|
// 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.
|
|
451
474
|
}
|
|
452
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* The function replaces an old node with a new node while preserving the height of the old node.
|
|
478
|
+
* @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
|
|
479
|
+
* `newNode`.
|
|
480
|
+
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
481
|
+
* the data structure.
|
|
482
|
+
* @returns the result of calling the `_replaceNode` method on the superclass, passing in the
|
|
483
|
+
* `oldNode` and `newNode` as arguments.
|
|
484
|
+
*/
|
|
453
485
|
_replaceNode(oldNode, newNode) {
|
|
454
486
|
newNode.height = oldNode.height;
|
|
455
487
|
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,18 +23,40 @@ class BinaryIndexedTree {
|
|
|
23
23
|
this._msb = (0, utils_1.getMSB)(max);
|
|
24
24
|
this._negativeCount = frequency < 0 ? max : 0;
|
|
25
25
|
}
|
|
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
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The function returns the value of the _msb property.
|
|
36
|
+
* @returns The `_msb` property of the object.
|
|
37
|
+
*/
|
|
29
38
|
get msb() {
|
|
30
39
|
return this._msb;
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The function returns the value of the _negativeCount property.
|
|
43
|
+
* @returns The method is returning the value of the variable `_negativeCount`, which is of type
|
|
44
|
+
* `number`.
|
|
45
|
+
*/
|
|
32
46
|
get negativeCount() {
|
|
33
47
|
return this._negativeCount;
|
|
34
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The above function returns the value of the protected variable `_freq`.
|
|
51
|
+
* @returns The frequency value stored in the protected variable `_freq`.
|
|
52
|
+
*/
|
|
35
53
|
get freq() {
|
|
36
54
|
return this._freq;
|
|
37
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* The above function returns the maximum value.
|
|
58
|
+
* @returns The maximum value stored in the variable `_max`.
|
|
59
|
+
*/
|
|
38
60
|
get max() {
|
|
39
61
|
return this._max;
|
|
40
62
|
}
|
|
@@ -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 @@ 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
|