data-structure-typed 0.8.17 → 0.9.16
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/.idea/modules.xml +1 -1
- package/README.md +197 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +1 -5
- package/dist/data-structures/binary-tree/avl-tree.js +93 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +14 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +20 -32
- package/dist/data-structures/binary-tree/binary-tree.js +480 -370
- package/dist/data-structures/binary-tree/bst.d.ts +4 -8
- package/dist/data-structures/binary-tree/bst.js +152 -107
- package/dist/data-structures/binary-tree/index.d.ts +7 -0
- package/dist/data-structures/binary-tree/index.js +7 -0
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +3 -3
- package/dist/data-structures/binary-tree/segment-tree.js +91 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +31 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +5 -33
- package/dist/data-structures/graph/abstract-graph.js +546 -311
- package/dist/data-structures/graph/directed-graph.d.ts +5 -13
- package/dist/data-structures/graph/directed-graph.js +250 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +4 -3
- package/dist/data-structures/graph/undirected-graph.js +166 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +1 -1
- package/dist/data-structures/hash/coordinate-map.js +38 -20
- package/dist/data-structures/hash/coordinate-set.js +33 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +2 -8
- package/dist/data-structures/heap/heap.js +36 -31
- package/dist/data-structures/heap/max-heap.d.ts +3 -2
- package/dist/data-structures/heap/max-heap.js +27 -9
- package/dist/data-structures/heap/min-heap.d.ts +3 -2
- package/dist/data-structures/heap/min-heap.js +27 -9
- package/dist/data-structures/index.d.ts +2 -0
- package/dist/data-structures/index.js +2 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +56 -53
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +8 -12
- package/dist/data-structures/linked-list/singly-linked-list.js +308 -174
- package/dist/data-structures/matrix/matrix.js +8 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +5 -5
- package/dist/data-structures/matrix/matrix2d.js +80 -63
- package/dist/data-structures/matrix/navigator.d.ts +2 -16
- package/dist/data-structures/matrix/navigator.js +37 -18
- package/dist/data-structures/matrix/vector2d.d.ts +18 -18
- package/dist/data-structures/matrix/vector2d.js +117 -94
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +3 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +25 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -21
- package/dist/data-structures/priority-queue/priority-queue.js +159 -116
- package/dist/data-structures/queue/deque.js +82 -56
- package/dist/data-structures/queue/index.d.ts +1 -0
- package/dist/data-structures/queue/index.js +1 -0
- package/dist/data-structures/queue/queue.d.ts +9 -10
- package/dist/data-structures/queue/queue.js +34 -34
- package/dist/data-structures/stack/stack.d.ts +9 -10
- package/dist/data-structures/stack/stack.js +31 -31
- package/dist/data-structures/trampoline.d.ts +14 -23
- package/dist/data-structures/trampoline.js +103 -25
- package/dist/data-structures/trie/trie.d.ts +13 -3
- package/dist/data-structures/trie/trie.js +234 -80
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.d.ts +5 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/{types → data-structures/types}/utils.d.ts +7 -1
- package/dist/{types → data-structures/types}/utils.js +20 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +6 -23
- package/dist/utils/utils.js +651 -0
- package/package.json +20 -42
- package/src/data-structures/binary-tree/avl-tree.ts +1 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +4 -4
- package/src/data-structures/binary-tree/binary-tree.ts +184 -139
- package/src/data-structures/binary-tree/bst.ts +15 -24
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/index.ts +7 -0
- package/src/data-structures/binary-tree/segment-tree.ts +20 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +1 -4
- package/src/data-structures/diagrams/README.md +7 -0
- package/src/data-structures/graph/abstract-graph.ts +58 -94
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.png +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.png +0 -0
- package/src/data-structures/graph/diagrams/edge-list.png +0 -0
- package/src/data-structures/graph/diagrams/max-flow.png +0 -0
- package/src/data-structures/graph/diagrams/mst.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/directed-graph.ts +12 -28
- package/src/data-structures/graph/undirected-graph.ts +11 -10
- package/src/data-structures/hash/coordinate-map.ts +1 -1
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +2 -11
- package/src/data-structures/heap/max-heap.ts +3 -2
- package/src/data-structures/heap/min-heap.ts +3 -2
- package/src/data-structures/index.ts +2 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +18 -32
- package/src/data-structures/matrix/matrix2d.ts +11 -11
- package/src/data-structures/matrix/navigator.ts +2 -14
- package/src/data-structures/matrix/vector2d.ts +52 -52
- package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +4 -3
- package/src/data-structures/priority-queue/priority-queue.ts +70 -78
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/index.ts +1 -0
- package/src/data-structures/queue/queue.ts +12 -13
- package/src/data-structures/stack/stack.ts +12 -13
- package/src/data-structures/trampoline.ts +31 -71
- package/src/data-structures/trie/trie.ts +61 -11
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +12 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +15 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/{types → data-structures/types}/utils.ts +20 -5
- package/src/utils/index.ts +1 -0
- package/src/{utils.ts → utils/utils.ts} +32 -132
- package/tsconfig.json +9 -6
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/index.d.ts +0 -3
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/types/index.d.ts +0 -1
- package/dist/types/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/types/index.ts +0 -1
- package/src/types/patches/index.d.ts +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.16",
|
|
4
4
|
"description": "Hash (CoordinateSet, CoordinateMap) Heap (MaxHeap, MinHeap) Binary Tree (AVL Tree, Binary Indexed Tree, Binary Search Tree, Segment Tree, Tree Multiset) Graph (Directed Graph, Undirected Graph) Linked List (Singly Linked List, Doubly Linked List) Matrix Priority Queue (Max Priority Queue, Min Priority Queue) Queue (Queue, Dequeue) Stack Trie",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"build": "rm -rf dist && npx tsc",
|
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
@@ -11,51 +12,27 @@
|
|
|
11
12
|
"url": "git+https://github.com/zrwusa/data-structure-typed.git"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
15
|
+
"Binary Tree",
|
|
16
|
+
"AVL Tree",
|
|
17
|
+
"Binary Search Tree (BST)",
|
|
18
|
+
"Tree Multiset",
|
|
19
|
+
"Segment Tree",
|
|
20
|
+
"Binary Indexed Tree",
|
|
21
|
+
"Graph",
|
|
22
|
+
"Directed Graph",
|
|
23
|
+
"Undirected Graph",
|
|
24
|
+
"Singly Linked List",
|
|
14
25
|
"Hash",
|
|
15
26
|
"CoordinateSet",
|
|
16
27
|
"CoordinateMap",
|
|
17
28
|
"Heap",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"AVL",
|
|
23
|
-
"Tree",
|
|
24
|
-
"Binary",
|
|
25
|
-
"Indexed",
|
|
26
|
-
"Tree",
|
|
27
|
-
"Binary",
|
|
28
|
-
"Search",
|
|
29
|
-
"Tree",
|
|
30
|
-
"Segment",
|
|
31
|
-
"Tree",
|
|
32
|
-
"Tree",
|
|
33
|
-
"Multiset",
|
|
34
|
-
"Graph",
|
|
35
|
-
"Directed",
|
|
36
|
-
"Graph",
|
|
37
|
-
"Undirected",
|
|
38
|
-
"Graph",
|
|
39
|
-
"Linked",
|
|
40
|
-
"List",
|
|
41
|
-
"Singly",
|
|
42
|
-
"Linked",
|
|
43
|
-
"List",
|
|
44
|
-
"Doubly",
|
|
45
|
-
"Linked",
|
|
46
|
-
"List",
|
|
47
|
-
"Matrix",
|
|
48
|
-
"Priority",
|
|
49
|
-
"Queue",
|
|
50
|
-
"Max",
|
|
51
|
-
"Priority",
|
|
52
|
-
"Queue",
|
|
53
|
-
"Min",
|
|
54
|
-
"Priority",
|
|
55
|
-
"Queue",
|
|
56
|
-
"Queue",
|
|
29
|
+
"Doubly Linked List",
|
|
30
|
+
"Priority Queue",
|
|
31
|
+
"Max Priority Queue",
|
|
32
|
+
"Min Priority Queue",
|
|
57
33
|
"Queue",
|
|
58
|
-
"
|
|
34
|
+
"ObjectDeque",
|
|
35
|
+
"ArrayDeque",
|
|
59
36
|
"Stack",
|
|
60
37
|
"Trie"
|
|
61
38
|
],
|
|
@@ -67,7 +44,8 @@
|
|
|
67
44
|
"homepage": "https://github.com/zrwusa/data-structure-typed#readme",
|
|
68
45
|
"types": "dist/index.d.ts",
|
|
69
46
|
"devDependencies": {
|
|
70
|
-
"@types/lodash": "^4.14.
|
|
47
|
+
"@types/lodash": "^4.14.197",
|
|
48
|
+
"@types/node": "^20.4.9",
|
|
71
49
|
"typescript": "^4.6.2"
|
|
72
50
|
},
|
|
73
51
|
"dependencies": {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import {BST, BSTNode} from './bst';
|
|
2
|
-
import {BinaryTreeNodeId} from '
|
|
3
|
-
|
|
4
|
-
export interface AVLTreeDeleted<T> {
|
|
5
|
-
deleted: AVLTreeNode<T> | null;
|
|
6
|
-
needBalanced: AVLTreeNode<T> | null;
|
|
7
|
-
}
|
|
2
|
+
import type {AVLTreeDeleted, BinaryTreeNodeId} from '../types';
|
|
8
3
|
|
|
9
4
|
export class AVLTreeNode<T> extends BSTNode<T> {
|
|
10
5
|
override clone(): AVLTreeNode<T> {
|
|
@@ -5,6 +5,10 @@ export class BinaryIndexedTree {
|
|
|
5
5
|
this._sumTree = new Array<number>(n + 1).fill(0);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
static lowBit(x: number) {
|
|
9
|
+
return x & (-x);
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
update(i: number, delta: number) {
|
|
9
13
|
while (i < this._sumTree.length) {
|
|
10
14
|
this._sumTree[i] += delta;
|
|
@@ -26,8 +30,4 @@ export class BinaryIndexedTree {
|
|
|
26
30
|
throw 'Index out of bounds';
|
|
27
31
|
return this.getPrefixSum(end) - this.getPrefixSum(start);
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
static lowBit(x: number) {
|
|
31
|
-
return x & (-x);
|
|
32
|
-
}
|
|
33
33
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type ResultsByProperty<T> = ResultByProperty<T>[];
|
|
10
|
-
|
|
11
|
-
export interface BinaryTreeNodeObj<T> {
|
|
12
|
-
id: BinaryTreeNodeId;
|
|
13
|
-
val: T;
|
|
14
|
-
count?: number;
|
|
15
|
-
}
|
|
1
|
+
import {trampoline} from '../trampoline';
|
|
2
|
+
import type {
|
|
3
|
+
BinaryTreeDeleted,
|
|
4
|
+
BinaryTreeNodeId,
|
|
5
|
+
BinaryTreeNodePropertyName, DFSOrderPattern,
|
|
6
|
+
NodeOrPropertyName, ResultByProperty,
|
|
7
|
+
ResultsByProperty
|
|
8
|
+
} from '../types';
|
|
16
9
|
|
|
17
10
|
export enum FamilyPosition {root, left, right}
|
|
18
11
|
|
|
19
12
|
export enum LoopType { iterative = 1, recursive = 2}
|
|
20
13
|
|
|
21
14
|
export class BinaryTreeNode<T> {
|
|
15
|
+
constructor(id: BinaryTreeNodeId, val: T, count?: number) {
|
|
16
|
+
this._id = id;
|
|
17
|
+
this._val = val;
|
|
18
|
+
this._count = count ?? 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
22
21
|
protected _id: BinaryTreeNodeId;
|
|
22
|
+
|
|
23
23
|
get id(): BinaryTreeNodeId {
|
|
24
24
|
return this._id;
|
|
25
25
|
}
|
|
@@ -29,6 +29,7 @@ export class BinaryTreeNode<T> {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
protected _val: T;
|
|
32
|
+
|
|
32
33
|
get val(): T {
|
|
33
34
|
return this._val;
|
|
34
35
|
}
|
|
@@ -38,6 +39,7 @@ export class BinaryTreeNode<T> {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
protected _left?: BinaryTreeNode<T> | null;
|
|
42
|
+
|
|
41
43
|
get left(): BinaryTreeNode<T> | null | undefined {
|
|
42
44
|
return this._left;
|
|
43
45
|
}
|
|
@@ -51,6 +53,7 @@ export class BinaryTreeNode<T> {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
protected _right?: BinaryTreeNode<T> | null;
|
|
56
|
+
|
|
54
57
|
get right(): BinaryTreeNode<T> | null | undefined {
|
|
55
58
|
return this._right;
|
|
56
59
|
}
|
|
@@ -63,7 +66,8 @@ export class BinaryTreeNode<T> {
|
|
|
63
66
|
this._right = v;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
protected _parent: BinaryTreeNode<T> | null | undefined
|
|
69
|
+
protected _parent: BinaryTreeNode<T> | null | undefined;
|
|
70
|
+
|
|
67
71
|
get parent(): BinaryTreeNode<T> | null | undefined {
|
|
68
72
|
return this._parent;
|
|
69
73
|
}
|
|
@@ -73,6 +77,7 @@ export class BinaryTreeNode<T> {
|
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
protected _familyPosition: FamilyPosition = FamilyPosition.root;
|
|
80
|
+
|
|
76
81
|
get familyPosition(): FamilyPosition {
|
|
77
82
|
return this._familyPosition;
|
|
78
83
|
}
|
|
@@ -82,6 +87,7 @@ export class BinaryTreeNode<T> {
|
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
protected _count = 1;
|
|
90
|
+
|
|
85
91
|
get count(): number {
|
|
86
92
|
return this._count;
|
|
87
93
|
}
|
|
@@ -100,12 +106,6 @@ export class BinaryTreeNode<T> {
|
|
|
100
106
|
this._height = v;
|
|
101
107
|
}
|
|
102
108
|
|
|
103
|
-
constructor(id: BinaryTreeNodeId, val: T, count?: number) {
|
|
104
|
-
this._id = id;
|
|
105
|
-
this._val = val;
|
|
106
|
-
this._count = count ?? 1;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
109
|
swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T> {
|
|
110
110
|
const {val, count, height} = swapNode;
|
|
111
111
|
const tempNode = new BinaryTreeNode<T>(swapNode.id, val);
|
|
@@ -131,8 +131,36 @@ export class BinaryTreeNode<T> {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
export class BinaryTree<T> {
|
|
134
|
+
protected _loopType: LoopType = LoopType.iterative;
|
|
135
|
+
protected _visitedId: BinaryTreeNodeId[] = [];
|
|
136
|
+
protected _visitedVal: Array<T> = [];
|
|
137
|
+
protected _visitedNode: BinaryTreeNode<T>[] = [];
|
|
138
|
+
protected _visitedCount: number[] = [];
|
|
139
|
+
protected _visitedLeftSum: number[] = [];
|
|
140
|
+
private readonly _autoIncrementId: boolean = false;
|
|
141
|
+
private _maxId: number = -1;
|
|
142
|
+
private readonly _isDuplicatedVal: boolean = false;
|
|
143
|
+
|
|
144
|
+
constructor(options?: {
|
|
145
|
+
loopType?: LoopType,
|
|
146
|
+
autoIncrementId?: boolean,
|
|
147
|
+
isDuplicatedVal?: boolean
|
|
148
|
+
}) {
|
|
149
|
+
if (options !== undefined) {
|
|
150
|
+
const {
|
|
151
|
+
loopType = LoopType.iterative,
|
|
152
|
+
autoIncrementId = false,
|
|
153
|
+
isDuplicatedVal = false
|
|
154
|
+
} = options;
|
|
155
|
+
this._isDuplicatedVal = isDuplicatedVal;
|
|
156
|
+
this._autoIncrementId = autoIncrementId;
|
|
157
|
+
this._loopType = loopType;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
134
161
|
protected _root: BinaryTreeNode<T> | null = null;
|
|
135
|
-
|
|
162
|
+
|
|
163
|
+
protected get root(): BinaryTreeNode<T> | null {
|
|
136
164
|
return this._root;
|
|
137
165
|
}
|
|
138
166
|
|
|
@@ -145,7 +173,8 @@ export class BinaryTree<T> {
|
|
|
145
173
|
}
|
|
146
174
|
|
|
147
175
|
protected _size = 0;
|
|
148
|
-
|
|
176
|
+
|
|
177
|
+
protected get size(): number {
|
|
149
178
|
return this._size;
|
|
150
179
|
}
|
|
151
180
|
|
|
@@ -154,7 +183,8 @@ export class BinaryTree<T> {
|
|
|
154
183
|
}
|
|
155
184
|
|
|
156
185
|
protected _count = 0;
|
|
157
|
-
|
|
186
|
+
|
|
187
|
+
protected get count(): number {
|
|
158
188
|
return this._count;
|
|
159
189
|
}
|
|
160
190
|
|
|
@@ -162,40 +192,8 @@ export class BinaryTree<T> {
|
|
|
162
192
|
this._count = v;
|
|
163
193
|
}
|
|
164
194
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
private readonly _isDuplicatedVal: boolean = false;
|
|
168
|
-
|
|
169
|
-
protected _loopType: LoopType = LoopType.iterative;
|
|
170
|
-
protected _visitedId: BinaryTreeNodeId[] = [];
|
|
171
|
-
protected _visitedVal: Array<T> = [];
|
|
172
|
-
protected _visitedNode: BinaryTreeNode<T>[] = [];
|
|
173
|
-
protected _visitedCount: number[] = [];
|
|
174
|
-
protected _visitedLeftSum: number[] = [];
|
|
175
|
-
|
|
176
|
-
protected _resetResults() {
|
|
177
|
-
this._visitedId = [];
|
|
178
|
-
this._visitedVal = [];
|
|
179
|
-
this._visitedNode = [];
|
|
180
|
-
this._visitedCount = [];
|
|
181
|
-
this._visitedLeftSum = [];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
constructor(options?: {
|
|
185
|
-
loopType?: LoopType,
|
|
186
|
-
autoIncrementId?: boolean,
|
|
187
|
-
isDuplicatedVal?: boolean
|
|
188
|
-
}) {
|
|
189
|
-
if (options !== undefined) {
|
|
190
|
-
const {
|
|
191
|
-
loopType = LoopType.iterative,
|
|
192
|
-
autoIncrementId = false,
|
|
193
|
-
isDuplicatedVal = false
|
|
194
|
-
} = options;
|
|
195
|
-
this._isDuplicatedVal = isDuplicatedVal;
|
|
196
|
-
this._autoIncrementId = autoIncrementId;
|
|
197
|
-
this._loopType = loopType;
|
|
198
|
-
}
|
|
195
|
+
getCount(): number {
|
|
196
|
+
return this._count;
|
|
199
197
|
}
|
|
200
198
|
|
|
201
199
|
createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null {
|
|
@@ -393,8 +391,8 @@ export class BinaryTree<T> {
|
|
|
393
391
|
return _getMaxHeight(beginRoot);
|
|
394
392
|
} else {
|
|
395
393
|
const stack: BinaryTreeNode<T>[] = [];
|
|
396
|
-
let node: BinaryTreeNode<T> | null | undefined = beginRoot, last: BinaryTreeNode<T> | null = null
|
|
397
|
-
|
|
394
|
+
let node: BinaryTreeNode<T> | null | undefined = beginRoot, last: BinaryTreeNode<T> | null = null;
|
|
395
|
+
const depths: Map<BinaryTreeNode<T>, number> = new Map();
|
|
398
396
|
|
|
399
397
|
while (stack.length > 0 || node) {
|
|
400
398
|
if (node) {
|
|
@@ -405,8 +403,8 @@ export class BinaryTree<T> {
|
|
|
405
403
|
if (!node.right || last === node.right) {
|
|
406
404
|
node = stack.pop();
|
|
407
405
|
if (node) {
|
|
408
|
-
|
|
409
|
-
|
|
406
|
+
const leftHeight = node.left ? depths.get(node.left) ?? -1 : -1;
|
|
407
|
+
const rightHeight = node.right ? depths.get(node.right) ?? -1 : -1;
|
|
410
408
|
depths.set(node, 1 + Math.max(leftHeight, rightHeight));
|
|
411
409
|
last = node;
|
|
412
410
|
node = null;
|
|
@@ -435,8 +433,8 @@ export class BinaryTree<T> {
|
|
|
435
433
|
return _getMinHeight(beginRoot);
|
|
436
434
|
} else {
|
|
437
435
|
const stack: BinaryTreeNode<T>[] = [];
|
|
438
|
-
let node: BinaryTreeNode<T> | null | undefined = beginRoot, last: BinaryTreeNode<T> | null = null
|
|
439
|
-
|
|
436
|
+
let node: BinaryTreeNode<T> | null | undefined = beginRoot, last: BinaryTreeNode<T> | null = null;
|
|
437
|
+
const depths: Map<BinaryTreeNode<T>, number> = new Map();
|
|
440
438
|
|
|
441
439
|
while (stack.length > 0 || node) {
|
|
442
440
|
if (node) {
|
|
@@ -447,8 +445,8 @@ export class BinaryTree<T> {
|
|
|
447
445
|
if (!node.right || last === node.right) {
|
|
448
446
|
node = stack.pop();
|
|
449
447
|
if (node) {
|
|
450
|
-
|
|
451
|
-
|
|
448
|
+
const leftMinHeight = node.left ? depths.get(node.left) ?? -1 : -1;
|
|
449
|
+
const rightMinHeight = node.right ? depths.get(node.right) ?? -1 : -1;
|
|
452
450
|
depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
|
|
453
451
|
last = node;
|
|
454
452
|
node = null;
|
|
@@ -514,76 +512,14 @@ export class BinaryTree<T> {
|
|
|
514
512
|
return result;
|
|
515
513
|
}
|
|
516
514
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
case 'id':
|
|
520
|
-
if (cur.id === nodeProperty) {
|
|
521
|
-
result.push(cur);
|
|
522
|
-
return !!onlyOne;
|
|
523
|
-
}
|
|
524
|
-
break;
|
|
525
|
-
case 'count':
|
|
526
|
-
if (cur.count === nodeProperty) {
|
|
527
|
-
result.push(cur);
|
|
528
|
-
return !!onlyOne;
|
|
529
|
-
}
|
|
530
|
-
break;
|
|
531
|
-
case 'val':
|
|
532
|
-
if (cur.val === nodeProperty) {
|
|
533
|
-
result.push(cur);
|
|
534
|
-
return !!onlyOne;
|
|
535
|
-
}
|
|
536
|
-
break;
|
|
537
|
-
default:
|
|
538
|
-
if (cur.id === nodeProperty) {
|
|
539
|
-
result.push(cur);
|
|
540
|
-
return !!onlyOne;
|
|
541
|
-
}
|
|
542
|
-
break;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName ?: NodeOrPropertyName) {
|
|
547
|
-
nodeOrPropertyName = nodeOrPropertyName ?? 'id';
|
|
548
|
-
|
|
549
|
-
switch (nodeOrPropertyName) {
|
|
550
|
-
case 'id':
|
|
551
|
-
this._visitedId.push(node.id);
|
|
552
|
-
break;
|
|
553
|
-
case 'val':
|
|
554
|
-
this._visitedVal.push(node.val);
|
|
555
|
-
break;
|
|
556
|
-
case 'node':
|
|
557
|
-
this._visitedNode.push(node);
|
|
558
|
-
break;
|
|
559
|
-
case 'count':
|
|
560
|
-
this._visitedCount.push(node.count);
|
|
561
|
-
break;
|
|
562
|
-
default:
|
|
563
|
-
this._visitedId.push(node.id);
|
|
564
|
-
break;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
protected _getResultByPropertyName(nodeOrPropertyName ?: NodeOrPropertyName): ResultsByProperty<T> {
|
|
569
|
-
nodeOrPropertyName = nodeOrPropertyName ?? 'id';
|
|
570
|
-
|
|
571
|
-
switch (nodeOrPropertyName) {
|
|
572
|
-
case 'id':
|
|
573
|
-
return this._visitedId;
|
|
574
|
-
case 'val':
|
|
575
|
-
return this._visitedVal;
|
|
576
|
-
case 'node':
|
|
577
|
-
return this._visitedNode;
|
|
578
|
-
case 'count':
|
|
579
|
-
return this._visitedCount;
|
|
580
|
-
default:
|
|
581
|
-
return this._visitedId;
|
|
582
|
-
}
|
|
515
|
+
getRoot(): BinaryTreeNode<T> | null {
|
|
516
|
+
return this.root;
|
|
583
517
|
}
|
|
584
518
|
|
|
585
519
|
getLeftMost(): BinaryTreeNode<T> | null;
|
|
520
|
+
|
|
586
521
|
getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
|
|
522
|
+
|
|
587
523
|
getLeftMost(node?: BinaryTreeNode<T> | null): BinaryTreeNode<T> | null {
|
|
588
524
|
node = node ?? this.root;
|
|
589
525
|
if (!node) return node;
|
|
@@ -598,7 +534,7 @@ export class BinaryTree<T> {
|
|
|
598
534
|
return _traverse(node);
|
|
599
535
|
} else {
|
|
600
536
|
// Indirect implementation of iteration using tail recursion optimization
|
|
601
|
-
const _traverse = trampoline((cur: BinaryTreeNode<T>)
|
|
537
|
+
const _traverse = trampoline((cur: BinaryTreeNode<T>) => {
|
|
602
538
|
if (!cur.left) return cur;
|
|
603
539
|
return _traverse.cont(cur.left);
|
|
604
540
|
});
|
|
@@ -608,7 +544,9 @@ export class BinaryTree<T> {
|
|
|
608
544
|
}
|
|
609
545
|
|
|
610
546
|
getRightMost(): BinaryTreeNode<T> | null;
|
|
547
|
+
|
|
611
548
|
getRightMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
|
|
549
|
+
|
|
612
550
|
getRightMost(node?: BinaryTreeNode<T> | null): BinaryTreeNode<T> | null {
|
|
613
551
|
node = node ?? this.root;
|
|
614
552
|
if (!node) return node;
|
|
@@ -622,7 +560,7 @@ export class BinaryTree<T> {
|
|
|
622
560
|
return _traverse(node);
|
|
623
561
|
} else {
|
|
624
562
|
// Indirect implementation of iteration using tail recursion optimization
|
|
625
|
-
const _traverse = trampoline((cur: BinaryTreeNode<T>)
|
|
563
|
+
const _traverse = trampoline((cur: BinaryTreeNode<T>) => {
|
|
626
564
|
if (!cur.right) return cur;
|
|
627
565
|
return _traverse.cont(cur.right);
|
|
628
566
|
});
|
|
@@ -653,7 +591,7 @@ export class BinaryTree<T> {
|
|
|
653
591
|
curr = curr.left;
|
|
654
592
|
}
|
|
655
593
|
curr = stack.pop()!;
|
|
656
|
-
if (prev >= curr.id) return false;
|
|
594
|
+
if (!(curr) || prev >= curr.id) return false;
|
|
657
595
|
prev = curr.id;
|
|
658
596
|
curr = curr.right;
|
|
659
597
|
}
|
|
@@ -779,10 +717,15 @@ export class BinaryTree<T> {
|
|
|
779
717
|
}
|
|
780
718
|
|
|
781
719
|
BFS(): BinaryTreeNodeId[];
|
|
720
|
+
|
|
782
721
|
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
722
|
+
|
|
783
723
|
BFS(nodeOrPropertyName: 'val'): T[];
|
|
724
|
+
|
|
784
725
|
BFS(nodeOrPropertyName: 'node'): BinaryTreeNode<T>[];
|
|
726
|
+
|
|
785
727
|
BFS(nodeOrPropertyName: 'count'): number[];
|
|
728
|
+
|
|
786
729
|
BFS(nodeOrPropertyName ?: NodeOrPropertyName): ResultsByProperty<T> {
|
|
787
730
|
nodeOrPropertyName = nodeOrPropertyName ?? 'id';
|
|
788
731
|
this._resetResults();
|
|
@@ -801,10 +744,15 @@ export class BinaryTree<T> {
|
|
|
801
744
|
}
|
|
802
745
|
|
|
803
746
|
DFS(): BinaryTreeNodeId[];
|
|
747
|
+
|
|
804
748
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
749
|
+
|
|
805
750
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
|
|
751
|
+
|
|
806
752
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
|
|
753
|
+
|
|
807
754
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
755
|
+
|
|
808
756
|
DFS(pattern ?: 'in' | 'pre' | 'post', nodeOrPropertyName ?: NodeOrPropertyName): ResultsByProperty<T> {
|
|
809
757
|
pattern = pattern ?? 'in';
|
|
810
758
|
nodeOrPropertyName = nodeOrPropertyName ?? 'id';
|
|
@@ -834,9 +782,13 @@ export class BinaryTree<T> {
|
|
|
834
782
|
}
|
|
835
783
|
|
|
836
784
|
DFSIterative(): BinaryTreeNodeId[];
|
|
785
|
+
|
|
837
786
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
787
|
+
|
|
838
788
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
|
|
789
|
+
|
|
839
790
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
|
|
791
|
+
|
|
840
792
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
841
793
|
|
|
842
794
|
/**
|
|
@@ -889,10 +841,15 @@ export class BinaryTree<T> {
|
|
|
889
841
|
}
|
|
890
842
|
|
|
891
843
|
levelIterative(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[];
|
|
844
|
+
|
|
892
845
|
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
846
|
+
|
|
893
847
|
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[];
|
|
848
|
+
|
|
894
849
|
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
|
|
850
|
+
|
|
895
851
|
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[];
|
|
852
|
+
|
|
896
853
|
levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName ?: NodeOrPropertyName): ResultsByProperty<T> {
|
|
897
854
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
898
855
|
node = node || this.root;
|
|
@@ -918,10 +875,15 @@ export class BinaryTree<T> {
|
|
|
918
875
|
}
|
|
919
876
|
|
|
920
877
|
listLevels(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[][];
|
|
878
|
+
|
|
921
879
|
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
880
|
+
|
|
922
881
|
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[][];
|
|
882
|
+
|
|
923
883
|
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[][];
|
|
884
|
+
|
|
924
885
|
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[][];
|
|
886
|
+
|
|
925
887
|
listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: NodeOrPropertyName): ResultByProperty<T>[][] {
|
|
926
888
|
nodeOrPropertyName = nodeOrPropertyName || 'id';
|
|
927
889
|
node = node || this.root;
|
|
@@ -977,9 +939,11 @@ export class BinaryTree<T> {
|
|
|
977
939
|
|
|
978
940
|
getPredecessor(node: BinaryTreeNode<T>): BinaryTreeNode<T> {
|
|
979
941
|
if (node.left) {
|
|
980
|
-
let predecessor: BinaryTreeNode<T> | null = node.left;
|
|
981
|
-
while (predecessor.right && predecessor.right !== node) {
|
|
982
|
-
predecessor
|
|
942
|
+
let predecessor: BinaryTreeNode<T> | null | undefined = node.left;
|
|
943
|
+
while (!(predecessor) || predecessor.right && predecessor.right !== node) {
|
|
944
|
+
if (predecessor) {
|
|
945
|
+
predecessor = predecessor.right;
|
|
946
|
+
}
|
|
983
947
|
}
|
|
984
948
|
return predecessor;
|
|
985
949
|
} else {
|
|
@@ -988,10 +952,15 @@ export class BinaryTree<T> {
|
|
|
988
952
|
}
|
|
989
953
|
|
|
990
954
|
morris(): BinaryTreeNodeId[];
|
|
955
|
+
|
|
991
956
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
957
|
+
|
|
992
958
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
|
|
959
|
+
|
|
993
960
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
|
|
961
|
+
|
|
994
962
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
963
|
+
|
|
995
964
|
/**
|
|
996
965
|
* The time complexity of Morris traversal is O(n), it's may slower than others
|
|
997
966
|
* The space complexity Morris traversal is O(1) because no using stack
|
|
@@ -1084,5 +1053,81 @@ export class BinaryTree<T> {
|
|
|
1084
1053
|
return this._getResultByPropertyName(nodeOrPropertyName);
|
|
1085
1054
|
}
|
|
1086
1055
|
|
|
1056
|
+
protected _resetResults() {
|
|
1057
|
+
this._visitedId = [];
|
|
1058
|
+
this._visitedVal = [];
|
|
1059
|
+
this._visitedNode = [];
|
|
1060
|
+
this._visitedCount = [];
|
|
1061
|
+
this._visitedLeftSum = [];
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName ?: BinaryTreeNodePropertyName, onlyOne ?: boolean) {
|
|
1065
|
+
switch (propertyName) {
|
|
1066
|
+
case 'id':
|
|
1067
|
+
if (cur.id === nodeProperty) {
|
|
1068
|
+
result.push(cur);
|
|
1069
|
+
return !!onlyOne;
|
|
1070
|
+
}
|
|
1071
|
+
break;
|
|
1072
|
+
case 'count':
|
|
1073
|
+
if (cur.count === nodeProperty) {
|
|
1074
|
+
result.push(cur);
|
|
1075
|
+
return !!onlyOne;
|
|
1076
|
+
}
|
|
1077
|
+
break;
|
|
1078
|
+
case 'val':
|
|
1079
|
+
if (cur.val === nodeProperty) {
|
|
1080
|
+
result.push(cur);
|
|
1081
|
+
return !!onlyOne;
|
|
1082
|
+
}
|
|
1083
|
+
break;
|
|
1084
|
+
default:
|
|
1085
|
+
if (cur.id === nodeProperty) {
|
|
1086
|
+
result.push(cur);
|
|
1087
|
+
return !!onlyOne;
|
|
1088
|
+
}
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName ?: NodeOrPropertyName) {
|
|
1094
|
+
nodeOrPropertyName = nodeOrPropertyName ?? 'id';
|
|
1095
|
+
|
|
1096
|
+
switch (nodeOrPropertyName) {
|
|
1097
|
+
case 'id':
|
|
1098
|
+
this._visitedId.push(node.id);
|
|
1099
|
+
break;
|
|
1100
|
+
case 'val':
|
|
1101
|
+
this._visitedVal.push(node.val);
|
|
1102
|
+
break;
|
|
1103
|
+
case 'node':
|
|
1104
|
+
this._visitedNode.push(node);
|
|
1105
|
+
break;
|
|
1106
|
+
case 'count':
|
|
1107
|
+
this._visitedCount.push(node.count);
|
|
1108
|
+
break;
|
|
1109
|
+
default:
|
|
1110
|
+
this._visitedId.push(node.id);
|
|
1111
|
+
break;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
protected _getResultByPropertyName(nodeOrPropertyName ?: NodeOrPropertyName): ResultsByProperty<T> {
|
|
1116
|
+
nodeOrPropertyName = nodeOrPropertyName ?? 'id';
|
|
1117
|
+
|
|
1118
|
+
switch (nodeOrPropertyName) {
|
|
1119
|
+
case 'id':
|
|
1120
|
+
return this._visitedId;
|
|
1121
|
+
case 'val':
|
|
1122
|
+
return this._visitedVal;
|
|
1123
|
+
case 'node':
|
|
1124
|
+
return this._visitedNode;
|
|
1125
|
+
case 'count':
|
|
1126
|
+
return this._visitedCount;
|
|
1127
|
+
default:
|
|
1128
|
+
return this._visitedId;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1087
1132
|
// --- end additional methods ---
|
|
1088
1133
|
}
|