data-structure-typed 1.18.7 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -419
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
- package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +12 -27
- package/dist/data-structures/binary-tree/bst.d.ts +66 -90
- package/dist/data-structures/binary-tree/bst.js +85 -163
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
- package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
- package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
- package/dist/data-structures/graph/abstract-graph.js +138 -72
- package/dist/data-structures/graph/directed-graph.d.ts +104 -101
- package/dist/data-structures/graph/directed-graph.js +134 -129
- package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
- package/dist/data-structures/graph/undirected-graph.js +107 -106
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +4 -5
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -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 +10 -6
- 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 +5 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +0 -62
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +5 -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 -2451
- package/docs/classes/AVLTreeNode.html +0 -499
- package/docs/classes/AaTree.html +0 -172
- package/docs/classes/AbstractBinaryTree.html +0 -2118
- package/docs/classes/AbstractBinaryTreeNode.html +0 -524
- package/docs/classes/AbstractEdge.html +0 -295
- package/docs/classes/AbstractGraph.html +0 -1043
- package/docs/classes/AbstractVertex.html +0 -258
- package/docs/classes/ArrayDeque.html +0 -439
- package/docs/classes/BST.html +0 -2297
- package/docs/classes/BSTNode.html +0 -503
- package/docs/classes/BTree.html +0 -172
- package/docs/classes/BinaryIndexedTree.html +0 -341
- package/docs/classes/BinaryTree.html +0 -2133
- package/docs/classes/BinaryTreeNode.html +0 -501
- package/docs/classes/Character.html +0 -220
- package/docs/classes/CoordinateMap.html +0 -483
- package/docs/classes/CoordinateSet.html +0 -444
- package/docs/classes/Deque.html +0 -975
- package/docs/classes/DirectedEdge.html +0 -366
- package/docs/classes/DirectedGraph.html +0 -1443
- package/docs/classes/DirectedVertex.html +0 -254
- package/docs/classes/DoublyLinkedList.html +0 -968
- package/docs/classes/DoublyLinkedListNode.html +0 -297
- package/docs/classes/HashTable.html +0 -172
- package/docs/classes/Heap.html +0 -423
- package/docs/classes/HeapItem.html +0 -255
- package/docs/classes/Matrix2D.html +0 -502
- package/docs/classes/MatrixNTI2D.html +0 -240
- package/docs/classes/MaxHeap.html +0 -436
- package/docs/classes/MaxPriorityQueue.html +0 -836
- package/docs/classes/MinHeap.html +0 -437
- package/docs/classes/MinPriorityQueue.html +0 -838
- package/docs/classes/Navigator.html +0 -313
- package/docs/classes/ObjectDeque.html +0 -455
- package/docs/classes/Pair.html +0 -172
- package/docs/classes/PriorityQueue.html +0 -760
- package/docs/classes/Queue.html +0 -392
- package/docs/classes/RBTree.html +0 -2388
- package/docs/classes/RBTreeNode.html +0 -516
- package/docs/classes/SegmentTree.html +0 -434
- package/docs/classes/SegmentTreeNode.html +0 -357
- package/docs/classes/SinglyLinkedList.html +0 -788
- package/docs/classes/SinglyLinkedListNode.html +0 -270
- package/docs/classes/SkipLinkedList.html +0 -172
- package/docs/classes/SplayTree.html +0 -172
- package/docs/classes/Stack.html +0 -368
- package/docs/classes/TreeMap.html +0 -172
- package/docs/classes/TreeMultiSet.html +0 -2297
- package/docs/classes/TreeMultiSetNode.html +0 -499
- package/docs/classes/TreeNode.html +0 -343
- package/docs/classes/TreeSet.html +0 -172
- package/docs/classes/Trie.html +0 -372
- package/docs/classes/TrieNode.html +0 -280
- package/docs/classes/TwoThreeTree.html +0 -172
- package/docs/classes/UndirectedEdge.html +0 -337
- package/docs/classes/UndirectedGraph.html +0 -1210
- package/docs/classes/UndirectedVertex.html +0 -254
- package/docs/classes/Vector2D.html +0 -805
- package/docs/enums/CP.html +0 -181
- package/docs/enums/FamilyPosition.html +0 -181
- package/docs/enums/LoopType.html +0 -182
- package/docs/enums/RBColor.html +0 -174
- package/docs/enums/TopologicalProperty.html +0 -181
- package/docs/index.html +0 -645
- package/docs/interfaces/IAVLTree.html +0 -1378
- package/docs/interfaces/IAVLTreeNode.html +0 -405
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1271
- package/docs/interfaces/IBSTNode.html +0 -408
- package/docs/interfaces/IDirectedGraph.html +0 -572
- package/docs/interfaces/IUNDirectedGraph.html +0 -465
- package/docs/modules.html +0 -262
- package/docs/types/AVLTreeOptions.html +0 -150
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
- package/docs/types/AbstractBinaryTreeOptions.html +0 -156
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
- package/docs/types/BSTComparator.html +0 -162
- package/docs/types/BSTOptions.html +0 -152
- package/docs/types/BinaryTreeDeletedResult.html +0 -159
- package/docs/types/BinaryTreeNodeId.html +0 -147
- package/docs/types/BinaryTreeNodePropertyName.html +0 -147
- package/docs/types/BinaryTreeOptions.html +0 -150
- package/docs/types/DFSOrderPattern.html +0 -147
- package/docs/types/DijkstraResult.html +0 -167
- package/docs/types/Direction.html +0 -147
- package/docs/types/EdgeId.html +0 -147
- package/docs/types/HeapOptions.html +0 -168
- package/docs/types/IdObject.html +0 -157
- package/docs/types/KeyValObject.html +0 -152
- package/docs/types/NavigatorParams.html +0 -181
- package/docs/types/NodeOrPropertyName.html +0 -147
- package/docs/types/PriorityQueueComparator.html +0 -167
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
- package/docs/types/PriorityQueueOptions.html +0 -161
- package/docs/types/RBTreeOptions.html +0 -150
- package/docs/types/RecursiveAVLTreeNode.html +0 -152
- package/docs/types/RecursiveBSTNode.html +0 -152
- package/docs/types/RecursiveBinaryTreeNode.html +0 -152
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
- package/docs/types/SegmentTreeNodeVal.html +0 -147
- package/docs/types/TopologicalStatus.html +0 -147
- package/docs/types/TreeMultiSetOptions.html +0 -152
- package/docs/types/Turning.html +0 -147
- package/docs/types/VertexId.html +0 -147
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -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
|
/**
|
|
@@ -65,8 +65,8 @@ var UndirectedVertex = /** @class */ (function (_super) {
|
|
|
65
65
|
__extends(UndirectedVertex, _super);
|
|
66
66
|
/**
|
|
67
67
|
* The constructor function initializes a vertex with an optional value.
|
|
68
|
-
* @param {VertexId} id - The `id` parameter is the identifier
|
|
69
|
-
*
|
|
68
|
+
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
|
|
69
|
+
* used to uniquely identify the vertex within a graph or network.
|
|
70
70
|
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
|
|
71
71
|
* vertex. If no value is provided, the vertex will be initialized with a default value.
|
|
72
72
|
*/
|
|
@@ -79,14 +79,14 @@ exports.UndirectedVertex = UndirectedVertex;
|
|
|
79
79
|
var UndirectedEdge = /** @class */ (function (_super) {
|
|
80
80
|
__extends(UndirectedEdge, _super);
|
|
81
81
|
/**
|
|
82
|
-
* The constructor function
|
|
82
|
+
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
|
|
83
83
|
* value.
|
|
84
|
-
* @param {VertexId} v1 - The
|
|
84
|
+
* @param {VertexId} v1 - The first vertex ID of the edge.
|
|
85
85
|
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
|
|
86
86
|
* graph edge.
|
|
87
87
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
|
|
88
|
-
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It
|
|
89
|
-
* the edge.
|
|
88
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
|
|
89
|
+
* with the edge.
|
|
90
90
|
*/
|
|
91
91
|
function UndirectedEdge(v1, v2, weight, val) {
|
|
92
92
|
var _this = _super.call(this, weight, val) || this;
|
|
@@ -108,6 +108,9 @@ var UndirectedEdge = /** @class */ (function (_super) {
|
|
|
108
108
|
exports.UndirectedEdge = UndirectedEdge;
|
|
109
109
|
var UndirectedGraph = /** @class */ (function (_super) {
|
|
110
110
|
__extends(UndirectedGraph, _super);
|
|
111
|
+
/**
|
|
112
|
+
* The constructor initializes a new Map object to store edges.
|
|
113
|
+
*/
|
|
111
114
|
function UndirectedGraph() {
|
|
112
115
|
var _this = _super.call(this) || this;
|
|
113
116
|
_this._edges = new Map();
|
|
@@ -121,37 +124,37 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
121
124
|
configurable: true
|
|
122
125
|
});
|
|
123
126
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @param val
|
|
127
|
+
* The function creates a new vertex with an optional value and returns it.
|
|
128
|
+
* @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
|
|
129
|
+
* vertex from another in the graph.
|
|
130
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
131
|
+
* it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
|
|
132
|
+
* the vertex.
|
|
133
|
+
* @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
|
|
128
134
|
*/
|
|
129
135
|
UndirectedGraph.prototype.createVertex = function (id, val) {
|
|
130
136
|
return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
|
|
131
137
|
};
|
|
132
138
|
/**
|
|
133
|
-
* The function
|
|
134
|
-
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
135
|
-
*
|
|
136
|
-
* @param {
|
|
137
|
-
*
|
|
138
|
-
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
139
|
-
* weight is provided, the default value is 1.
|
|
139
|
+
* The function creates an undirected edge between two vertices with an optional weight and value.
|
|
140
|
+
* @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
141
|
+
* @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
142
|
+
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
143
|
+
* no weight is provided, it defaults to 1.
|
|
140
144
|
* @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
|
|
141
145
|
* is used to store additional information or data associated with the edge.
|
|
142
|
-
* @returns
|
|
146
|
+
* @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
|
|
143
147
|
*/
|
|
144
148
|
UndirectedGraph.prototype.createEdge = function (v1, v2, weight, val) {
|
|
145
149
|
return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
|
|
146
150
|
};
|
|
147
151
|
/**
|
|
148
|
-
* The function `getEdge` returns the first
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @returns an instance of `E` or `null`.
|
|
152
|
+
* The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
|
|
153
|
+
* @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
154
|
+
* object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
|
|
155
|
+
* @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
|
|
156
|
+
* object), `null`, or `VertexId` (vertex ID).
|
|
157
|
+
* @returns an edge (E) or null.
|
|
155
158
|
*/
|
|
156
159
|
UndirectedGraph.prototype.getEdge = function (v1, v2) {
|
|
157
160
|
var _a;
|
|
@@ -166,49 +169,11 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
166
169
|
return edges ? edges[0] || null : null;
|
|
167
170
|
};
|
|
168
171
|
/**
|
|
169
|
-
* The function
|
|
170
|
-
* @param
|
|
171
|
-
*
|
|
172
|
-
*
|
|
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
|
-
/**
|
|
203
|
-
* The function removes an edge between two vertices in an undirected graph.
|
|
204
|
-
* @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
|
|
205
|
-
* a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
|
|
206
|
-
* @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
|
|
207
|
-
* `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
|
|
208
|
-
* removed.
|
|
209
|
-
* @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
|
|
210
|
-
* between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
|
|
211
|
-
* between them, the function returns `null`.
|
|
172
|
+
* The function removes an edge between two vertices in a graph and returns the removed edge.
|
|
173
|
+
* @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
|
|
174
|
+
* @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
|
|
175
|
+
* (VertexId). It represents the second vertex of the edge that needs to be removed.
|
|
176
|
+
* @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
|
|
212
177
|
*/
|
|
213
178
|
UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
|
|
214
179
|
var vertex1 = this._getVertex(v1);
|
|
@@ -228,19 +193,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
228
193
|
return removed;
|
|
229
194
|
};
|
|
230
195
|
/**
|
|
231
|
-
* The removeEdge function removes an edge between two vertices in
|
|
232
|
-
* @param edge -
|
|
233
|
-
*
|
|
234
|
-
* @returns The method is returning an UndirectedEdge object or null.
|
|
196
|
+
* The removeEdge function removes an edge between two vertices in a graph.
|
|
197
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
198
|
+
* @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
|
|
235
199
|
*/
|
|
236
200
|
UndirectedGraph.prototype.removeEdge = function (edge) {
|
|
237
201
|
return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
|
|
238
202
|
};
|
|
239
203
|
/**
|
|
240
|
-
* The function
|
|
241
|
-
*
|
|
242
|
-
* `V`.
|
|
243
|
-
* @returns the degree of
|
|
204
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
|
|
205
|
+
* vertex.
|
|
206
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
|
|
207
|
+
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
208
|
+
* edges connected to that vertex.
|
|
244
209
|
*/
|
|
245
210
|
UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
|
|
246
211
|
var _a;
|
|
@@ -253,10 +218,10 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
253
218
|
}
|
|
254
219
|
};
|
|
255
220
|
/**
|
|
256
|
-
* The function
|
|
257
|
-
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or
|
|
258
|
-
* `V
|
|
259
|
-
* @returns an array of
|
|
221
|
+
* The function returns the edges of a given vertex or vertex ID.
|
|
222
|
+
* @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
|
|
223
|
+
* unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
|
|
224
|
+
* @returns an array of edges.
|
|
260
225
|
*/
|
|
261
226
|
UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
|
|
262
227
|
var vertex = this._getVertex(vertexOrId);
|
|
@@ -268,8 +233,8 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
268
233
|
}
|
|
269
234
|
};
|
|
270
235
|
/**
|
|
271
|
-
* The function "edgeSet" returns an array of unique
|
|
272
|
-
* @returns The method `edgeSet()` returns an array of `E
|
|
236
|
+
* The function "edgeSet" returns an array of unique edges from a set of edges.
|
|
237
|
+
* @returns The method `edgeSet()` returns an array of type `E[]`.
|
|
273
238
|
*/
|
|
274
239
|
UndirectedGraph.prototype.edgeSet = function () {
|
|
275
240
|
var edgeSet = new Set();
|
|
@@ -281,13 +246,13 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
281
246
|
return __spreadArray([], __read(edgeSet), false);
|
|
282
247
|
};
|
|
283
248
|
/**
|
|
284
|
-
* The function
|
|
285
|
-
* @param {V | VertexId} vertexOrId - The `vertexOrId`
|
|
286
|
-
* `
|
|
287
|
-
* @returns an array of
|
|
249
|
+
* The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
|
|
250
|
+
* @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
|
|
251
|
+
* (`VertexId`).
|
|
252
|
+
* @returns an array of vertices (V[]).
|
|
288
253
|
*/
|
|
289
254
|
UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
|
|
290
|
-
var
|
|
255
|
+
var e_1, _a;
|
|
291
256
|
var neighbors = [];
|
|
292
257
|
var vertex = this._getVertex(vertexOrId);
|
|
293
258
|
if (vertex) {
|
|
@@ -301,23 +266,22 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
301
266
|
}
|
|
302
267
|
}
|
|
303
268
|
}
|
|
304
|
-
catch (
|
|
269
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
305
270
|
finally {
|
|
306
271
|
try {
|
|
307
272
|
if (neighborEdges_1_1 && !neighborEdges_1_1.done && (_a = neighborEdges_1.return)) _a.call(neighborEdges_1);
|
|
308
273
|
}
|
|
309
|
-
finally { if (
|
|
274
|
+
finally { if (e_1) throw e_1.error; }
|
|
310
275
|
}
|
|
311
276
|
}
|
|
312
277
|
return neighbors;
|
|
313
278
|
};
|
|
314
279
|
/**
|
|
315
|
-
* The function "getEndsOfEdge" returns the
|
|
316
|
-
*
|
|
317
|
-
* @param edge -
|
|
318
|
-
* array containing two vertices
|
|
319
|
-
*
|
|
320
|
-
* exists in the graph. If the edge does not exist, it returns `null`.
|
|
280
|
+
* The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
|
|
281
|
+
* it returns null.
|
|
282
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
283
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
|
|
284
|
+
* graph. If the edge does not exist, it returns `null`.
|
|
321
285
|
*/
|
|
322
286
|
UndirectedGraph.prototype.getEndsOfEdge = function (edge) {
|
|
323
287
|
if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
|
|
@@ -332,6 +296,43 @@ var UndirectedGraph = /** @class */ (function (_super) {
|
|
|
332
296
|
return null;
|
|
333
297
|
}
|
|
334
298
|
};
|
|
299
|
+
/**
|
|
300
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
|
|
301
|
+
* @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
|
|
302
|
+
* @returns a boolean value.
|
|
303
|
+
*/
|
|
304
|
+
UndirectedGraph.prototype._addEdgeOnly = function (edge) {
|
|
305
|
+
var e_2, _a;
|
|
306
|
+
try {
|
|
307
|
+
for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
308
|
+
var end = _c.value;
|
|
309
|
+
var endVertex = this._getVertex(end);
|
|
310
|
+
if (endVertex === null)
|
|
311
|
+
return false;
|
|
312
|
+
if (endVertex) {
|
|
313
|
+
var edges = this._edges.get(endVertex);
|
|
314
|
+
if (edges) {
|
|
315
|
+
edges.push(edge);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
this._edges.set(endVertex, [edge]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
324
|
+
finally {
|
|
325
|
+
try {
|
|
326
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
327
|
+
}
|
|
328
|
+
finally { if (e_2) throw e_2.error; }
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* The function sets the edges of a graph.
|
|
334
|
+
* @param v - A map where the keys are of type V and the values are arrays of type E.
|
|
335
|
+
*/
|
|
335
336
|
UndirectedGraph.prototype._setEdges = function (v) {
|
|
336
337
|
this._edges = v;
|
|
337
338
|
};
|
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
import { AbstractBinaryTreeNodeProperties, AbstractBinaryTreeNodeProperty, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../types';
|
|
2
2
|
import { AbstractBinaryTreeNode } from '../binary-tree';
|
|
3
|
-
export interface IAbstractBinaryTreeNode<T,
|
|
4
|
-
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
3
|
+
export interface IAbstractBinaryTreeNode<T, NEIGHBOR extends IAbstractBinaryTreeNode<T, NEIGHBOR>> {
|
|
5
4
|
get id(): BinaryTreeNodeId;
|
|
6
5
|
set id(v: BinaryTreeNodeId);
|
|
7
6
|
get val(): T | undefined;
|
|
8
7
|
set val(v: T | undefined);
|
|
9
|
-
get left():
|
|
10
|
-
set left(v:
|
|
11
|
-
get right():
|
|
12
|
-
set right(v:
|
|
13
|
-
get parent():
|
|
14
|
-
set parent(v:
|
|
8
|
+
get left(): NEIGHBOR | null | undefined;
|
|
9
|
+
set left(v: NEIGHBOR | null | undefined);
|
|
10
|
+
get right(): NEIGHBOR | null | undefined;
|
|
11
|
+
set right(v: NEIGHBOR | null | undefined);
|
|
12
|
+
get parent(): NEIGHBOR | null | undefined;
|
|
13
|
+
set parent(v: NEIGHBOR | null | undefined);
|
|
15
14
|
get familyPosition(): FamilyPosition;
|
|
16
|
-
set familyPosition(v: FamilyPosition);
|
|
17
|
-
get count(): number;
|
|
18
|
-
set count(v: number);
|
|
19
15
|
get height(): number;
|
|
20
16
|
set height(v: number);
|
|
21
|
-
swapLocation(swapNode: FAMILY): FAMILY;
|
|
22
|
-
clone(): FAMILY | null;
|
|
23
17
|
}
|
|
24
18
|
export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N>> {
|
|
25
|
-
createNode(id: BinaryTreeNodeId, val
|
|
19
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
|
|
26
20
|
get loopType(): LoopType;
|
|
27
21
|
get visitedId(): BinaryTreeNodeId[];
|
|
28
22
|
get visitedVal(): Array<N['val']>;
|
|
@@ -31,10 +25,10 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
31
25
|
get visitedLeftSum(): number[];
|
|
32
26
|
get autoIncrementId(): boolean;
|
|
33
27
|
get maxId(): number;
|
|
34
|
-
get
|
|
28
|
+
get isMergeDuplicatedVal(): boolean;
|
|
35
29
|
get root(): N | null;
|
|
36
30
|
get size(): number;
|
|
37
|
-
|
|
31
|
+
swapLocation(srcNode: N, destNode: N): N;
|
|
38
32
|
clear(): void;
|
|
39
33
|
isEmpty(): boolean;
|
|
40
34
|
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
@@ -45,7 +39,7 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
45
39
|
getDepth(node: N): number;
|
|
46
40
|
getHeight(beginRoot?: N | null): number;
|
|
47
41
|
getMinHeight(beginRoot?: N | null): number;
|
|
48
|
-
|
|
42
|
+
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
49
43
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
50
44
|
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
51
45
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
@@ -58,7 +52,7 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
|
|
|
58
52
|
getRightMost(node?: N | null): N | null;
|
|
59
53
|
isBSTByRooted(node: N | null): boolean;
|
|
60
54
|
isBST(node?: N | null): boolean;
|
|
61
|
-
|
|
55
|
+
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
62
56
|
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
63
57
|
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
64
58
|
BFS(): BinaryTreeNodeId[];
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { VertexId } from '../types';
|
|
2
2
|
export interface IAbstractGraph<V, E> {
|
|
3
3
|
hasVertex(vertexOrId: V | VertexId): boolean;
|
|
4
|
-
|
|
5
|
-
addVertex(newVertex: V): boolean;
|
|
4
|
+
addVertex(id: VertexId, val?: V): boolean;
|
|
6
5
|
removeVertex(vertexOrId: V | VertexId): boolean;
|
|
7
6
|
removeAllVertices(vertices: V[] | VertexId[]): boolean;
|
|
8
7
|
degreeOf(vertexOrId: V | VertexId): number;
|
|
@@ -10,8 +9,7 @@ export interface IAbstractGraph<V, E> {
|
|
|
10
9
|
hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
|
|
11
10
|
getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
|
|
12
11
|
edgeSet(): E[];
|
|
13
|
-
|
|
14
|
-
addEdge(edge: E): boolean;
|
|
12
|
+
addEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
|
|
15
13
|
removeEdge(edge: E): E | null;
|
|
16
14
|
setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
|
|
17
15
|
getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AVLTreeNode } from '../binary-tree';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
3
|
import { BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
|
|
4
|
-
export interface IAVLTreeNode<T,
|
|
4
|
+
export interface IAVLTreeNode<T, NEIGHBOR extends IAVLTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
5
|
}
|
|
6
6
|
export interface IAVLTree<N extends AVLTreeNode<N['val'], N>> extends IBST<N> {
|
|
7
|
-
add(id: BinaryTreeNodeId, val
|
|
7
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null): N | null | undefined;
|
|
8
8
|
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
9
9
|
balanceFactor(node: N): number;
|
|
10
10
|
updateHeight(node: N): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../binary-tree';
|
|
2
2
|
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
3
|
-
export interface IBinaryTreeNode<T,
|
|
3
|
+
export interface IBinaryTreeNode<T, NEIGHBOR extends IBinaryTreeNode<T, NEIGHBOR>> extends IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
4
4
|
}
|
|
5
5
|
export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> extends IAbstractBinaryTree<N> {
|
|
6
6
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { BSTNode } from '../binary-tree';
|
|
2
2
|
import { IBinaryTree, IBinaryTreeNode } from './binary-tree';
|
|
3
3
|
import { BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName } from '../types';
|
|
4
|
-
export interface IBSTNode<T,
|
|
5
|
-
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
4
|
+
export interface IBSTNode<T, NEIGHBOR extends IBSTNode<T, NEIGHBOR>> extends IBinaryTreeNode<T, NEIGHBOR> {
|
|
6
5
|
}
|
|
7
6
|
export interface IBST<N extends BSTNode<N['val'], N>> extends IBinaryTree<N> {
|
|
8
|
-
createNode(id: BinaryTreeNodeId, val?: N['val']
|
|
9
|
-
add(id: BinaryTreeNodeId, val
|
|
7
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
8
|
+
add(id: BinaryTreeNodeId, val?: N['val'] | null, count?: number): N | null | undefined;
|
|
10
9
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
11
10
|
lastKey(): BinaryTreeNodeId;
|
|
12
11
|
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
13
12
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
14
13
|
lesserSum(id: BinaryTreeNodeId, propertyName?: BinaryTreeNodePropertyName): number;
|
|
15
14
|
allGreaterNodesAdd(node: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
16
|
-
|
|
15
|
+
perfectlyBalance(): boolean;
|
|
17
16
|
isAVLBalanced(): boolean;
|
|
18
17
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { RBTreeNode } from '../binary-tree';
|
|
2
2
|
import { IBST, IBSTNode } from './bst';
|
|
3
3
|
import { BinaryTreeNodeId } from '../types';
|
|
4
|
-
export interface IRBTreeNode<T,
|
|
5
|
-
createNode(id: BinaryTreeNodeId, val?: T | null, count?: number): FAMILY;
|
|
4
|
+
export interface IRBTreeNode<T, NEIGHBOR extends IRBTreeNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
6
5
|
}
|
|
7
6
|
export interface IRBTree<N extends RBTreeNode<N['val'], N>> extends IBST<N> {
|
|
8
|
-
createNode(id: BinaryTreeNodeId, val?: N
|
|
7
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
9
8
|
}
|
|
@@ -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, NEIGHBOR extends ITreeMultisetNode<T, NEIGHBOR>> extends IBSTNode<T, NEIGHBOR> {
|
|
5
|
+
}
|
|
6
|
+
export interface ITreeMultiset<N extends TreeMultisetNode<N['val'], N>> extends IAVLTree<N> {
|
|
7
|
+
}
|
|
@@ -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,11 +10,15 @@ 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
|
-
export type BinaryTreeNodePropertyName = 'id' | 'val'
|
|
21
|
+
export type BinaryTreeNodePropertyName = 'id' | 'val';
|
|
18
22
|
export type NodeOrPropertyName = 'node' | BinaryTreeNodePropertyName;
|
|
19
23
|
export type DFSOrderPattern = 'in' | 'pre' | 'post';
|
|
20
24
|
export type BinaryTreeNodeId = number;
|
|
@@ -24,9 +28,9 @@ export type BinaryTreeDeletedResult<N> = {
|
|
|
24
28
|
};
|
|
25
29
|
export type AbstractBinaryTreeNodeProperty<N extends AbstractBinaryTreeNode<N['val'], N>> = N['val'] | N | number | BinaryTreeNodeId;
|
|
26
30
|
export type AbstractBinaryTreeNodeProperties<N extends AbstractBinaryTreeNode<N['val'], N>> = AbstractBinaryTreeNodeProperty<N>[];
|
|
27
|
-
export type
|
|
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 & {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { BinaryTreeNode } from '../binary-tree';
|
|
2
2
|
import { AbstractBinaryTreeOptions } from './abstract-binary-tree';
|
|
3
|
-
export type
|
|
3
|
+
export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
4
|
export type BinaryTreeOptions = AbstractBinaryTreeOptions & {};
|