data-structure-typed 2.1.1 → 2.2.0
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/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +4 -0
- package/README.md +19 -7
- package/dist/cjs/index.cjs +1175 -585
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/{index.cjs → cjs-legacy/index.cjs} +1145 -613
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +1175 -585
- package/dist/esm/index.mjs.map +1 -1
- package/dist/{index.js → esm-legacy/index.mjs} +1147 -615
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +66 -4
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +59 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +60 -6
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +58 -4
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -4
- package/dist/types/data-structures/heap/heap.d.ts +4 -4
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
- package/dist/types/interfaces/binary-tree.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +711 -228
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/jest.integration.config.js +7 -3
- package/package.json +29 -7
- package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +107 -16
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +103 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
- package/src/data-structures/binary-tree/tree-counter.ts +105 -14
- package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +1 -1
- package/test/integration/compile.test.mjs +159 -0
- package/test/integration/compile.test.ts +176 -0
- package/test/integration/heap.test.js +1 -1
- package/test/integration/index.html +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/bst.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +3 -3
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +5 -4
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +4 -4
- package/{tsconfig-base.json → tsconfig.base.json} +0 -1
- package/tsconfig.test.json +1 -0
- package/{tsconfig-types.json → tsconfig.types.json} +1 -3
- package/tsup.config.js +2 -3
- package/tsup.node.config.js +71 -0
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/test/integration/compile.js +0 -144
- package/test/integration/compile.mjs +0 -135
- package/test/integration/compile.ts +0 -171
- package/tsup.node.config.ts +0 -37
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
preset: 'ts-jest',
|
|
3
3
|
testEnvironment: 'node',
|
|
4
|
-
testMatch: [
|
|
4
|
+
testMatch: [
|
|
5
|
+
'<rootDir>/test/integration/**/*.test.ts',
|
|
6
|
+
'<rootDir>/test/integration/**/*.test.js',
|
|
7
|
+
'<rootDir>/test/integration/**/*.test.mjs'
|
|
8
|
+
],
|
|
5
9
|
transform: {
|
|
6
|
-
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }]
|
|
7
|
-
}
|
|
10
|
+
'^.+\\.(ts|tsx)$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }]
|
|
11
|
+
}
|
|
8
12
|
};
|
package/package.json
CHANGED
|
@@ -1,32 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Standard data structure",
|
|
5
5
|
"browser": "dist/umd/data-structure-typed.min.js",
|
|
6
6
|
"umd:main": "dist/umd/data-structure-typed.min.js",
|
|
7
7
|
"main": "dist/cjs/index.cjs",
|
|
8
|
-
"module": "
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
9
|
"types": "dist/types/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
+
"types": "./dist/types/index.d.ts",
|
|
13
|
+
"node": {
|
|
14
|
+
"import": "./dist/esm/index.mjs",
|
|
15
|
+
"require": "./dist/cjs/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"browser": {
|
|
18
|
+
"import": "./dist/esm-legacy/index.mjs",
|
|
19
|
+
"require": "./dist/cjs-legacy/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"import": "./dist/esm-legacy/index.mjs",
|
|
22
|
+
"require": "./dist/cjs-legacy/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./modern": {
|
|
12
25
|
"types": "./dist/types/index.d.ts",
|
|
13
26
|
"import": "./dist/esm/index.mjs",
|
|
14
27
|
"require": "./dist/cjs/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./legacy": {
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"import": "./dist/esm-legacy/index.mjs",
|
|
32
|
+
"require": "./dist/cjs-legacy/index.cjs"
|
|
15
33
|
}
|
|
16
34
|
},
|
|
17
35
|
"sideEffects": false,
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=12.20.0",
|
|
38
|
+
"npm": ">=6.14.0"
|
|
39
|
+
},
|
|
18
40
|
"scripts": {
|
|
19
41
|
"build": "npm run build:ecu && npm run build:docs-class",
|
|
20
|
-
"build:node": "tsup --config tsup.node.config.
|
|
21
|
-
"build:types": "rm -rf dist/types && tsc -p tsconfig
|
|
42
|
+
"build:node": "tsup --config tsup.node.config.js",
|
|
43
|
+
"build:types": "rm -rf dist/types && tsc -p tsconfig.types.json",
|
|
22
44
|
"build:umd": "tsup",
|
|
23
45
|
"build:ecu": "npm run build:node && npm run build:types && npm run build:umd",
|
|
24
46
|
"build:docs": "npm run gen:examples && typedoc --out docs ./src",
|
|
25
47
|
"build:docs-class": "npm run gen:examples && typedoc --out docs ./src/data-structures",
|
|
26
|
-
"gen:examples": "ts-node scripts/
|
|
48
|
+
"gen:examples": "ts-node scripts/test-to-example.ts",
|
|
27
49
|
"test:in-band": "jest --runInBand",
|
|
28
50
|
"test": "npm run test:in-band",
|
|
29
|
-
"test:integration": "npm run update:subs && jest --config jest.integration.config.js && tsc test/integration/compile.ts && node test/integration/compile.mjs",
|
|
51
|
+
"test:integration": "npm run update:subs && jest --config jest.integration.config.js && tsc test/integration/compile.test.ts && node test/integration/compile.mjs",
|
|
30
52
|
"test:perf": "npm run build:ecu && ts-node test/performance/benchmark-runner.ts --isolate --gc --cooldown-ms=80",
|
|
31
53
|
"check": "tsc --noEmit",
|
|
32
54
|
"check:circular-refs": "dependency-cruiser src",
|
|
@@ -77,7 +99,7 @@
|
|
|
77
99
|
"benchmark": "^2.1.4",
|
|
78
100
|
"binary-tree-typed": "^1.54.3",
|
|
79
101
|
"bst-typed": "^1.54.3",
|
|
80
|
-
"data-structure-typed": "^1.
|
|
102
|
+
"data-structure-typed": "^2.1.2",
|
|
81
103
|
"dependency-cruiser": "^16.5.0",
|
|
82
104
|
"doctoc": "^2.2.1",
|
|
83
105
|
"eslint": "^9.13.0",
|
|
@@ -12,10 +12,12 @@ import type {
|
|
|
12
12
|
BinaryTreeOptions,
|
|
13
13
|
BSTNOptKeyOrNode,
|
|
14
14
|
EntryCallback,
|
|
15
|
-
|
|
15
|
+
FamilyPosition,
|
|
16
|
+
IterationType,
|
|
17
|
+
RBTNColor
|
|
16
18
|
} from '../../types';
|
|
17
19
|
import { IBinaryTree } from '../../interfaces';
|
|
18
|
-
import { AVLTree
|
|
20
|
+
import { AVLTree } from './avl-tree';
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* AVL node with an extra 'count' field; keeps parent/child links.
|
|
@@ -23,8 +25,10 @@ import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
|
23
25
|
* @template K
|
|
24
26
|
* @template V
|
|
25
27
|
*/
|
|
26
|
-
export class AVLTreeCounterNode<K = any, V = any>
|
|
27
|
-
|
|
28
|
+
export class AVLTreeCounterNode<K = any, V = any> {
|
|
29
|
+
key: K;
|
|
30
|
+
value?: V;
|
|
31
|
+
parent?: AVLTreeCounterNode<K, V> = undefined;
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Create an AVL counter node.
|
|
@@ -35,18 +39,19 @@ export class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
|
35
39
|
* @returns New AVLTreeCounterNode instance.
|
|
36
40
|
*/
|
|
37
41
|
constructor(key: K, value?: V, count = 1) {
|
|
38
|
-
|
|
42
|
+
this.key = key;
|
|
43
|
+
this.value = value;
|
|
39
44
|
this.count = count;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
_left?: AVLTreeCounterNode<K, V> | null | undefined = undefined;
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
50
|
* Get the left child pointer.
|
|
46
51
|
* @remarks Time O(1), Space O(1)
|
|
47
52
|
* @returns Left child node, or null/undefined.
|
|
48
53
|
*/
|
|
49
|
-
|
|
54
|
+
get left(): AVLTreeCounterNode<K, V> | null | undefined {
|
|
50
55
|
return this._left;
|
|
51
56
|
}
|
|
52
57
|
|
|
@@ -56,21 +61,21 @@ export class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
|
56
61
|
* @param v - New left child node, or null/undefined.
|
|
57
62
|
* @returns void
|
|
58
63
|
*/
|
|
59
|
-
|
|
64
|
+
set left(v: AVLTreeCounterNode<K, V> | null | undefined) {
|
|
60
65
|
if (v) {
|
|
61
66
|
v.parent = this;
|
|
62
67
|
}
|
|
63
68
|
this._left = v;
|
|
64
69
|
}
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
_right?: AVLTreeCounterNode<K, V> | null | undefined = undefined;
|
|
67
72
|
|
|
68
73
|
/**
|
|
69
74
|
* Get the right child pointer.
|
|
70
75
|
* @remarks Time O(1), Space O(1)
|
|
71
76
|
* @returns Right child node, or null/undefined.
|
|
72
77
|
*/
|
|
73
|
-
|
|
78
|
+
get right(): AVLTreeCounterNode<K, V> | null | undefined {
|
|
74
79
|
return this._right;
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -80,12 +85,98 @@ export class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
|
80
85
|
* @param v - New right child node, or null/undefined.
|
|
81
86
|
* @returns void
|
|
82
87
|
*/
|
|
83
|
-
|
|
88
|
+
set right(v: AVLTreeCounterNode<K, V> | null | undefined) {
|
|
84
89
|
if (v) {
|
|
85
90
|
v.parent = this;
|
|
86
91
|
}
|
|
87
92
|
this._right = v;
|
|
88
93
|
}
|
|
94
|
+
|
|
95
|
+
_height: number = 0;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
99
|
+
* @remarks Time O(1), Space O(1)
|
|
100
|
+
*
|
|
101
|
+
* @returns The height.
|
|
102
|
+
*/
|
|
103
|
+
get height(): number {
|
|
104
|
+
return this._height;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sets the height of the node.
|
|
109
|
+
* @remarks Time O(1), Space O(1)
|
|
110
|
+
*
|
|
111
|
+
* @param value - The new height.
|
|
112
|
+
*/
|
|
113
|
+
set height(value: number) {
|
|
114
|
+
this._height = value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_color: RBTNColor = 'BLACK';
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
121
|
+
* @remarks Time O(1), Space O(1)
|
|
122
|
+
*
|
|
123
|
+
* @returns The node's color.
|
|
124
|
+
*/
|
|
125
|
+
get color(): RBTNColor {
|
|
126
|
+
return this._color;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Sets the color of the node.
|
|
131
|
+
* @remarks Time O(1), Space O(1)
|
|
132
|
+
*
|
|
133
|
+
* @param value - The new color.
|
|
134
|
+
*/
|
|
135
|
+
set color(value: RBTNColor) {
|
|
136
|
+
this._color = value;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_count: number = 1;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
143
|
+
* @remarks Time O(1), Space O(1)
|
|
144
|
+
*
|
|
145
|
+
* @returns The subtree node count.
|
|
146
|
+
*/
|
|
147
|
+
get count(): number {
|
|
148
|
+
return this._count;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Sets the count of nodes in the subtree.
|
|
153
|
+
* @remarks Time O(1), Space O(1)
|
|
154
|
+
*
|
|
155
|
+
* @param value - The new count.
|
|
156
|
+
*/
|
|
157
|
+
set count(value: number) {
|
|
158
|
+
this._count = value;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Gets the position of the node relative to its parent.
|
|
163
|
+
* @remarks Time O(1), Space O(1)
|
|
164
|
+
*
|
|
165
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
166
|
+
*/
|
|
167
|
+
get familyPosition(): FamilyPosition {
|
|
168
|
+
if (!this.parent) {
|
|
169
|
+
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (this.parent.left === this) {
|
|
173
|
+
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
174
|
+
} else if (this.parent.right === this) {
|
|
175
|
+
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return 'MAL_NODE';
|
|
179
|
+
}
|
|
89
180
|
}
|
|
90
181
|
|
|
91
182
|
/**
|
|
@@ -130,7 +221,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
130
221
|
return sum;
|
|
131
222
|
}
|
|
132
223
|
|
|
133
|
-
override
|
|
224
|
+
override createNode(key: K, value?: V, count?: number): AVLTreeCounterNode<K, V> {
|
|
134
225
|
return new AVLTreeCounterNode(key, this._isMapMode ? undefined : value, count) as AVLTreeCounterNode<K, V>;
|
|
135
226
|
}
|
|
136
227
|
|
|
@@ -391,10 +482,10 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
391
482
|
const [key, entryValue] = keyNodeOrEntry;
|
|
392
483
|
if (key === undefined || key === null) return [undefined, undefined];
|
|
393
484
|
const finalValue = value ?? entryValue;
|
|
394
|
-
return [this.
|
|
485
|
+
return [this.createNode(key, finalValue, count), finalValue];
|
|
395
486
|
}
|
|
396
487
|
|
|
397
|
-
return [this.
|
|
488
|
+
return [this.createNode(keyNodeOrEntry, value, count), value];
|
|
398
489
|
}
|
|
399
490
|
|
|
400
491
|
/**
|
|
@@ -412,7 +503,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
412
503
|
destNode = this.ensureNode(destNode);
|
|
413
504
|
if (srcNode && destNode) {
|
|
414
505
|
const { key, value, count, height } = destNode;
|
|
415
|
-
const tempNode = this.
|
|
506
|
+
const tempNode = this.createNode(key, value, count);
|
|
416
507
|
if (tempNode) {
|
|
417
508
|
tempNode.height = height;
|
|
418
509
|
|
|
@@ -12,7 +12,9 @@ import type {
|
|
|
12
12
|
BTNOptKeyOrNull,
|
|
13
13
|
ElemOf,
|
|
14
14
|
EntryCallback,
|
|
15
|
-
|
|
15
|
+
FamilyPosition,
|
|
16
|
+
IterationType,
|
|
17
|
+
RBTNColor
|
|
16
18
|
} from '../../types';
|
|
17
19
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
18
20
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -23,8 +25,10 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
23
25
|
* @template K
|
|
24
26
|
* @template V
|
|
25
27
|
*/
|
|
26
|
-
export class AVLTreeMultiMapNode<K = any, V = any>
|
|
27
|
-
|
|
28
|
+
export class AVLTreeMultiMapNode<K = any, V = any> {
|
|
29
|
+
key: K;
|
|
30
|
+
value?: V[];
|
|
31
|
+
parent?: AVLTreeMultiMapNode<K, V> = undefined;
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Create an AVLTreeMultiMap node with a value bucket.
|
|
@@ -33,18 +37,19 @@ export class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K, V[]> {
|
|
|
33
37
|
* @param value - Initial array of values.
|
|
34
38
|
* @returns New AVLTreeMultiMapNode instance.
|
|
35
39
|
*/
|
|
36
|
-
constructor(key: K, value: V[]) {
|
|
37
|
-
|
|
40
|
+
constructor(key: K, value: V[] = []) {
|
|
41
|
+
this.key = key;
|
|
42
|
+
this.value = value;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
_left?: AVLTreeMultiMapNode<K, V> | null | undefined = undefined;
|
|
41
46
|
|
|
42
47
|
/**
|
|
43
48
|
* Get the left child pointer.
|
|
44
49
|
* @remarks Time O(1), Space O(1)
|
|
45
50
|
* @returns Left child node, or null/undefined.
|
|
46
51
|
*/
|
|
47
|
-
|
|
52
|
+
get left(): AVLTreeMultiMapNode<K, V> | null | undefined {
|
|
48
53
|
return this._left;
|
|
49
54
|
}
|
|
50
55
|
|
|
@@ -54,21 +59,21 @@ export class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K, V[]> {
|
|
|
54
59
|
* @param v - New left child node, or null/undefined.
|
|
55
60
|
* @returns void
|
|
56
61
|
*/
|
|
57
|
-
|
|
62
|
+
set left(v: AVLTreeMultiMapNode<K, V> | null | undefined) {
|
|
58
63
|
if (v) {
|
|
59
64
|
v.parent = this;
|
|
60
65
|
}
|
|
61
66
|
this._left = v;
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
_right?: AVLTreeMultiMapNode<K, V> | null | undefined = undefined;
|
|
65
70
|
|
|
66
71
|
/**
|
|
67
72
|
* Get the right child pointer.
|
|
68
73
|
* @remarks Time O(1), Space O(1)
|
|
69
74
|
* @returns Right child node, or null/undefined.
|
|
70
75
|
*/
|
|
71
|
-
|
|
76
|
+
get right(): AVLTreeMultiMapNode<K, V> | null | undefined {
|
|
72
77
|
return this._right;
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -78,12 +83,98 @@ export class AVLTreeMultiMapNode<K = any, V = any> extends AVLTreeNode<K, V[]> {
|
|
|
78
83
|
* @param v - New right child node, or null/undefined.
|
|
79
84
|
* @returns void
|
|
80
85
|
*/
|
|
81
|
-
|
|
86
|
+
set right(v: AVLTreeMultiMapNode<K, V> | null | undefined) {
|
|
82
87
|
if (v) {
|
|
83
88
|
v.parent = this;
|
|
84
89
|
}
|
|
85
90
|
this._right = v;
|
|
86
91
|
}
|
|
92
|
+
|
|
93
|
+
_height: number = 0;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
97
|
+
* @remarks Time O(1), Space O(1)
|
|
98
|
+
*
|
|
99
|
+
* @returns The height.
|
|
100
|
+
*/
|
|
101
|
+
get height(): number {
|
|
102
|
+
return this._height;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Sets the height of the node.
|
|
107
|
+
* @remarks Time O(1), Space O(1)
|
|
108
|
+
*
|
|
109
|
+
* @param value - The new height.
|
|
110
|
+
*/
|
|
111
|
+
set height(value: number) {
|
|
112
|
+
this._height = value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
_color: RBTNColor = 'BLACK';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
119
|
+
* @remarks Time O(1), Space O(1)
|
|
120
|
+
*
|
|
121
|
+
* @returns The node's color.
|
|
122
|
+
*/
|
|
123
|
+
get color(): RBTNColor {
|
|
124
|
+
return this._color;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sets the color of the node.
|
|
129
|
+
* @remarks Time O(1), Space O(1)
|
|
130
|
+
*
|
|
131
|
+
* @param value - The new color.
|
|
132
|
+
*/
|
|
133
|
+
set color(value: RBTNColor) {
|
|
134
|
+
this._color = value;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_count: number = 1;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
141
|
+
* @remarks Time O(1), Space O(1)
|
|
142
|
+
*
|
|
143
|
+
* @returns The subtree node count.
|
|
144
|
+
*/
|
|
145
|
+
get count(): number {
|
|
146
|
+
return this._count;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Sets the count of nodes in the subtree.
|
|
151
|
+
* @remarks Time O(1), Space O(1)
|
|
152
|
+
*
|
|
153
|
+
* @param value - The new count.
|
|
154
|
+
*/
|
|
155
|
+
set count(value: number) {
|
|
156
|
+
this._count = value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gets the position of the node relative to its parent.
|
|
161
|
+
* @remarks Time O(1), Space O(1)
|
|
162
|
+
*
|
|
163
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
164
|
+
*/
|
|
165
|
+
get familyPosition(): FamilyPosition {
|
|
166
|
+
if (!this.parent) {
|
|
167
|
+
return this.left || this.right ? 'ROOT' : 'ISOLATED';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (this.parent.left === this) {
|
|
171
|
+
return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
|
|
172
|
+
} else if (this.parent.right === this) {
|
|
173
|
+
return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return 'MAL_NODE';
|
|
177
|
+
}
|
|
87
178
|
}
|
|
88
179
|
|
|
89
180
|
/**
|
|
@@ -113,10 +204,23 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
113
204
|
}
|
|
114
205
|
}
|
|
115
206
|
|
|
116
|
-
override
|
|
207
|
+
override createNode(key: K, value: V[] = []): AVLTreeMultiMapNode<K, V> {
|
|
117
208
|
return new AVLTreeMultiMapNode<K, V>(key, this._isMapMode ? [] : value);
|
|
118
209
|
}
|
|
119
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Checks if the given item is a `AVLTreeMultiMapNode` instance.
|
|
213
|
+
* @remarks Time O(1), Space O(1)
|
|
214
|
+
*
|
|
215
|
+
* @param keyNodeOrEntry - The item to check.
|
|
216
|
+
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
217
|
+
*/
|
|
218
|
+
override isNode(
|
|
219
|
+
keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
220
|
+
): keyNodeOrEntry is AVLTreeMultiMapNode<K, V> {
|
|
221
|
+
return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
222
|
+
}
|
|
223
|
+
|
|
120
224
|
override add(
|
|
121
225
|
keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
122
226
|
): boolean;
|