avl-tree-typed 2.1.0 → 2.1.2
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/cjs/index.cjs +3859 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +3852 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +15 -3
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/avl-tree-typed.js +3852 -0
- package/dist/umd/avl-tree-typed.js.map +1 -0
- package/dist/umd/avl-tree-typed.min.js +13 -0
- package/dist/umd/avl-tree-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
- package/src/data-structures/binary-tree/avl-tree.ts +6 -8
- package/src/data-structures/binary-tree/binary-tree.ts +13 -15
- package/src/data-structures/binary-tree/bst.ts +6 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
- package/src/data-structures/binary-tree/tree-counter.ts +8 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
- 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 +3 -3
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -31
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -23
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./binary-tree"), exports);
|
|
18
|
-
__exportStar(require("./bst"), exports);
|
|
19
|
-
__exportStar(require("./binary-indexed-tree"), exports);
|
|
20
|
-
__exportStar(require("./segment-tree"), exports);
|
|
21
|
-
__exportStar(require("./avl-tree"), exports);
|
|
22
|
-
__exportStar(require("./red-black-tree"), exports);
|
|
23
|
-
__exportStar(require("./avl-tree-multi-map"), exports);
|
|
24
|
-
__exportStar(require("./tree-multi-map"), exports);
|
|
25
|
-
__exportStar(require("./tree-counter"), exports);
|
|
26
|
-
__exportStar(require("./avl-tree-counter"), exports);
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Pablo Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BinaryTreeOptions, CRUD, EntryCallback, RBTNColor, RedBlackTreeOptions } from '../../types';
|
|
9
|
-
import { BST, BSTNode } from './bst';
|
|
10
|
-
import { IBinaryTree } from '../../interfaces';
|
|
11
|
-
export declare class RedBlackTreeNode<K = any, V = any> extends BSTNode<K, V> {
|
|
12
|
-
parent?: RedBlackTreeNode<K, V>;
|
|
13
|
-
/**
|
|
14
|
-
* Create a Red-Black Tree and optionally bulk-insert items.
|
|
15
|
-
* @remarks Time O(n log n), Space O(n)
|
|
16
|
-
* @param key - See parameter type for details.
|
|
17
|
-
* @param [value]- See parameter type for details.
|
|
18
|
-
* @param color - See parameter type for details.
|
|
19
|
-
* @returns New RedBlackTree instance.
|
|
20
|
-
*/
|
|
21
|
-
constructor(key: K, value?: V, color?: RBTNColor);
|
|
22
|
-
_left?: RedBlackTreeNode<K, V> | null | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Get the left child pointer.
|
|
25
|
-
* @remarks Time O(1), Space O(1)
|
|
26
|
-
* @returns Left child node, or null/undefined.
|
|
27
|
-
*/
|
|
28
|
-
get left(): RedBlackTreeNode<K, V> | null | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Set the left child and update its parent pointer.
|
|
31
|
-
* @remarks Time O(1), Space O(1)
|
|
32
|
-
* @param v - New left node, or null/undefined.
|
|
33
|
-
* @returns void
|
|
34
|
-
*/
|
|
35
|
-
set left(v: RedBlackTreeNode<K, V> | null | undefined);
|
|
36
|
-
_right?: RedBlackTreeNode<K, V> | null | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Get the right child pointer.
|
|
39
|
-
* @remarks Time O(1), Space O(1)
|
|
40
|
-
* @returns Right child node, or null/undefined.
|
|
41
|
-
*/
|
|
42
|
-
get right(): RedBlackTreeNode<K, V> | null | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Set the right child and update its parent pointer.
|
|
45
|
-
* @remarks Time O(1), Space O(1)
|
|
46
|
-
* @param v - New right node, or null/undefined.
|
|
47
|
-
* @returns void
|
|
48
|
-
*/
|
|
49
|
-
set right(v: RedBlackTreeNode<K, V> | null | undefined);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* RRRRed-Black Tree (self-balancing BST) supporting map-like mode and stable O(log n) updates.
|
|
53
|
-
* @remarks Time O(1), Space O(1)
|
|
54
|
-
* @template K
|
|
55
|
-
* @template V
|
|
56
|
-
* @template R
|
|
57
|
-
* 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high but the query efficiency is slightly lower.
|
|
58
|
-
* 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
|
|
59
|
-
* @example
|
|
60
|
-
* // using Red-Black Tree as a price-based index for stock data
|
|
61
|
-
* // Define the structure of individual stock records
|
|
62
|
-
* interface StockRecord {
|
|
63
|
-
* price: number; // Stock price (key for indexing)
|
|
64
|
-
* symbol: string; // Stock ticker symbol
|
|
65
|
-
* volume: number; // Trade volume
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* // Simulate stock market data as it might come from an external feed
|
|
69
|
-
* const marketStockData: StockRecord[] = [
|
|
70
|
-
* { price: 142.5, symbol: 'AAPL', volume: 1000000 },
|
|
71
|
-
* { price: 335.2, symbol: 'MSFT', volume: 800000 },
|
|
72
|
-
* { price: 3285.04, symbol: 'AMZN', volume: 500000 },
|
|
73
|
-
* { price: 267.98, symbol: 'META', volume: 750000 },
|
|
74
|
-
* { price: 234.57, symbol: 'GOOGL', volume: 900000 }
|
|
75
|
-
* ];
|
|
76
|
-
*
|
|
77
|
-
* // Extend the stock record type to include metadata for database usage
|
|
78
|
-
* type StockTableRecord = StockRecord & { lastUpdated: Date };
|
|
79
|
-
*
|
|
80
|
-
* // Create a Red-Black Tree to index stock records by price
|
|
81
|
-
* // Simulates a database index with stock price as the key for quick lookups
|
|
82
|
-
* const priceIndex = new RedBlackTree<number, StockTableRecord, StockRecord>(marketStockData, {
|
|
83
|
-
* toEntryFn: stockRecord => [
|
|
84
|
-
* stockRecord.price, // Use stock price as the key
|
|
85
|
-
* {
|
|
86
|
-
* ...stockRecord,
|
|
87
|
-
* lastUpdated: new Date() // Add a timestamp for when the record was indexed
|
|
88
|
-
* }
|
|
89
|
-
* ]
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* // Query the stock with the highest price
|
|
93
|
-
* const highestPricedStock = priceIndex.getRightMost();
|
|
94
|
-
* console.log(priceIndex.get(highestPricedStock)?.symbol); // 'AMZN' // Amazon has the highest price
|
|
95
|
-
*
|
|
96
|
-
* // Query stocks within a specific price range (200 to 400)
|
|
97
|
-
* const stocksInRange = priceIndex.rangeSearch(
|
|
98
|
-
* [200, 400], // Price range
|
|
99
|
-
* node => priceIndex.get(node)?.symbol // Extract stock symbols for the result
|
|
100
|
-
* );
|
|
101
|
-
* console.log(stocksInRange); // ['GOOGL', 'META', 'MSFT']
|
|
102
|
-
*/
|
|
103
|
-
export declare class RedBlackTree<K = any, V = any, R extends object = object> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
|
|
104
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: RedBlackTreeOptions<K, V, R>);
|
|
105
|
-
protected _root: RedBlackTreeNode<K, V> | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* Get the current root node.
|
|
108
|
-
* @remarks Time O(1), Space O(1)
|
|
109
|
-
* @returns Root node, or undefined.
|
|
110
|
-
*/
|
|
111
|
-
get root(): RedBlackTreeNode<K, V> | undefined;
|
|
112
|
-
/**
|
|
113
|
-
* Create a red-black node for the given key/value (value ignored in map mode).
|
|
114
|
-
* @remarks Time O(1), Space O(1)
|
|
115
|
-
* @param key - See parameter type for details.
|
|
116
|
-
* @param [value] - See parameter type for details.
|
|
117
|
-
* @param color - See parameter type for details.
|
|
118
|
-
* @returns A new RedBlackTreeNode instance.
|
|
119
|
-
*/
|
|
120
|
-
_createNode(key: K, value?: V, color?: RBTNColor): RedBlackTreeNode<K, V>;
|
|
121
|
-
/**
|
|
122
|
-
* Type guard: check whether the input is a RedBlackTreeNode.
|
|
123
|
-
* @remarks Time O(1), Space O(1)
|
|
124
|
-
* @param keyNodeOrEntry - See parameter type for details.
|
|
125
|
-
* @returns True if the value is a RedBlackTreeNode.
|
|
126
|
-
*/
|
|
127
|
-
isNode(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is RedBlackTreeNode<K, V>;
|
|
128
|
-
/**
|
|
129
|
-
* Remove all nodes and clear the key→value store (if in map mode).
|
|
130
|
-
* @remarks Time O(n), Space O(1)
|
|
131
|
-
* @returns void
|
|
132
|
-
*/
|
|
133
|
-
clear(): void;
|
|
134
|
-
/**
|
|
135
|
-
* Insert or replace an entry using BST order and red-black fix-up.
|
|
136
|
-
* @remarks Time O(log n), Space O(1)
|
|
137
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
|
|
138
|
-
* @param [value]- See parameter type for details.
|
|
139
|
-
* @returns True if inserted or updated; false if ignored.
|
|
140
|
-
*/
|
|
141
|
-
add(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Delete a node by key/node/entry and rebalance as needed.
|
|
144
|
-
* @remarks Time O(log n), Space O(1)
|
|
145
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node to delete.
|
|
146
|
-
* @returns Array with deletion metadata (removed node, rebalancing hint if any).
|
|
147
|
-
*/
|
|
148
|
-
delete(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[];
|
|
149
|
-
/**
|
|
150
|
-
* Transform entries into a like-kind red-black tree with possibly different key/value types.
|
|
151
|
-
* @remarks Time O(n), Space O(n)
|
|
152
|
-
* @template MK
|
|
153
|
-
* @template MV
|
|
154
|
-
* @template MR
|
|
155
|
-
* @param callback - Mapping function from (key, value, index, tree) to a new [key, value].
|
|
156
|
-
* @param [options] - See parameter type for details.
|
|
157
|
-
* @param [thisArg] - See parameter type for details.
|
|
158
|
-
* @returns A new RedBlackTree with mapped entries.
|
|
159
|
-
*/
|
|
160
|
-
map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): RedBlackTree<MK, MV, MR>;
|
|
161
|
-
protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): this;
|
|
162
|
-
protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | RedBlackTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): RedBlackTree<TK, TV, TR>;
|
|
163
|
-
protected _setRoot(v: RedBlackTreeNode<K, V> | undefined): void;
|
|
164
|
-
protected _replaceNode(oldNode: RedBlackTreeNode<K, V>, newNode: RedBlackTreeNode<K, V>): RedBlackTreeNode<K, V>;
|
|
165
|
-
/**
|
|
166
|
-
* (Protected) Standard BST insert followed by red-black fix-up.
|
|
167
|
-
* @remarks Time O(log n), Space O(1)
|
|
168
|
-
* @param node - Node to insert.
|
|
169
|
-
* @returns Status string: 'CREATED' or 'UPDATED'.
|
|
170
|
-
*/
|
|
171
|
-
protected _insert(node: RedBlackTreeNode<K, V>): CRUD;
|
|
172
|
-
/**
|
|
173
|
-
* (Protected) Transplant a subtree in place of another during deletion.
|
|
174
|
-
* @remarks Time O(1), Space O(1)
|
|
175
|
-
* @param u - Node to replace.
|
|
176
|
-
* @param v - Replacement subtree root (may be undefined).
|
|
177
|
-
* @returns void
|
|
178
|
-
*/
|
|
179
|
-
protected _transplant(u: RedBlackTreeNode<K, V>, v: RedBlackTreeNode<K, V> | undefined): void;
|
|
180
|
-
/**
|
|
181
|
-
* (Protected) Restore red-black properties after insertion (recolor/rotate).
|
|
182
|
-
* @remarks Time O(log n), Space O(1)
|
|
183
|
-
* @param z - Recently inserted node.
|
|
184
|
-
* @returns void
|
|
185
|
-
*/
|
|
186
|
-
protected _insertFixup(z: RedBlackTreeNode<K, V> | undefined): void;
|
|
187
|
-
/**
|
|
188
|
-
* (Protected) Restore red-black properties after deletion (recolor/rotate).
|
|
189
|
-
* @remarks Time O(log n), Space O(1)
|
|
190
|
-
* @param node - Child that replaced the deleted node (may be undefined).
|
|
191
|
-
* @returns void
|
|
192
|
-
*/
|
|
193
|
-
protected _deleteFixup(node: RedBlackTreeNode<K, V> | undefined): void;
|
|
194
|
-
/**
|
|
195
|
-
* (Protected) Perform a left rotation around x.
|
|
196
|
-
* @remarks Time O(1), Space O(1)
|
|
197
|
-
* @param x - Pivot node to rotate around.
|
|
198
|
-
* @returns void
|
|
199
|
-
*/
|
|
200
|
-
protected _leftRotate(x: RedBlackTreeNode<K, V> | undefined): void;
|
|
201
|
-
/**
|
|
202
|
-
* (Protected) Perform a right rotation around y.
|
|
203
|
-
* @remarks Time O(1), Space O(1)
|
|
204
|
-
* @param y - Pivot node to rotate around.
|
|
205
|
-
* @returns void
|
|
206
|
-
*/
|
|
207
|
-
protected _rightRotate(y: RedBlackTreeNode<K, V> | undefined): void;
|
|
208
|
-
}
|