data-structure-typed 1.18.6 → 1.18.8
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/README.md +154 -366
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +72 -51
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +226 -158
- package/dist/data-structures/binary-tree/avl-tree.d.ts +7 -6
- package/dist/data-structures/binary-tree/avl-tree.js +5 -3
- package/dist/data-structures/binary-tree/binary-tree.d.ts +16 -6
- package/dist/data-structures/binary-tree/binary-tree.js +16 -7
- package/dist/data-structures/binary-tree/bst.d.ts +37 -28
- package/dist/data-structures/binary-tree/bst.js +44 -76
- package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
- package/dist/data-structures/binary-tree/rb-tree.js +27 -14
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +18 -7
- package/dist/data-structures/binary-tree/tree-multiset.js +20 -15
- package/dist/data-structures/graph/abstract-graph.d.ts +28 -27
- package/dist/data-structures/graph/abstract-graph.js +58 -36
- package/dist/data-structures/graph/directed-graph.d.ts +27 -24
- package/dist/data-structures/graph/directed-graph.js +65 -60
- package/dist/data-structures/graph/undirected-graph.d.ts +12 -18
- package/dist/data-structures/graph/undirected-graph.js +52 -65
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +100 -0
- package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +3 -8
- package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
- package/dist/data-structures/interfaces/binary-tree.d.ts +4 -24
- package/dist/data-structures/interfaces/bst.d.ts +18 -1
- package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
- package/dist/data-structures/interfaces/index.d.ts +1 -1
- package/dist/data-structures/interfaces/index.js +1 -1
- package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
- package/dist/data-structures/interfaces/rb-tree.js +2 -0
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
- package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
- package/dist/data-structures/tree/tree.d.ts +1 -4
- package/dist/data-structures/tree/tree.js +1 -12
- package/dist/data-structures/types/abstract-binary-tree.d.ts +11 -7
- package/dist/data-structures/types/abstract-binary-tree.js +9 -5
- package/dist/data-structures/types/avl-tree.d.ts +1 -1
- package/dist/data-structures/types/binary-tree.d.ts +1 -1
- package/dist/data-structures/types/bst.d.ts +1 -1
- package/dist/data-structures/types/bst.js +1 -1
- package/dist/data-structures/types/directed-graph.js +1 -1
- package/dist/data-structures/types/helpers.d.ts +1 -8
- package/dist/data-structures/types/rb-tree.d.ts +2 -0
- package/dist/data-structures/types/rb-tree.js +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +4 -4
- package/dist/utils/types/utils.d.ts +18 -0
- package/dist/utils/utils.d.ts +6 -1
- package/dist/utils/utils.js +83 -1
- package/package.json +2 -2
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
- package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
- package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
- package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
- package/backup/recursive-type/src/data-structures/index.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
- package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
- package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
- package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
- package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
- package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
- package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
- package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
- package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
- package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/index.ts +0 -1
- package/backup/recursive-type/src/utils/index.ts +0 -2
- package/backup/recursive-type/src/utils/types/index.ts +0 -1
- package/backup/recursive-type/src/utils/types/utils.ts +0 -6
- package/backup/recursive-type/src/utils/utils.ts +0 -78
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2339
- package/docs/classes/AVLTreeNode.html +0 -450
- package/docs/classes/AaTree.html +0 -166
- package/docs/classes/AbstractBinaryTree.html +0 -2023
- package/docs/classes/AbstractBinaryTreeNode.html +0 -491
- package/docs/classes/AbstractEdge.html +0 -289
- package/docs/classes/AbstractGraph.html +0 -1046
- package/docs/classes/AbstractVertex.html +0 -252
- package/docs/classes/ArrayDeque.html +0 -433
- package/docs/classes/BST.html +0 -2196
- package/docs/classes/BSTNode.html +0 -453
- package/docs/classes/BTree.html +0 -166
- package/docs/classes/BinaryIndexedTree.html +0 -335
- package/docs/classes/BinaryTree.html +0 -2037
- package/docs/classes/BinaryTreeNode.html +0 -452
- package/docs/classes/Character.html +0 -214
- package/docs/classes/CoordinateMap.html +0 -477
- package/docs/classes/CoordinateSet.html +0 -438
- package/docs/classes/Deque.html +0 -969
- package/docs/classes/DirectedEdge.html +0 -360
- package/docs/classes/DirectedGraph.html +0 -1408
- package/docs/classes/DirectedVertex.html +0 -248
- package/docs/classes/DoublyLinkedList.html +0 -962
- package/docs/classes/DoublyLinkedListNode.html +0 -291
- package/docs/classes/HashTable.html +0 -166
- package/docs/classes/Heap.html +0 -417
- package/docs/classes/HeapItem.html +0 -249
- package/docs/classes/Matrix2D.html +0 -496
- package/docs/classes/MatrixNTI2D.html +0 -234
- package/docs/classes/MaxHeap.html +0 -430
- package/docs/classes/MaxPriorityQueue.html +0 -830
- package/docs/classes/MinHeap.html +0 -431
- package/docs/classes/MinPriorityQueue.html +0 -832
- package/docs/classes/Navigator.html +0 -307
- package/docs/classes/ObjectDeque.html +0 -449
- package/docs/classes/Pair.html +0 -166
- package/docs/classes/PriorityQueue.html +0 -754
- package/docs/classes/Queue.html +0 -386
- package/docs/classes/SegmentTree.html +0 -428
- package/docs/classes/SegmentTreeNode.html +0 -351
- package/docs/classes/SinglyLinkedList.html +0 -782
- package/docs/classes/SinglyLinkedListNode.html +0 -264
- package/docs/classes/SkipLinkedList.html +0 -166
- package/docs/classes/SplayTree.html +0 -166
- package/docs/classes/Stack.html +0 -362
- package/docs/classes/TreeMap.html +0 -166
- package/docs/classes/TreeMultiSet.html +0 -2196
- package/docs/classes/TreeMultiSetNode.html +0 -450
- package/docs/classes/TreeNode.html +0 -337
- package/docs/classes/TreeSet.html +0 -166
- package/docs/classes/Trie.html +0 -366
- package/docs/classes/TrieNode.html +0 -274
- package/docs/classes/TwoThreeTree.html +0 -166
- package/docs/classes/UndirectedEdge.html +0 -331
- package/docs/classes/UndirectedGraph.html +0 -1196
- package/docs/classes/UndirectedVertex.html +0 -248
- package/docs/classes/Vector2D.html +0 -799
- package/docs/enums/CP.html +0 -175
- package/docs/enums/FamilyPosition.html +0 -175
- package/docs/enums/LoopType.html +0 -176
- package/docs/enums/RBColor.html +0 -168
- package/docs/enums/TopologicalProperty.html +0 -175
- package/docs/index.html +0 -639
- package/docs/interfaces/IBinaryTree.html +0 -189
- package/docs/interfaces/IBinaryTreeNode.html +0 -396
- package/docs/interfaces/IDirectedGraph.html +0 -259
- package/docs/interfaces/IGraph.html +0 -471
- package/docs/interfaces/IUNDirectedGraph.html +0 -151
- package/docs/modules.html +0 -250
- package/docs/types/AVLTreeOptions.html +0 -144
- package/docs/types/AbstractBinaryTreeOptions.html +0 -150
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -146
- package/docs/types/AbstractResultByProperty.html +0 -146
- package/docs/types/AbstractResultsByProperty.html +0 -146
- package/docs/types/BSTComparator.html +0 -156
- package/docs/types/BSTOptions.html +0 -146
- package/docs/types/BinaryTreeDeletedResult.html +0 -153
- package/docs/types/BinaryTreeNodeId.html +0 -141
- package/docs/types/BinaryTreeNodePropertyName.html +0 -141
- package/docs/types/BinaryTreeOptions.html +0 -144
- package/docs/types/DFSOrderPattern.html +0 -141
- package/docs/types/DijkstraResult.html +0 -161
- package/docs/types/Direction.html +0 -141
- package/docs/types/EdgeId.html +0 -141
- package/docs/types/HeapOptions.html +0 -162
- package/docs/types/IdObject.html +0 -151
- package/docs/types/KeyValObject.html +0 -146
- package/docs/types/NavigatorParams.html +0 -175
- package/docs/types/NodeOrPropertyName.html +0 -141
- package/docs/types/PriorityQueueComparator.html +0 -161
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -141
- package/docs/types/PriorityQueueOptions.html +0 -155
- package/docs/types/RBTreeOptions.html +0 -144
- package/docs/types/RecursiveAVLTreeNode.html +0 -146
- package/docs/types/RecursiveBSTNode.html +0 -146
- package/docs/types/RecursiveBinaryTreeNode.html +0 -146
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -146
- package/docs/types/SegmentTreeNodeVal.html +0 -141
- package/docs/types/TopologicalStatus.html +0 -141
- package/docs/types/TreeMultiSetOptions.html +0 -146
- package/docs/types/Turning.html +0 -141
- package/docs/types/VertexId.html +0 -141
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
|
|
2
2
|
import type { VertexId } from '../types';
|
|
3
|
+
import { IUNDirectedGraph } from '../interfaces';
|
|
3
4
|
export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
|
|
4
5
|
/**
|
|
5
6
|
* The constructor function initializes a vertex with an optional value.
|
|
@@ -26,7 +27,7 @@ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
|
|
|
26
27
|
get vertices(): [VertexId, VertexId];
|
|
27
28
|
set vertices(v: [VertexId, VertexId]);
|
|
28
29
|
}
|
|
29
|
-
export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> {
|
|
30
|
+
export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
|
|
30
31
|
constructor();
|
|
31
32
|
protected _edges: Map<V, E[]>;
|
|
32
33
|
get edges(): Map<V, E[]>;
|
|
@@ -36,9 +37,9 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
36
37
|
* @param id
|
|
37
38
|
* @param val
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
+
createVertex(id: VertexId, val?: V['val']): V;
|
|
40
41
|
/**
|
|
41
|
-
* The function
|
|
42
|
+
* The function createEdge creates an undirected edge between two vertices with an optional weight and value.
|
|
42
43
|
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
|
|
43
44
|
* could be a unique identifier or label for the vertex.
|
|
44
45
|
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
|
|
@@ -49,7 +50,7 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
49
50
|
* is used to store additional information or data associated with the edge.
|
|
50
51
|
* @returns an instance of the UndirectedEdge class, casted as type E.
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
+
createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
|
|
53
54
|
/**
|
|
54
55
|
* The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
|
|
55
56
|
* exists.
|
|
@@ -60,13 +61,6 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
60
61
|
* @returns an instance of `E` or `null`.
|
|
61
62
|
*/
|
|
62
63
|
getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
|
|
63
|
-
/**
|
|
64
|
-
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
65
|
-
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
66
|
-
* array of two vertices connected by the edge.
|
|
67
|
-
* @returns a boolean value.
|
|
68
|
-
*/
|
|
69
|
-
addEdge(edge: E): boolean;
|
|
70
64
|
/**
|
|
71
65
|
* The function removes an edge between two vertices in an undirected graph.
|
|
72
66
|
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
@@ -105,13 +99,6 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
105
99
|
* @returns The method `edgeSet()` returns an array of `E` objects.
|
|
106
100
|
*/
|
|
107
101
|
edgeSet(): E[];
|
|
108
|
-
/**
|
|
109
|
-
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
110
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
|
|
111
|
-
* `V` object or a `VertexId`.
|
|
112
|
-
* @returns The function `getEdgesOf` returns an array of `E` objects.
|
|
113
|
-
*/
|
|
114
|
-
getEdgesOf(vertexOrId: V | VertexId): E[];
|
|
115
102
|
/**
|
|
116
103
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
|
|
117
104
|
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
|
|
@@ -128,5 +115,12 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
|
|
|
128
115
|
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
129
116
|
*/
|
|
130
117
|
getEndsOfEdge(edge: E): [V, V] | null;
|
|
118
|
+
/**
|
|
119
|
+
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
120
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
121
|
+
* array of two vertices connected by the edge.
|
|
122
|
+
* @returns a boolean value.
|
|
123
|
+
*/
|
|
124
|
+
protected _addEdgeOnly(edge: E): boolean;
|
|
131
125
|
protected _setEdges(v: Map<V, E[]>): void;
|
|
132
126
|
}
|
|
@@ -14,17 +14,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
-
var __values = (this && this.__values) || function(o) {
|
|
18
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
19
|
-
if (m) return m.call(o);
|
|
20
|
-
if (o && typeof o.length === "number") return {
|
|
21
|
-
next: function () {
|
|
22
|
-
if (o && i >= o.length) o = void 0;
|
|
23
|
-
return { value: o && o[i++], done: !o };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
27
|
-
};
|
|
28
17
|
var __read = (this && this.__read) || function (o, n) {
|
|
29
18
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
30
19
|
if (!m) return o;
|
|
@@ -50,6 +39,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
50
39
|
}
|
|
51
40
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
52
41
|
};
|
|
42
|
+
var __values = (this && this.__values) || function(o) {
|
|
43
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
44
|
+
if (m) return m.call(o);
|
|
45
|
+
if (o && typeof o.length === "number") return {
|
|
46
|
+
next: function () {
|
|
47
|
+
if (o && i >= o.length) o = void 0;
|
|
48
|
+
return { value: o && o[i++], done: !o };
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
52
|
+
};
|
|
53
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
54
|
exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
|
|
55
55
|
/**
|
|
@@ -126,11 +126,11 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
126
126
|
* @param id
|
|
127
127
|
* @param val
|
|
128
128
|
*/
|
|
129
|
-
UndirectedGraph.prototype.
|
|
129
|
+
UndirectedGraph.prototype.createVertex = function (id, val) {
|
|
130
130
|
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
131
131
|
};
|
|
132
132
|
/**
|
|
133
|
-
* The function
|
|
133
|
+
* The function createEdge creates an undirected edge between two vertices with an optional weight and value.
|
|
134
134
|
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
|
|
135
135
|
* could be a unique identifier or label for the vertex.
|
|
136
136
|
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
|
|
@@ -141,7 +141,7 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
141
141
|
* is used to store additional information or data associated with the edge.
|
|
142
142
|
* @returns an instance of the UndirectedEdge class, casted as type E.
|
|
143
143
|
*/
|
|
144
|
-
UndirectedGraph.prototype.
|
|
144
|
+
UndirectedGraph.prototype.createEdge = function (v1, v2, weight, val) {
|
|
145
145
|
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
146
146
|
};
|
|
147
147
|
/**
|
|
@@ -165,40 +165,6 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
165
165
|
}
|
|
166
166
|
return edges ? edges[0] || null : null;
|
|
167
167
|
};
|
|
168
|
-
/**
|
|
169
|
-
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
170
|
-
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
171
|
-
* array of two vertices connected by the edge.
|
|
172
|
-
* @returns a boolean value.
|
|
173
|
-
*/
|
|
174
|
-
UndirectedGraph.prototype.addEdge = function (edge) {
|
|
175
|
-
var e_1, _a;
|
|
176
|
-
try {
|
|
177
|
-
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
178
|
-
var end = _c.value;
|
|
179
|
-
var endVertex = this._getVertex(end);
|
|
180
|
-
if (endVertex === null)
|
|
181
|
-
return false;
|
|
182
|
-
if (endVertex) {
|
|
183
|
-
var edges = this._edges.get(endVertex);
|
|
184
|
-
if (edges) {
|
|
185
|
-
edges.push(edge);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
this._edges.set(endVertex, [edge]);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
194
|
-
finally {
|
|
195
|
-
try {
|
|
196
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
197
|
-
}
|
|
198
|
-
finally { if (e_1) throw e_1.error; }
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
201
|
-
};
|
|
202
168
|
/**
|
|
203
169
|
* The function removes an edge between two vertices in an undirected graph.
|
|
204
170
|
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
@@ -280,19 +246,6 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
280
246
|
});
|
|
281
247
|
return __spreadArray([], __read(edgeSet), false);
|
|
282
248
|
};
|
|
283
|
-
/**
|
|
284
|
-
* The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
|
|
285
|
-
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
|
|
286
|
-
* `V` object or a `VertexId`.
|
|
287
|
-
* @returns The function `getEdgesOf` returns an array of `E` objects.
|
|
288
|
-
*/
|
|
289
|
-
UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
|
|
290
|
-
var vertex = this._getVertex(vertexOrId);
|
|
291
|
-
if (!vertex) {
|
|
292
|
-
return [];
|
|
293
|
-
}
|
|
294
|
-
return this._edges.get(vertex) || [];
|
|
295
|
-
};
|
|
296
249
|
/**
|
|
297
250
|
* The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
|
|
298
251
|
* @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
|
|
@@ -300,11 +253,11 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
300
253
|
* @returns an array of UndirectedVertex objects.
|
|
301
254
|
*/
|
|
302
255
|
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
303
|
-
var
|
|
256
|
+
var e_1, _a;
|
|
304
257
|
var neighbors = [];
|
|
305
258
|
var vertex = this._getVertex(vertexOrId);
|
|
306
259
|
if (vertex) {
|
|
307
|
-
var neighborEdges = this.
|
|
260
|
+
var neighborEdges = this.edgesOf(vertex);
|
|
308
261
|
try {
|
|
309
262
|
for (var neighborEdges_1 = __values(neighborEdges), neighborEdges_1_1 = neighborEdges_1.next(); !neighborEdges_1_1.done; neighborEdges_1_1 = neighborEdges_1.next()) {
|
|
310
263
|
var edge = neighborEdges_1_1.value;
|
|
@@ -314,12 +267,12 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
314
267
|
}
|
|
315
268
|
}
|
|
316
269
|
}
|
|
317
|
-
catch (
|
|
270
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
318
271
|
finally {
|
|
319
272
|
try {
|
|
320
273
|
if (neighborEdges_1_1 && !neighborEdges_1_1.done && (_a = neighborEdges_1.return)) _a.call(neighborEdges_1);
|
|
321
274
|
}
|
|
322
|
-
finally { if (
|
|
275
|
+
finally { if (e_1) throw e_1.error; }
|
|
323
276
|
}
|
|
324
277
|
}
|
|
325
278
|
return neighbors;
|
|
@@ -345,6 +298,40 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
345
298
|
return null;
|
|
346
299
|
}
|
|
347
300
|
};
|
|
301
|
+
/**
|
|
302
|
+
* The function adds an undirected edge to a graph by updating the adjacency list.
|
|
303
|
+
* @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
|
|
304
|
+
* array of two vertices connected by the edge.
|
|
305
|
+
* @returns a boolean value.
|
|
306
|
+
*/
|
|
307
|
+
UndirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
308
|
+
var e_2, _a;
|
|
309
|
+
try {
|
|
310
|
+
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
311
|
+
var end = _c.value;
|
|
312
|
+
var endVertex = this._getVertex(end);
|
|
313
|
+
if (endVertex === null)
|
|
314
|
+
return false;
|
|
315
|
+
if (endVertex) {
|
|
316
|
+
var edges = this._edges.get(endVertex);
|
|
317
|
+
if (edges) {
|
|
318
|
+
edges.push(edge);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
this._edges.set(endVertex, [edge]);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
327
|
+
finally {
|
|
328
|
+
try {
|
|
329
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
330
|
+
}
|
|
331
|
+
finally { if (e_2) throw e_2.error; }
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
};
|
|
348
335
|
UndirectedGraph.prototype._setEdges = function (v) {
|
|
349
336
|
this._edges = v;
|
|
350
337
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
|
|
2
|
+
import { AbstractBinaryTreeNode } from '../binary-tree';
|
|
3
|
+
export interface IAbstractBinaryTreeNode<T, FAMILY extends IAbstractBinaryTreeNode<T, FAMILY>> {
|
|
4
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
5
|
+
get id(): BinaryTreeNodeId;
|
|
6
|
+
set id(v: BinaryTreeNodeId);
|
|
7
|
+
get val(): T | undefined;
|
|
8
|
+
set val(v: T | undefined);
|
|
9
|
+
get left(): FAMILY | null | undefined;
|
|
10
|
+
set left(v: FAMILY | null | undefined);
|
|
11
|
+
get right(): FAMILY | null | undefined;
|
|
12
|
+
set right(v: FAMILY | null | undefined);
|
|
13
|
+
get parent(): FAMILY | null | undefined;
|
|
14
|
+
set parent(v: FAMILY | null | undefined);
|
|
15
|
+
get familyPosition(): FamilyPosition;
|
|
16
|
+
get count(): number;
|
|
17
|
+
set count(v: number);
|
|
18
|
+
get height(): number;
|
|
19
|
+
set height(v: number);
|
|
20
|
+
swapLocation(swapNode: FAMILY): FAMILY;
|
|
21
|
+
clone(): FAMILY | null;
|
|
22
|
+
}
|
|
23
|
+
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
24
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
25
|
+
get loopType(): LoopType;
|
|
26
|
+
get visitedId(): BinaryTreeNodeId[];
|
|
27
|
+
get visitedVal(): Array<N['val']>;
|
|
28
|
+
get visitedNode(): N[];
|
|
29
|
+
get visitedCount(): number[];
|
|
30
|
+
get visitedLeftSum(): number[];
|
|
31
|
+
get autoIncrementId(): boolean;
|
|
32
|
+
get maxId(): number;
|
|
33
|
+
get isMergeDuplicatedVal(): boolean;
|
|
34
|
+
get root(): N | null;
|
|
35
|
+
get size(): number;
|
|
36
|
+
get count(): number;
|
|
37
|
+
clear(): void;
|
|
38
|
+
isEmpty(): boolean;
|
|
39
|
+
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
40
|
+
addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
41
|
+
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
|
|
42
|
+
fill(data: N[] | Array<N['val']>): boolean;
|
|
43
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
44
|
+
getDepth(node: N): number;
|
|
45
|
+
getHeight(beginRoot?: N | null): number;
|
|
46
|
+
getMinHeight(beginRoot?: N | null): number;
|
|
47
|
+
isBalanced(beginRoot?: N | null): boolean;
|
|
48
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
49
|
+
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
50
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
51
|
+
getPathToRoot(node: N): N[];
|
|
52
|
+
getLeftMost(): N | null;
|
|
53
|
+
getLeftMost(node: N): N;
|
|
54
|
+
getLeftMost(node?: N | null): N | null;
|
|
55
|
+
getRightMost(): N | null;
|
|
56
|
+
getRightMost(node: N): N;
|
|
57
|
+
getRightMost(node?: N | null): N | null;
|
|
58
|
+
isBSTByRooted(node: N | null): boolean;
|
|
59
|
+
isBST(node?: N | null): boolean;
|
|
60
|
+
getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
|
|
61
|
+
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
62
|
+
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
63
|
+
BFS(): BinaryTreeNodeId[];
|
|
64
|
+
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
65
|
+
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
66
|
+
BFS(nodeOrPropertyName: 'node'): N[];
|
|
67
|
+
BFS(nodeOrPropertyName: 'count'): number[];
|
|
68
|
+
BFS(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
69
|
+
DFS(): BinaryTreeNodeId[];
|
|
70
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
71
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
72
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
73
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
74
|
+
DFS(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
75
|
+
DFSIterative(): BinaryTreeNodeId[];
|
|
76
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
77
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
78
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
79
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
80
|
+
DFSIterative(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
81
|
+
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
82
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
83
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
84
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
85
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
86
|
+
levelIterative(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
87
|
+
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
88
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
89
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
90
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
91
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
92
|
+
listLevels(node: N | null, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperty<N>[][];
|
|
93
|
+
getPredecessor(node: N): N;
|
|
94
|
+
morris(): BinaryTreeNodeId[];
|
|
95
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
96
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
97
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
98
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
99
|
+
morris(pattern?: 'in' | 'pre' | 'post', nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
100
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { VertexId } from '../types';
|
|
2
|
-
export interface
|
|
2
|
+
export interface IAbstractGraph<V, E> {
|
|
3
3
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
4
|
-
|
|
5
|
-
_getVertexId(vertexOrId: V | VertexId): VertexId;
|
|
6
|
-
createAddVertex(id: VertexId, val?: V): boolean;
|
|
7
|
-
addVertex(newVertex: V): boolean;
|
|
4
|
+
addVertex(id: VertexId, val?: V): boolean;
|
|
8
5
|
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
9
6
|
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
10
7
|
degreeOf(vertexOrId: V | VertexId): number;
|
|
@@ -12,9 +9,7 @@ export interface IGraph<V, E> {
|
|
|
12
9
|
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
13
10
|
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
14
11
|
edgeSet(): E[];
|
|
15
|
-
|
|
16
|
-
addEdge(edge: E): boolean;
|
|
17
|
-
removeEdgeBetween(src: V | VertexId, dest: V | VertexId): E | null;
|
|
12
|
+
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
|
18
13
|
removeEdge(edge: E): E | null;
|
|
19
14
|
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
20
15
|
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { AVLTreeNode } from '../binary-tree';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
4
|
+
export interface IAVLTreeNode<T, FAMILY extends IAVLTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
|
+
}
|
|
6
|
+
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null;
|
|
8
|
+
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
|
+
balanceFactor(node: N): number;
|
|
10
|
+
updateHeight(node: N): void;
|
|
11
|
+
balancePath(node: N): void;
|
|
12
|
+
balanceLL(A: N): void;
|
|
13
|
+
balanceLR(A: N): void;
|
|
14
|
+
balanceRR(A: N): void;
|
|
15
|
+
balanceRL(A: N): void;
|
|
16
|
+
}
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
get id(): BinaryTreeNodeId;
|
|
5
|
-
set id(v: BinaryTreeNodeId);
|
|
6
|
-
get val(): T;
|
|
7
|
-
set val(v: T);
|
|
8
|
-
get left(): FAMILY | null | undefined;
|
|
9
|
-
set left(v: FAMILY | null | undefined);
|
|
10
|
-
get right(): FAMILY | null | undefined;
|
|
11
|
-
set right(v: FAMILY | null | undefined);
|
|
12
|
-
get parent(): FAMILY | null | undefined;
|
|
13
|
-
set parent(v: FAMILY | null | undefined);
|
|
14
|
-
get familyPosition(): FamilyPosition;
|
|
15
|
-
set familyPosition(v: FamilyPosition);
|
|
16
|
-
get count(): number;
|
|
17
|
-
set count(v: number);
|
|
18
|
-
get height(): number;
|
|
19
|
-
set height(v: number);
|
|
20
|
-
_createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
|
|
21
|
-
swapLocation(swapNode: FAMILY): FAMILY;
|
|
22
|
-
clone(): FAMILY | null;
|
|
1
|
+
import { BinaryTreeNode } from '../binary-tree';
|
|
2
|
+
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
+
export interface IBinaryTreeNode<T, FAMILY extends IBinaryTreeNode<T, FAMILY>> extends IAbstractBinaryTreeNode<T, FAMILY> {
|
|
23
4
|
}
|
|
24
|
-
export interface IBinaryTree<N extends
|
|
25
|
-
_createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
5
|
+
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
|
|
26
6
|
}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { BSTNode } from '../binary-tree';
|
|
2
|
+
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
|
+
import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
|
|
4
|
+
export interface IBSTNode<T, FAMILY extends IBSTNode<T, FAMILY>> extends IBinaryTreeNode<T, FAMILY> {
|
|
5
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
6
|
+
}
|
|
7
|
+
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
8
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
9
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null;
|
|
10
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
11
|
+
lastKey(): BinaryTreeNodeId;
|
|
12
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
13
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
14
|
+
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
|
|
15
|
+
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
16
|
+
balance(): boolean;
|
|
17
|
+
isAVLBalanced(): boolean;
|
|
18
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { VertexId } from '../types';
|
|
2
|
-
|
|
2
|
+
import { IAbstractGraph } from './abstract-graph';
|
|
3
|
+
export interface IDirectedGraph<V, E> extends IAbstractGraph<V, E> {
|
|
3
4
|
incomingEdgesOf(vertex: V): E[];
|
|
4
5
|
outgoingEdgesOf(vertex: V): E[];
|
|
5
6
|
inDegreeOf(vertexOrId: V | VertexId): number;
|
|
6
7
|
outDegreeOf(vertexOrId: V | VertexId): number;
|
|
7
8
|
getEdgeSrc(e: E): V | null;
|
|
8
9
|
getEdgeDest(e: E): V | null;
|
|
10
|
+
removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
11
|
+
removeEdgesBetween(v1: V | VertexId, v2: V | VertexId): E[];
|
|
9
12
|
}
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./binary-tree"), exports);
|
|
17
|
+
__exportStar(require("./abstract-binary-tree"), exports);
|
|
18
18
|
__exportStar(require("./bst"), exports);
|
|
19
19
|
__exportStar(require("./avl-tree"), exports);
|
|
20
20
|
__exportStar(require("./segment-tree"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RBTreeNode } from '../binary-tree';
|
|
2
|
+
import { IBST, IBSTNode } from './bst';
|
|
3
|
+
import { BinaryTreeNodeId } from '../types';
|
|
4
|
+
export interface IRBTreeNode<T, FAMILY extends IRBTreeNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
6
|
+
}
|
|
7
|
+
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
8
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
9
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { TreeMultiSetNode } from '../binary-tree';
|
|
2
|
+
import { IBSTNode } from './bst';
|
|
3
|
+
import { IAVLTree } from './avl-tree';
|
|
4
|
+
export interface ITreeMultiSetNode<T, FAMILY extends ITreeMultiSetNode<T, FAMILY>> extends IBSTNode<T, FAMILY> {
|
|
5
|
+
}
|
|
6
|
+
export interface ITreeMultiSet<N extends TreeMultiSetNode<N['val'], N>> extends IAVLTree<N> {
|
|
7
|
+
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { VertexId } from '../types';
|
|
2
|
+
import { IAbstractGraph } from './abstract-graph';
|
|
3
|
+
export interface IUNDirectedGraph<V, E> extends IAbstractGraph<V, E> {
|
|
4
|
+
removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
|
|
2
5
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export declare class TreeNode<T = number> {
|
|
2
|
-
constructor(id: string,
|
|
2
|
+
constructor(id: string, value?: T, children?: TreeNode<T>[]);
|
|
3
3
|
private _id;
|
|
4
4
|
get id(): string;
|
|
5
5
|
set id(value: string);
|
|
6
|
-
private _name?;
|
|
7
|
-
get name(): string | undefined;
|
|
8
|
-
set name(value: string | undefined);
|
|
9
6
|
private _value?;
|
|
10
7
|
get value(): T | undefined;
|
|
11
8
|
set value(value: T | undefined);
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TreeNode = void 0;
|
|
4
4
|
var TreeNode = /** @class */ (function () {
|
|
5
|
-
function TreeNode(id,
|
|
5
|
+
function TreeNode(id, value, children) {
|
|
6
6
|
this._id = id;
|
|
7
|
-
this._name = name || '';
|
|
8
7
|
this._value = value || undefined;
|
|
9
8
|
this._children = children || [];
|
|
10
9
|
}
|
|
@@ -18,16 +17,6 @@ var TreeNode = /** @class */ (function () {
|
|
|
18
17
|
enumerable: false,
|
|
19
18
|
configurable: true
|
|
20
19
|
});
|
|
21
|
-
Object.defineProperty(TreeNode.prototype, "name", {
|
|
22
|
-
get: function () {
|
|
23
|
-
return this._name;
|
|
24
|
-
},
|
|
25
|
-
set: function (value) {
|
|
26
|
-
this._name = value;
|
|
27
|
-
},
|
|
28
|
-
enumerable: false,
|
|
29
|
-
configurable: true
|
|
30
|
-
});
|
|
31
20
|
Object.defineProperty(TreeNode.prototype, "value", {
|
|
32
21
|
get: function () {
|
|
33
22
|
return this._value;
|
|
@@ -10,9 +10,13 @@ export declare enum LoopType {
|
|
|
10
10
|
RECURSIVE = "RECURSIVE"
|
|
11
11
|
}
|
|
12
12
|
export declare enum FamilyPosition {
|
|
13
|
-
ROOT =
|
|
14
|
-
LEFT =
|
|
15
|
-
RIGHT =
|
|
13
|
+
ROOT = "ROOT",
|
|
14
|
+
LEFT = "LEFT",
|
|
15
|
+
RIGHT = "RIGHT",
|
|
16
|
+
ROOT_LEFT = "ROOT_LEFT",
|
|
17
|
+
ROOT_RIGHT = "ROOT_RIGHT",
|
|
18
|
+
ISOLATED = "ISOLATED",
|
|
19
|
+
MAL_NODE = "MAL_NODE"
|
|
16
20
|
}
|
|
17
21
|
export type BinaryTreeNodePropertyName = 'id' | 'val' | 'count';
|
|
18
22
|
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
@@ -22,11 +26,11 @@ export type BinaryTreeDeletedResult<N> = {
|
|
|
22
26
|
deleted: N | null | undefined;
|
|
23
27
|
needBalanced: N | null;
|
|
24
28
|
};
|
|
25
|
-
export type
|
|
26
|
-
export type
|
|
27
|
-
export type
|
|
29
|
+
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
|
|
30
|
+
export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
|
|
31
|
+
export type AbstractBinaryTreeNodeNested<T> = AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, AbstractBinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
28
32
|
export type AbstractBinaryTreeOptions = {
|
|
29
33
|
loopType?: LoopType;
|
|
30
34
|
autoIncrementId?: boolean;
|
|
31
|
-
|
|
35
|
+
isMergeDuplicatedVal?: boolean;
|
|
32
36
|
};
|
|
@@ -11,11 +11,15 @@ var LoopType;
|
|
|
11
11
|
(function (LoopType) {
|
|
12
12
|
LoopType["ITERATIVE"] = "ITERATIVE";
|
|
13
13
|
LoopType["RECURSIVE"] = "RECURSIVE";
|
|
14
|
-
})(LoopType
|
|
14
|
+
})(LoopType = exports.LoopType || (exports.LoopType = {}));
|
|
15
15
|
/* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */
|
|
16
16
|
var FamilyPosition;
|
|
17
17
|
(function (FamilyPosition) {
|
|
18
|
-
FamilyPosition[
|
|
19
|
-
FamilyPosition[
|
|
20
|
-
FamilyPosition[
|
|
21
|
-
|
|
18
|
+
FamilyPosition["ROOT"] = "ROOT";
|
|
19
|
+
FamilyPosition["LEFT"] = "LEFT";
|
|
20
|
+
FamilyPosition["RIGHT"] = "RIGHT";
|
|
21
|
+
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
22
|
+
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
23
|
+
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
24
|
+
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
25
|
+
})(FamilyPosition = exports.FamilyPosition || (exports.FamilyPosition = {}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AVLTreeNode } from '../binary-tree';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
|
-
export type
|
|
3
|
+
export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type AVLTreeOptions = BSTOptions & {};
|