data-structure-typed 1.48.4 → 1.48.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/cjs/data-structures/base/iterable-base.js +3 -3
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +16 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/cjs/data-structures/binary-tree/bst.js +17 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +52 -52
- package/dist/cjs/data-structures/graph/abstract-graph.js +78 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +47 -47
- package/dist/cjs/data-structures/graph/directed-graph.js +56 -56
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/cjs/data-structures/graph/map-graph.js +8 -8
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +29 -29
- package/dist/cjs/data-structures/graph/undirected-graph.js +57 -57
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +3 -3
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -6
- package/dist/mjs/data-structures/base/iterable-base.js +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +5 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +18 -15
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +17 -14
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -11
- package/dist/mjs/data-structures/binary-tree/bst.js +17 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +19 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +20 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +21 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +25 -18
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +52 -52
- package/dist/mjs/data-structures/graph/abstract-graph.js +79 -79
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +47 -47
- package/dist/mjs/data-structures/graph/directed-graph.js +56 -56
- package/dist/mjs/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/mjs/data-structures/graph/map-graph.js +8 -8
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +29 -29
- package/dist/mjs/data-structures/graph/undirected-graph.js +59 -59
- package/dist/mjs/data-structures/hash/hash-map.d.ts +8 -8
- package/dist/mjs/data-structures/hash/hash-map.js +3 -3
- package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/base/base.d.ts +3 -3
- package/dist/umd/data-structure-typed.js +302 -280
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree.ts +8 -5
- package/src/data-structures/binary-tree/binary-tree.ts +23 -19
- package/src/data-structures/binary-tree/bst.ts +19 -14
- package/src/data-structures/binary-tree/rb-tree.ts +20 -14
- package/src/data-structures/binary-tree/tree-multimap.ts +27 -19
- package/src/data-structures/graph/abstract-graph.ts +82 -82
- package/src/data-structures/graph/directed-graph.ts +56 -56
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +59 -59
- package/src/data-structures/hash/hash-map.ts +8 -8
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/base/base.ts +3 -3
- package/test/integration/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +3 -3
- package/test/unit/data-structures/graph/directed-graph.test.ts +15 -15
- package/test/unit/data-structures/graph/map-graph.test.ts +3 -3
- package/test/unit/data-structures/graph/undirected-graph.test.ts +12 -12
|
@@ -128,7 +128,7 @@ var dataStructureTyped = (() => {
|
|
|
128
128
|
HashTableNode: () => HashTableNode,
|
|
129
129
|
Heap: () => Heap,
|
|
130
130
|
IterableElementBase: () => IterableElementBase,
|
|
131
|
-
|
|
131
|
+
IterableEntryBase: () => IterableEntryBase,
|
|
132
132
|
IterationType: () => IterationType,
|
|
133
133
|
LinkedHashMap: () => LinkedHashMap,
|
|
134
134
|
LinkedListQueue: () => LinkedListQueue,
|
|
@@ -520,7 +520,7 @@ var dataStructureTyped = (() => {
|
|
|
520
520
|
var calcMinUnitsRequired = (totalQuantity, unitSize) => Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
521
521
|
|
|
522
522
|
// src/data-structures/base/iterable-base.ts
|
|
523
|
-
var
|
|
523
|
+
var IterableEntryBase = class {
|
|
524
524
|
/**
|
|
525
525
|
* Time Complexity: O(n)
|
|
526
526
|
* Space Complexity: O(1)
|
|
@@ -829,7 +829,7 @@ var dataStructureTyped = (() => {
|
|
|
829
829
|
};
|
|
830
830
|
|
|
831
831
|
// src/data-structures/hash/hash-map.ts
|
|
832
|
-
var HashMap = class _HashMap extends
|
|
832
|
+
var HashMap = class _HashMap extends IterableEntryBase {
|
|
833
833
|
/**
|
|
834
834
|
* The constructor function initializes a new instance of a class with optional elements and options.
|
|
835
835
|
* @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
|
|
@@ -1041,7 +1041,7 @@ var dataStructureTyped = (() => {
|
|
|
1041
1041
|
return strKey;
|
|
1042
1042
|
}
|
|
1043
1043
|
};
|
|
1044
|
-
var LinkedHashMap = class _LinkedHashMap extends
|
|
1044
|
+
var LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
|
|
1045
1045
|
constructor(elements, options = {
|
|
1046
1046
|
hashFn: (key) => String(key),
|
|
1047
1047
|
objHashFn: (key) => key
|
|
@@ -5420,13 +5420,13 @@ var dataStructureTyped = (() => {
|
|
|
5420
5420
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
5421
5421
|
*/
|
|
5422
5422
|
};
|
|
5423
|
-
var AbstractGraph = class extends
|
|
5423
|
+
var AbstractGraph = class extends IterableEntryBase {
|
|
5424
5424
|
constructor() {
|
|
5425
5425
|
super();
|
|
5426
|
-
__publicField(this, "
|
|
5426
|
+
__publicField(this, "_vertexMap", /* @__PURE__ */ new Map());
|
|
5427
5427
|
}
|
|
5428
|
-
get
|
|
5429
|
-
return this.
|
|
5428
|
+
get vertexMap() {
|
|
5429
|
+
return this._vertexMap;
|
|
5430
5430
|
}
|
|
5431
5431
|
/**
|
|
5432
5432
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
@@ -5438,12 +5438,12 @@ var dataStructureTyped = (() => {
|
|
|
5438
5438
|
*
|
|
5439
5439
|
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
5440
5440
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
5441
|
-
* the `
|
|
5442
|
-
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `
|
|
5441
|
+
* the `_vertexMap` map.
|
|
5442
|
+
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertexMap`
|
|
5443
5443
|
* map. If the vertex does not exist, it returns `undefined`.
|
|
5444
5444
|
*/
|
|
5445
5445
|
getVertex(vertexKey) {
|
|
5446
|
-
return this.
|
|
5446
|
+
return this._vertexMap.get(vertexKey) || void 0;
|
|
5447
5447
|
}
|
|
5448
5448
|
/**
|
|
5449
5449
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
@@ -5459,7 +5459,7 @@ var dataStructureTyped = (() => {
|
|
|
5459
5459
|
* @returns a boolean value.
|
|
5460
5460
|
*/
|
|
5461
5461
|
hasVertex(vertexOrKey) {
|
|
5462
|
-
return this.
|
|
5462
|
+
return this._vertexMap.has(this._getVertexKey(vertexOrKey));
|
|
5463
5463
|
}
|
|
5464
5464
|
/**
|
|
5465
5465
|
* Time Complexity: O(1) - Constant time for Map operations.
|
|
@@ -5492,25 +5492,25 @@ var dataStructureTyped = (() => {
|
|
|
5492
5492
|
*/
|
|
5493
5493
|
deleteVertex(vertexOrKey) {
|
|
5494
5494
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
5495
|
-
return this.
|
|
5495
|
+
return this._vertexMap.delete(vertexKey);
|
|
5496
5496
|
}
|
|
5497
5497
|
/**
|
|
5498
|
-
* Time Complexity: O(K), where K is the number of
|
|
5498
|
+
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
5499
5499
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
5500
5500
|
*/
|
|
5501
5501
|
/**
|
|
5502
|
-
* Time Complexity: O(K), where K is the number of
|
|
5502
|
+
* Time Complexity: O(K), where K is the number of vertexMap to be removed.
|
|
5503
5503
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
5504
5504
|
*
|
|
5505
|
-
* The function removes all
|
|
5506
|
-
* @param {VO[] | VertexKey[]}
|
|
5505
|
+
* The function removes all vertexMap from a graph and returns a boolean indicating if any vertexMap were removed.
|
|
5506
|
+
* @param {VO[] | VertexKey[]} vertexMap - The `vertexMap` parameter can be either an array of vertexMap (`VO[]`) or an array
|
|
5507
5507
|
* of vertex IDs (`VertexKey[]`).
|
|
5508
|
-
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no
|
|
5508
|
+
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertexMap
|
|
5509
5509
|
* were removed.
|
|
5510
5510
|
*/
|
|
5511
|
-
removeManyVertices(
|
|
5511
|
+
removeManyVertices(vertexMap) {
|
|
5512
5512
|
const removed = [];
|
|
5513
|
-
for (const v of
|
|
5513
|
+
for (const v of vertexMap) {
|
|
5514
5514
|
removed.push(this.deleteVertex(v));
|
|
5515
5515
|
}
|
|
5516
5516
|
return removed.length > 0;
|
|
@@ -5523,7 +5523,7 @@ var dataStructureTyped = (() => {
|
|
|
5523
5523
|
* Time Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
5524
5524
|
* Space Complexity: O(1) - Depends on the implementation in the concrete class.
|
|
5525
5525
|
*
|
|
5526
|
-
* The function checks if there is an edge between two
|
|
5526
|
+
* The function checks if there is an edge between two vertexMap and returns a boolean value indicating the result.
|
|
5527
5527
|
* @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
|
|
5528
5528
|
* identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
|
|
5529
5529
|
* @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
|
|
@@ -5564,14 +5564,14 @@ var dataStructureTyped = (() => {
|
|
|
5564
5564
|
* Time Complexity: O(1) - Constant time for Map and Edge operations.
|
|
5565
5565
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
5566
5566
|
*
|
|
5567
|
-
* The function sets the weight of an edge between two
|
|
5567
|
+
* The function sets the weight of an edge between two vertexMap in a graph.
|
|
5568
5568
|
* @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
|
|
5569
5569
|
* the source vertex of the edge.
|
|
5570
5570
|
* @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
|
|
5571
5571
|
* either a `VertexKey` or a vertex object `VO`.
|
|
5572
5572
|
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
|
|
5573
5573
|
* and the destination vertex (destOrKey).
|
|
5574
|
-
* @returns a boolean value. If the edge exists between the source and destination
|
|
5574
|
+
* @returns a boolean value. If the edge exists between the source and destination vertexMap, the function will update
|
|
5575
5575
|
* the weight of the edge and return true. If the edge does not exist, the function will return false.
|
|
5576
5576
|
*/
|
|
5577
5577
|
setEdgeWeight(srcOrKey, destOrKey, weight) {
|
|
@@ -5591,12 +5591,12 @@ var dataStructureTyped = (() => {
|
|
|
5591
5591
|
* Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
|
|
5592
5592
|
* Space Complexity: O(P) - Linear space, where P is the number of paths found.
|
|
5593
5593
|
*
|
|
5594
|
-
* The function `getAllPathsBetween` finds all paths between two
|
|
5594
|
+
* The function `getAllPathsBetween` finds all paths between two vertexMap in a graph using depth-first search.
|
|
5595
5595
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
5596
5596
|
* It is the starting vertex for finding paths.
|
|
5597
5597
|
* @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
5598
5598
|
* @param limit - The count of limitation of result array.
|
|
5599
|
-
* @returns The function `getAllPathsBetween` returns an array of arrays of
|
|
5599
|
+
* @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
|
|
5600
5600
|
*/
|
|
5601
5601
|
getAllPathsBetween(v1, v2, limit = 1e3) {
|
|
5602
5602
|
const paths = [];
|
|
@@ -5633,8 +5633,8 @@ var dataStructureTyped = (() => {
|
|
|
5633
5633
|
* Space Complexity: O(1) - Constant space.
|
|
5634
5634
|
*
|
|
5635
5635
|
* The function calculates the sum of weights along a given path.
|
|
5636
|
-
* @param {VO[]} path - An array of
|
|
5637
|
-
* @returns The function `getPathSumWeight` returns the sum of the weights of the
|
|
5636
|
+
* @param {VO[]} path - An array of vertexMap (VO) representing a path in a graph.
|
|
5637
|
+
* @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
|
|
5638
5638
|
*/
|
|
5639
5639
|
getPathSumWeight(path) {
|
|
5640
5640
|
var _a;
|
|
@@ -5652,17 +5652,17 @@ var dataStructureTyped = (() => {
|
|
|
5652
5652
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
5653
5653
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
5654
5654
|
*
|
|
5655
|
-
* The function `getMinCostBetween` calculates the minimum cost between two
|
|
5655
|
+
* The function `getMinCostBetween` calculates the minimum cost between two vertexMap in a graph, either based on edge
|
|
5656
5656
|
* weights or using a breadth-first search algorithm.
|
|
5657
5657
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
|
|
5658
5658
|
* @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
|
|
5659
5659
|
* you want to find the minimum cost or weight from the source vertex `v1`.
|
|
5660
|
-
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph
|
|
5660
|
+
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edgeMap have weights.
|
|
5661
5661
|
* If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
|
|
5662
|
-
* the
|
|
5663
|
-
* @returns The function `getMinCostBetween` returns a number representing the minimum cost between two
|
|
5662
|
+
* the edgeMap. If isWeight is set to false or not provided, the function will calculate the
|
|
5663
|
+
* @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertexMap (`v1`
|
|
5664
5664
|
* and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
|
|
5665
|
-
*
|
|
5665
|
+
* vertexMap. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
5666
5666
|
* minimum number of
|
|
5667
5667
|
*/
|
|
5668
5668
|
getMinCostBetween(v1, v2, isWeight) {
|
|
@@ -5714,20 +5714,20 @@ var dataStructureTyped = (() => {
|
|
|
5714
5714
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
5715
5715
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
5716
5716
|
*
|
|
5717
|
-
* The function `getMinPathBetween` returns the minimum path between two
|
|
5717
|
+
* The function `getMinPathBetween` returns the minimum path between two vertexMap in a graph, either based on weight or
|
|
5718
5718
|
* using a breadth-first search algorithm.
|
|
5719
5719
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
|
|
5720
5720
|
* object (`VO`) or a vertex ID (`VertexKey`).
|
|
5721
5721
|
* @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
|
|
5722
5722
|
* path.
|
|
5723
|
-
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of
|
|
5723
|
+
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edgeMap in finding the
|
|
5724
5724
|
* minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
|
|
5725
5725
|
* to false, the function will use breadth-first search (BFS) to find the minimum path.
|
|
5726
5726
|
* @param isDFS - If set to true, it enforces the use of getAllPathsBetween to first obtain all possible paths,
|
|
5727
5727
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
5728
5728
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
5729
|
-
* @returns The function `getMinPathBetween` returns an array of
|
|
5730
|
-
* two
|
|
5729
|
+
* @returns The function `getMinPathBetween` returns an array of vertexMap (`VO[]`) representing the minimum path between
|
|
5730
|
+
* two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
|
|
5731
5731
|
*/
|
|
5732
5732
|
getMinPathBetween(v1, v2, isWeight, isDFS = false) {
|
|
5733
5733
|
var _a, _b;
|
|
@@ -5789,7 +5789,7 @@ var dataStructureTyped = (() => {
|
|
|
5789
5789
|
* Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
|
|
5790
5790
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
|
|
5791
5791
|
*
|
|
5792
|
-
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two
|
|
5792
|
+
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertexMap in
|
|
5793
5793
|
* a graph without using a heap data structure.
|
|
5794
5794
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
5795
5795
|
* vertex object or a vertex ID.
|
|
@@ -5801,7 +5801,7 @@ var dataStructureTyped = (() => {
|
|
|
5801
5801
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
5802
5802
|
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
5803
5803
|
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
5804
|
-
* shortest paths from the source vertex to all other
|
|
5804
|
+
* shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
|
|
5805
5805
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
5806
5806
|
*/
|
|
5807
5807
|
dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
|
|
@@ -5815,7 +5815,7 @@ var dataStructureTyped = (() => {
|
|
|
5815
5815
|
let minDest = void 0;
|
|
5816
5816
|
let minPath = [];
|
|
5817
5817
|
const paths = [];
|
|
5818
|
-
const
|
|
5818
|
+
const vertexMap = this._vertexMap;
|
|
5819
5819
|
const distMap = /* @__PURE__ */ new Map();
|
|
5820
5820
|
const seen = /* @__PURE__ */ new Set();
|
|
5821
5821
|
const preMap = /* @__PURE__ */ new Map();
|
|
@@ -5824,7 +5824,7 @@ var dataStructureTyped = (() => {
|
|
|
5824
5824
|
if (!srcVertex) {
|
|
5825
5825
|
return void 0;
|
|
5826
5826
|
}
|
|
5827
|
-
for (const vertex of
|
|
5827
|
+
for (const vertex of vertexMap) {
|
|
5828
5828
|
const vertexOrKey = vertex[1];
|
|
5829
5829
|
if (vertexOrKey instanceof AbstractVertex)
|
|
5830
5830
|
distMap.set(vertexOrKey, Infinity);
|
|
@@ -5845,7 +5845,7 @@ var dataStructureTyped = (() => {
|
|
|
5845
5845
|
return minV;
|
|
5846
5846
|
};
|
|
5847
5847
|
const getPaths = (minV) => {
|
|
5848
|
-
for (const vertex of
|
|
5848
|
+
for (const vertex of vertexMap) {
|
|
5849
5849
|
const vertexOrKey = vertex[1];
|
|
5850
5850
|
if (vertexOrKey instanceof AbstractVertex) {
|
|
5851
5851
|
const path = [vertexOrKey];
|
|
@@ -5861,7 +5861,7 @@ var dataStructureTyped = (() => {
|
|
|
5861
5861
|
}
|
|
5862
5862
|
}
|
|
5863
5863
|
};
|
|
5864
|
-
for (let i = 1; i <
|
|
5864
|
+
for (let i = 1; i < vertexMap.size; i++) {
|
|
5865
5865
|
const cur = getMinOfNoSeen();
|
|
5866
5866
|
if (cur) {
|
|
5867
5867
|
seen.add(cur);
|
|
@@ -5908,7 +5908,7 @@ var dataStructureTyped = (() => {
|
|
|
5908
5908
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
5909
5909
|
*
|
|
5910
5910
|
* Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
|
|
5911
|
-
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight
|
|
5911
|
+
* Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
|
|
5912
5912
|
* The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
|
|
5913
5913
|
*
|
|
5914
5914
|
* /
|
|
@@ -5928,13 +5928,13 @@ var dataStructureTyped = (() => {
|
|
|
5928
5928
|
* start. It can be either a vertex object or a vertex ID.
|
|
5929
5929
|
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
5930
5930
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
5931
|
-
* will calculate the shortest paths to all other
|
|
5931
|
+
* will calculate the shortest paths to all other vertexMap from the source vertex.
|
|
5932
5932
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
5933
5933
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
5934
5934
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
5935
5935
|
* @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
|
|
5936
5936
|
* paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
|
|
5937
|
-
* shortest paths from the source vertex to all other
|
|
5937
|
+
* shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
|
|
5938
5938
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
5939
5939
|
*/
|
|
5940
5940
|
dijkstra(src, dest, getMinDist, genPaths) {
|
|
@@ -5949,7 +5949,7 @@ var dataStructureTyped = (() => {
|
|
|
5949
5949
|
let minDest = void 0;
|
|
5950
5950
|
let minPath = [];
|
|
5951
5951
|
const paths = [];
|
|
5952
|
-
const
|
|
5952
|
+
const vertexMap = this._vertexMap;
|
|
5953
5953
|
const distMap = /* @__PURE__ */ new Map();
|
|
5954
5954
|
const seen = /* @__PURE__ */ new Set();
|
|
5955
5955
|
const preMap = /* @__PURE__ */ new Map();
|
|
@@ -5957,7 +5957,7 @@ var dataStructureTyped = (() => {
|
|
|
5957
5957
|
const destVertex = dest ? this._getVertex(dest) : void 0;
|
|
5958
5958
|
if (!srcVertex)
|
|
5959
5959
|
return void 0;
|
|
5960
|
-
for (const vertex of
|
|
5960
|
+
for (const vertex of vertexMap) {
|
|
5961
5961
|
const vertexOrKey = vertex[1];
|
|
5962
5962
|
if (vertexOrKey instanceof AbstractVertex)
|
|
5963
5963
|
distMap.set(vertexOrKey, Infinity);
|
|
@@ -5967,7 +5967,7 @@ var dataStructureTyped = (() => {
|
|
|
5967
5967
|
distMap.set(srcVertex, 0);
|
|
5968
5968
|
preMap.set(srcVertex, void 0);
|
|
5969
5969
|
const getPaths = (minV) => {
|
|
5970
|
-
for (const vertex of
|
|
5970
|
+
for (const vertex of vertexMap) {
|
|
5971
5971
|
const vertexOrKey = vertex[1];
|
|
5972
5972
|
if (vertexOrKey instanceof AbstractVertex) {
|
|
5973
5973
|
const path = [vertexOrKey];
|
|
@@ -6045,16 +6045,16 @@ var dataStructureTyped = (() => {
|
|
|
6045
6045
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
6046
6046
|
*
|
|
6047
6047
|
* one to rest pairs
|
|
6048
|
-
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all
|
|
6048
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
6049
6049
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
6050
|
-
* all other
|
|
6050
|
+
* all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
|
|
6051
6051
|
* @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
|
|
6052
6052
|
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.
|
|
6053
6053
|
* @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
|
|
6054
6054
|
* @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
|
|
6055
|
-
* calculate the minimum distance from the source vertex to all other
|
|
6055
|
+
* calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
|
|
6056
6056
|
* `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
|
|
6057
|
-
* @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all
|
|
6057
|
+
* @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
|
|
6058
6058
|
* vertex.
|
|
6059
6059
|
* @returns The function `bellmanFord` returns an object with the following properties:
|
|
6060
6060
|
*/
|
|
@@ -6074,20 +6074,20 @@ var dataStructureTyped = (() => {
|
|
|
6074
6074
|
hasNegativeCycle = false;
|
|
6075
6075
|
if (!srcVertex)
|
|
6076
6076
|
return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
|
|
6077
|
-
const
|
|
6078
|
-
const numOfVertices =
|
|
6079
|
-
const
|
|
6080
|
-
const numOfEdges =
|
|
6081
|
-
this.
|
|
6077
|
+
const vertexMap = this._vertexMap;
|
|
6078
|
+
const numOfVertices = vertexMap.size;
|
|
6079
|
+
const edgeMap = this.edgeSet();
|
|
6080
|
+
const numOfEdges = edgeMap.length;
|
|
6081
|
+
this._vertexMap.forEach((vertex) => {
|
|
6082
6082
|
distMap.set(vertex, Infinity);
|
|
6083
6083
|
});
|
|
6084
6084
|
distMap.set(srcVertex, 0);
|
|
6085
6085
|
for (let i = 1; i < numOfVertices; ++i) {
|
|
6086
6086
|
for (let j = 0; j < numOfEdges; ++j) {
|
|
6087
|
-
const ends = this.getEndsOfEdge(
|
|
6087
|
+
const ends = this.getEndsOfEdge(edgeMap[j]);
|
|
6088
6088
|
if (ends) {
|
|
6089
6089
|
const [s, d] = ends;
|
|
6090
|
-
const weight =
|
|
6090
|
+
const weight = edgeMap[j].weight;
|
|
6091
6091
|
const sWeight = distMap.get(s);
|
|
6092
6092
|
const dWeight = distMap.get(d);
|
|
6093
6093
|
if (sWeight !== void 0 && dWeight !== void 0) {
|
|
@@ -6112,7 +6112,7 @@ var dataStructureTyped = (() => {
|
|
|
6112
6112
|
});
|
|
6113
6113
|
}
|
|
6114
6114
|
if (genPath) {
|
|
6115
|
-
for (const vertex of
|
|
6115
|
+
for (const vertex of vertexMap) {
|
|
6116
6116
|
const vertexOrKey = vertex[1];
|
|
6117
6117
|
if (vertexOrKey instanceof AbstractVertex) {
|
|
6118
6118
|
const path = [vertexOrKey];
|
|
@@ -6129,10 +6129,10 @@ var dataStructureTyped = (() => {
|
|
|
6129
6129
|
}
|
|
6130
6130
|
}
|
|
6131
6131
|
for (let j = 0; j < numOfEdges; ++j) {
|
|
6132
|
-
const ends = this.getEndsOfEdge(
|
|
6132
|
+
const ends = this.getEndsOfEdge(edgeMap[j]);
|
|
6133
6133
|
if (ends) {
|
|
6134
6134
|
const [s] = ends;
|
|
6135
|
-
const weight =
|
|
6135
|
+
const weight = edgeMap[j].weight;
|
|
6136
6136
|
const sWeight = distMap.get(s);
|
|
6137
6137
|
if (sWeight) {
|
|
6138
6138
|
if (sWeight !== Infinity && sWeight + weight < sWeight)
|
|
@@ -6153,7 +6153,7 @@ var dataStructureTyped = (() => {
|
|
|
6153
6153
|
/**
|
|
6154
6154
|
* BellmanFord time:O(VE) space:O(VO)
|
|
6155
6155
|
* one to rest pairs
|
|
6156
|
-
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all
|
|
6156
|
+
* The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
6157
6157
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
6158
6158
|
*/
|
|
6159
6159
|
/**
|
|
@@ -6161,7 +6161,7 @@ var dataStructureTyped = (() => {
|
|
|
6161
6161
|
* Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
|
|
6162
6162
|
* Not support graph with negative weight cycle
|
|
6163
6163
|
* all pairs
|
|
6164
|
-
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight
|
|
6164
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
|
|
6165
6165
|
* /
|
|
6166
6166
|
|
|
6167
6167
|
/**
|
|
@@ -6170,17 +6170,17 @@ var dataStructureTyped = (() => {
|
|
|
6170
6170
|
*
|
|
6171
6171
|
* Not support graph with negative weight cycle
|
|
6172
6172
|
* all pairs
|
|
6173
|
-
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight
|
|
6174
|
-
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of
|
|
6173
|
+
* The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
|
|
6174
|
+
* The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
|
|
6175
6175
|
* graph.
|
|
6176
6176
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
6177
|
-
* property is a 2D array of numbers representing the shortest path costs between
|
|
6178
|
-
* `predecessor` property is a 2D array of
|
|
6179
|
-
* path between
|
|
6177
|
+
* property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
|
|
6178
|
+
* `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
|
|
6179
|
+
* path between vertexMap in the
|
|
6180
6180
|
*/
|
|
6181
6181
|
floydWarshall() {
|
|
6182
6182
|
var _a;
|
|
6183
|
-
const idAndVertices = [...this.
|
|
6183
|
+
const idAndVertices = [...this._vertexMap];
|
|
6184
6184
|
const n = idAndVertices.length;
|
|
6185
6185
|
const costs = [];
|
|
6186
6186
|
const predecessor = [];
|
|
@@ -6213,7 +6213,7 @@ var dataStructureTyped = (() => {
|
|
|
6213
6213
|
* Space Complexity: O(V) - Linear space (Tarjan's algorithm).
|
|
6214
6214
|
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
6215
6215
|
* Tarjan can find cycles in directed or undirected graph
|
|
6216
|
-
* Tarjan can find the articulation points and bridges(critical
|
|
6216
|
+
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
6217
6217
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
6218
6218
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
6219
6219
|
* /
|
|
@@ -6224,22 +6224,22 @@ var dataStructureTyped = (() => {
|
|
|
6224
6224
|
*
|
|
6225
6225
|
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
6226
6226
|
* Tarjan can find cycles in directed or undirected graph
|
|
6227
|
-
* Tarjan can find the articulation points and bridges(critical
|
|
6227
|
+
* Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time,
|
|
6228
6228
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
6229
6229
|
* Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
|
|
6230
6230
|
* The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
|
|
6231
6231
|
* strongly connected components (SCCs), and cycles in a graph.
|
|
6232
6232
|
* @param {boolean} [needCutVertexes] - A boolean value indicating whether or not to calculate and return the
|
|
6233
|
-
* articulation points in the graph. Articulation points are the
|
|
6233
|
+
* articulation points in the graph. Articulation points are the vertexMap in a graph whose removal would increase the
|
|
6234
6234
|
* number of connected components in the graph.
|
|
6235
6235
|
* @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
|
|
6236
|
-
* (
|
|
6236
|
+
* (edgeMap whose removal would increase the number of connected components in the graph).
|
|
6237
6237
|
* @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
|
|
6238
6238
|
* graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
|
|
6239
6239
|
* SCCs will not be calculated or returned.
|
|
6240
6240
|
* @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
|
|
6241
6241
|
* set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
|
|
6242
|
-
* are arrays of
|
|
6242
|
+
* are arrays of vertexMap that form cycles within the SCCs.
|
|
6243
6243
|
* @returns The function `tarjan` returns an object with the following properties:
|
|
6244
6244
|
*/
|
|
6245
6245
|
tarjan(needCutVertexes = false, needBridges = false, needSCCs = true, needCycles = false) {
|
|
@@ -6254,12 +6254,12 @@ var dataStructureTyped = (() => {
|
|
|
6254
6254
|
needCycles = defaultConfig;
|
|
6255
6255
|
const dfnMap = /* @__PURE__ */ new Map();
|
|
6256
6256
|
const lowMap = /* @__PURE__ */ new Map();
|
|
6257
|
-
const
|
|
6258
|
-
|
|
6257
|
+
const vertexMap = this._vertexMap;
|
|
6258
|
+
vertexMap.forEach((v) => {
|
|
6259
6259
|
dfnMap.set(v, -1);
|
|
6260
6260
|
lowMap.set(v, Infinity);
|
|
6261
6261
|
});
|
|
6262
|
-
const [root] =
|
|
6262
|
+
const [root] = vertexMap.values();
|
|
6263
6263
|
const cutVertexes = [];
|
|
6264
6264
|
const bridges = [];
|
|
6265
6265
|
let dfn = 0;
|
|
@@ -6441,7 +6441,7 @@ var dataStructureTyped = (() => {
|
|
|
6441
6441
|
return mapped;
|
|
6442
6442
|
}
|
|
6443
6443
|
*_getIterator() {
|
|
6444
|
-
for (const vertex of this.
|
|
6444
|
+
for (const vertex of this._vertexMap.values()) {
|
|
6445
6445
|
yield [vertex.key, vertex.value];
|
|
6446
6446
|
}
|
|
6447
6447
|
}
|
|
@@ -6449,12 +6449,12 @@ var dataStructureTyped = (() => {
|
|
|
6449
6449
|
if (this.hasVertex(newVertex)) {
|
|
6450
6450
|
return false;
|
|
6451
6451
|
}
|
|
6452
|
-
this.
|
|
6452
|
+
this._vertexMap.set(newVertex.key, newVertex);
|
|
6453
6453
|
return true;
|
|
6454
6454
|
}
|
|
6455
6455
|
_getVertex(vertexOrKey) {
|
|
6456
6456
|
const vertexKey = this._getVertexKey(vertexOrKey);
|
|
6457
|
-
return this.
|
|
6457
|
+
return this._vertexMap.get(vertexKey) || void 0;
|
|
6458
6458
|
}
|
|
6459
6459
|
_getVertexKey(vertexOrKey) {
|
|
6460
6460
|
return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
|
|
@@ -6476,7 +6476,7 @@ var dataStructureTyped = (() => {
|
|
|
6476
6476
|
};
|
|
6477
6477
|
var DirectedEdge = class extends AbstractEdge {
|
|
6478
6478
|
/**
|
|
6479
|
-
* The constructor function initializes the source and destination
|
|
6479
|
+
* The constructor function initializes the source and destination vertexMap of an edge, along with an optional weight
|
|
6480
6480
|
* and value.
|
|
6481
6481
|
* @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
|
|
6482
6482
|
* a graph.
|
|
@@ -6516,7 +6516,7 @@ var dataStructureTyped = (() => {
|
|
|
6516
6516
|
/**
|
|
6517
6517
|
* The function creates a new vertex with an optional value and returns it.
|
|
6518
6518
|
* @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
|
|
6519
|
-
* could be a number or a string depending on how you want to identify your
|
|
6519
|
+
* could be a number or a string depending on how you want to identify your vertexMap.
|
|
6520
6520
|
* @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
|
|
6521
6521
|
* it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
|
|
6522
6522
|
* assigned the same value as the 'key' parameter
|
|
@@ -6530,7 +6530,7 @@ var dataStructureTyped = (() => {
|
|
|
6530
6530
|
* This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
|
|
6531
6531
|
*/
|
|
6532
6532
|
/**
|
|
6533
|
-
* The function creates a directed edge between two
|
|
6533
|
+
* The function creates a directed edge between two vertexMap with an optional weight and value.
|
|
6534
6534
|
* @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
|
|
6535
6535
|
* @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
|
|
6536
6536
|
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
|
|
@@ -6543,43 +6543,43 @@ var dataStructureTyped = (() => {
|
|
|
6543
6543
|
return new DirectedEdge(src, dest, weight != null ? weight : 1, value);
|
|
6544
6544
|
}
|
|
6545
6545
|
/**
|
|
6546
|
-
* Time Complexity: O(|V|) where |V| is the number of
|
|
6546
|
+
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
6547
6547
|
* Space Complexity: O(1)
|
|
6548
6548
|
*/
|
|
6549
6549
|
/**
|
|
6550
|
-
* Time Complexity: O(|V|) where |V| is the number of
|
|
6550
|
+
* Time Complexity: O(|V|) where |V| is the number of vertexMap
|
|
6551
6551
|
* Space Complexity: O(1)
|
|
6552
6552
|
*
|
|
6553
|
-
* The `getEdge` function retrieves an edge between two
|
|
6553
|
+
* The `getEdge` function retrieves an edge between two vertexMap based on their source and destination IDs.
|
|
6554
6554
|
* @param {VO | VertexKey | undefined} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
|
|
6555
6555
|
* @param {VO | VertexKey | undefined} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
|
|
6556
6556
|
* destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `undefined` if the
|
|
6557
6557
|
* destination is not specified.
|
|
6558
|
-
* @returns the first edge found between the source and destination
|
|
6558
|
+
* @returns the first edge found between the source and destination vertexMap, or undefined if no such edge is found.
|
|
6559
6559
|
*/
|
|
6560
6560
|
getEdge(srcOrKey, destOrKey) {
|
|
6561
|
-
let
|
|
6561
|
+
let edgeMap = [];
|
|
6562
6562
|
if (srcOrKey !== void 0 && destOrKey !== void 0) {
|
|
6563
6563
|
const src = this._getVertex(srcOrKey);
|
|
6564
6564
|
const dest = this._getVertex(destOrKey);
|
|
6565
6565
|
if (src && dest) {
|
|
6566
6566
|
const srcOutEdges = this._outEdgeMap.get(src);
|
|
6567
6567
|
if (srcOutEdges) {
|
|
6568
|
-
|
|
6568
|
+
edgeMap = srcOutEdges.filter((edge) => edge.dest === dest.key);
|
|
6569
6569
|
}
|
|
6570
6570
|
}
|
|
6571
6571
|
}
|
|
6572
|
-
return
|
|
6572
|
+
return edgeMap[0] || void 0;
|
|
6573
6573
|
}
|
|
6574
6574
|
/**
|
|
6575
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6575
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6576
6576
|
* Space Complexity: O(1)
|
|
6577
6577
|
*/
|
|
6578
6578
|
/**
|
|
6579
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6579
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6580
6580
|
* Space Complexity: O(1)
|
|
6581
6581
|
*
|
|
6582
|
-
* The function removes an edge between two
|
|
6582
|
+
* The function removes an edge between two vertexMap in a graph and returns the removed edge.
|
|
6583
6583
|
* @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
|
|
6584
6584
|
* @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
|
|
6585
6585
|
* @returns the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.
|
|
@@ -6602,11 +6602,11 @@ var dataStructureTyped = (() => {
|
|
|
6602
6602
|
return removed;
|
|
6603
6603
|
}
|
|
6604
6604
|
/**
|
|
6605
|
-
* Time Complexity: O(E) where E is the number of
|
|
6605
|
+
* Time Complexity: O(E) where E is the number of edgeMap
|
|
6606
6606
|
* Space Complexity: O(1)
|
|
6607
6607
|
*/
|
|
6608
6608
|
/**
|
|
6609
|
-
* Time Complexity: O(E) where E is the number of
|
|
6609
|
+
* Time Complexity: O(E) where E is the number of edgeMap
|
|
6610
6610
|
* Space Complexity: O(1)
|
|
6611
6611
|
*
|
|
6612
6612
|
* The `deleteEdge` function removes an edge from a graph and returns the removed edge.
|
|
@@ -6671,22 +6671,22 @@ var dataStructureTyped = (() => {
|
|
|
6671
6671
|
this._outEdgeMap.delete(vertex);
|
|
6672
6672
|
this._inEdgeMap.delete(vertex);
|
|
6673
6673
|
}
|
|
6674
|
-
return this.
|
|
6674
|
+
return this._vertexMap.delete(vertexKey);
|
|
6675
6675
|
}
|
|
6676
6676
|
/**
|
|
6677
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6677
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6678
6678
|
* Space Complexity: O(1)
|
|
6679
6679
|
*/
|
|
6680
6680
|
/**
|
|
6681
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6681
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6682
6682
|
* Space Complexity: O(1)
|
|
6683
6683
|
*
|
|
6684
|
-
* The function removes
|
|
6684
|
+
* The function removes edgeMap between two vertexMap and returns the removed edgeMap.
|
|
6685
6685
|
* @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
|
|
6686
6686
|
* unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
|
|
6687
6687
|
* @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
|
|
6688
6688
|
* the second vertex in the edge that needs to be removed.
|
|
6689
|
-
* @returns an array of removed
|
|
6689
|
+
* @returns an array of removed edgeMap (EO[]).
|
|
6690
6690
|
*/
|
|
6691
6691
|
deleteEdgesBetween(v1, v2) {
|
|
6692
6692
|
const removed = [];
|
|
@@ -6706,10 +6706,10 @@ var dataStructureTyped = (() => {
|
|
|
6706
6706
|
* Time Complexity: O(1)
|
|
6707
6707
|
* Space Complexity: O(1)
|
|
6708
6708
|
*
|
|
6709
|
-
* The function `incomingEdgesOf` returns an array of incoming
|
|
6709
|
+
* The function `incomingEdgesOf` returns an array of incoming edgeMap for a given vertex or vertex ID.
|
|
6710
6710
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
6711
6711
|
* (`VertexKey`).
|
|
6712
|
-
* @returns The method `incomingEdgesOf` returns an array of
|
|
6712
|
+
* @returns The method `incomingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
6713
6713
|
*/
|
|
6714
6714
|
incomingEdgesOf(vertexOrKey) {
|
|
6715
6715
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -6726,10 +6726,10 @@ var dataStructureTyped = (() => {
|
|
|
6726
6726
|
* Time Complexity: O(1)
|
|
6727
6727
|
* Space Complexity: O(1)
|
|
6728
6728
|
*
|
|
6729
|
-
* The function `outgoingEdgesOf` returns an array of outgoing
|
|
6729
|
+
* The function `outgoingEdgesOf` returns an array of outgoing edgeMap from a given vertex or vertex ID.
|
|
6730
6730
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
|
|
6731
6731
|
* (`VertexKey`).
|
|
6732
|
-
* @returns The method `outgoingEdgesOf` returns an array of
|
|
6732
|
+
* @returns The method `outgoingEdgesOf` returns an array of edgeMap (`EO[]`).
|
|
6733
6733
|
*/
|
|
6734
6734
|
outgoingEdgesOf(vertexOrKey) {
|
|
6735
6735
|
const target = this._getVertex(vertexOrKey);
|
|
@@ -6761,9 +6761,9 @@ var dataStructureTyped = (() => {
|
|
|
6761
6761
|
* Time Complexity: O(1)
|
|
6762
6762
|
* Space Complexity: O(1)
|
|
6763
6763
|
*
|
|
6764
|
-
* The function "inDegreeOf" returns the number of incoming
|
|
6764
|
+
* The function "inDegreeOf" returns the number of incoming edgeMap for a given vertex.
|
|
6765
6765
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
6766
|
-
* @returns The number of incoming
|
|
6766
|
+
* @returns The number of incoming edgeMap of the specified vertex or vertex ID.
|
|
6767
6767
|
*/
|
|
6768
6768
|
inDegreeOf(vertexOrKey) {
|
|
6769
6769
|
return this.incomingEdgesOf(vertexOrKey).length;
|
|
@@ -6776,9 +6776,9 @@ var dataStructureTyped = (() => {
|
|
|
6776
6776
|
* Time Complexity: O(1)
|
|
6777
6777
|
* Space Complexity: O(1)
|
|
6778
6778
|
*
|
|
6779
|
-
* The function `outDegreeOf` returns the number of outgoing
|
|
6779
|
+
* The function `outDegreeOf` returns the number of outgoing edgeMap from a given vertex.
|
|
6780
6780
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
6781
|
-
* @returns The number of outgoing
|
|
6781
|
+
* @returns The number of outgoing edgeMap from the specified vertex or vertex ID.
|
|
6782
6782
|
*/
|
|
6783
6783
|
outDegreeOf(vertexOrKey) {
|
|
6784
6784
|
return this.outgoingEdgesOf(vertexOrKey).length;
|
|
@@ -6791,9 +6791,9 @@ var dataStructureTyped = (() => {
|
|
|
6791
6791
|
* Time Complexity: O(1)
|
|
6792
6792
|
* Space Complexity: O(1)
|
|
6793
6793
|
*
|
|
6794
|
-
* The function "edgesOf" returns an array of both outgoing and incoming
|
|
6794
|
+
* The function "edgesOf" returns an array of both outgoing and incoming edgeMap of a given vertex or vertex ID.
|
|
6795
6795
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
6796
|
-
* @returns The function `edgesOf` returns an array of
|
|
6796
|
+
* @returns The function `edgesOf` returns an array of edgeMap.
|
|
6797
6797
|
*/
|
|
6798
6798
|
edgesOf(vertexOrKey) {
|
|
6799
6799
|
return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
|
|
@@ -6829,17 +6829,17 @@ var dataStructureTyped = (() => {
|
|
|
6829
6829
|
return this._getVertex(e.dest);
|
|
6830
6830
|
}
|
|
6831
6831
|
/**
|
|
6832
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6832
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6833
6833
|
* Space Complexity: O(1)
|
|
6834
6834
|
*/
|
|
6835
6835
|
/**
|
|
6836
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6836
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6837
6837
|
* Space Complexity: O(1)
|
|
6838
6838
|
*
|
|
6839
|
-
* The function `getDestinations` returns an array of destination
|
|
6839
|
+
* The function `getDestinations` returns an array of destination vertexMap connected to a given vertex.
|
|
6840
6840
|
* @param {VO | VertexKey | undefined} vertex - The `vertex` parameter represents the starting vertex from which we want to
|
|
6841
6841
|
* find the destinations. It can be either a `VO` object, a `VertexKey` value, or `undefined`.
|
|
6842
|
-
* @returns an array of
|
|
6842
|
+
* @returns an array of vertexMap (VO[]).
|
|
6843
6843
|
*/
|
|
6844
6844
|
getDestinations(vertex) {
|
|
6845
6845
|
if (vertex === void 0) {
|
|
@@ -6856,24 +6856,24 @@ var dataStructureTyped = (() => {
|
|
|
6856
6856
|
return destinations;
|
|
6857
6857
|
}
|
|
6858
6858
|
/**
|
|
6859
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of
|
|
6859
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
6860
6860
|
* Space Complexity: O(|V|)
|
|
6861
6861
|
*/
|
|
6862
6862
|
/**
|
|
6863
|
-
* Time Complexity: O(|V| + |E|) where |V| is the number of
|
|
6863
|
+
* Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
|
|
6864
6864
|
* Space Complexity: O(|V|)
|
|
6865
6865
|
*
|
|
6866
|
-
* The `topologicalSort` function performs a topological sort on a graph and returns an array of
|
|
6866
|
+
* The `topologicalSort` function performs a topological sort on a graph and returns an array of vertexMap or vertex IDs
|
|
6867
6867
|
* in the sorted order, or undefined if the graph contains a cycle.
|
|
6868
6868
|
* @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
|
|
6869
|
-
* property to use for sorting the
|
|
6870
|
-
* specified, the
|
|
6871
|
-
* @returns an array of
|
|
6869
|
+
* property to use for sorting the vertexMap. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
|
|
6870
|
+
* specified, the vertexMap themselves will be used for sorting. If 'key' is specified, the ids of
|
|
6871
|
+
* @returns an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.
|
|
6872
6872
|
*/
|
|
6873
6873
|
topologicalSort(propertyName) {
|
|
6874
6874
|
propertyName = propertyName != null ? propertyName : "key";
|
|
6875
6875
|
const statusMap = /* @__PURE__ */ new Map();
|
|
6876
|
-
for (const entry of this.
|
|
6876
|
+
for (const entry of this.vertexMap) {
|
|
6877
6877
|
statusMap.set(entry[1], 0);
|
|
6878
6878
|
}
|
|
6879
6879
|
let sorted = [];
|
|
@@ -6892,7 +6892,7 @@ var dataStructureTyped = (() => {
|
|
|
6892
6892
|
statusMap.set(cur, 2);
|
|
6893
6893
|
sorted.push(cur);
|
|
6894
6894
|
};
|
|
6895
|
-
for (const entry of this.
|
|
6895
|
+
for (const entry of this.vertexMap) {
|
|
6896
6896
|
if (statusMap.get(entry[1]) === 0) {
|
|
6897
6897
|
dfs(entry[1]);
|
|
6898
6898
|
}
|
|
@@ -6904,35 +6904,35 @@ var dataStructureTyped = (() => {
|
|
|
6904
6904
|
return sorted.reverse();
|
|
6905
6905
|
}
|
|
6906
6906
|
/**
|
|
6907
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6907
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6908
6908
|
* Space Complexity: O(|E|)
|
|
6909
6909
|
*/
|
|
6910
6910
|
/**
|
|
6911
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6911
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6912
6912
|
* Space Complexity: O(|E|)
|
|
6913
6913
|
*
|
|
6914
|
-
* The `edgeSet` function returns an array of all the
|
|
6915
|
-
* @returns The `edgeSet()` method returns an array of
|
|
6914
|
+
* The `edgeSet` function returns an array of all the edgeMap in the graph.
|
|
6915
|
+
* @returns The `edgeSet()` method returns an array of edgeMap (`EO[]`).
|
|
6916
6916
|
*/
|
|
6917
6917
|
edgeSet() {
|
|
6918
|
-
let
|
|
6918
|
+
let edgeMap = [];
|
|
6919
6919
|
this._outEdgeMap.forEach((outEdges) => {
|
|
6920
|
-
|
|
6920
|
+
edgeMap = [...edgeMap, ...outEdges];
|
|
6921
6921
|
});
|
|
6922
|
-
return
|
|
6922
|
+
return edgeMap;
|
|
6923
6923
|
}
|
|
6924
6924
|
/**
|
|
6925
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6925
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6926
6926
|
* Space Complexity: O(1)
|
|
6927
6927
|
*/
|
|
6928
6928
|
/**
|
|
6929
|
-
* Time Complexity: O(|E|) where |E| is the number of
|
|
6929
|
+
* Time Complexity: O(|E|) where |E| is the number of edgeMap
|
|
6930
6930
|
* Space Complexity: O(1)
|
|
6931
6931
|
*
|
|
6932
|
-
* The function `getNeighbors` returns an array of neighboring
|
|
6932
|
+
* The function `getNeighbors` returns an array of neighboring vertexMap of a given vertex or vertex ID in a graph.
|
|
6933
6933
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
6934
6934
|
* (`VertexKey`).
|
|
6935
|
-
* @returns an array of
|
|
6935
|
+
* @returns an array of vertexMap (VO[]).
|
|
6936
6936
|
*/
|
|
6937
6937
|
getNeighbors(vertexOrKey) {
|
|
6938
6938
|
const neighbors = [];
|
|
@@ -6956,10 +6956,10 @@ var dataStructureTyped = (() => {
|
|
|
6956
6956
|
* Time Complexity: O(1)
|
|
6957
6957
|
* Space Complexity: O(1)
|
|
6958
6958
|
*
|
|
6959
|
-
* The function "getEndsOfEdge" returns the source and destination
|
|
6959
|
+
* The function "getEndsOfEdge" returns the source and destination vertexMap of an edge if it exists in the graph,
|
|
6960
6960
|
* otherwise it returns undefined.
|
|
6961
6961
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
|
|
6962
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
6962
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
6963
6963
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
6964
6964
|
*/
|
|
6965
6965
|
getEndsOfEdge(edge) {
|
|
@@ -6982,7 +6982,7 @@ var dataStructureTyped = (() => {
|
|
|
6982
6982
|
* Time Complexity: O(1)
|
|
6983
6983
|
* Space Complexity: O(1)
|
|
6984
6984
|
*
|
|
6985
|
-
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination
|
|
6985
|
+
* The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
|
|
6986
6986
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
6987
6987
|
* needs to be added to the graph.
|
|
6988
6988
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
@@ -7040,21 +7040,21 @@ var dataStructureTyped = (() => {
|
|
|
7040
7040
|
*/
|
|
7041
7041
|
constructor(v1, v2, weight, value) {
|
|
7042
7042
|
super(weight, value);
|
|
7043
|
-
__publicField(this, "
|
|
7044
|
-
this.
|
|
7043
|
+
__publicField(this, "vertexMap");
|
|
7044
|
+
this.vertexMap = [v1, v2];
|
|
7045
7045
|
}
|
|
7046
7046
|
};
|
|
7047
7047
|
var UndirectedGraph = class extends AbstractGraph {
|
|
7048
7048
|
/**
|
|
7049
|
-
* The constructor initializes a new Map object to store
|
|
7049
|
+
* The constructor initializes a new Map object to store edgeMap.
|
|
7050
7050
|
*/
|
|
7051
7051
|
constructor() {
|
|
7052
7052
|
super();
|
|
7053
|
-
__publicField(this, "
|
|
7054
|
-
this.
|
|
7053
|
+
__publicField(this, "_edgeMap");
|
|
7054
|
+
this._edgeMap = /* @__PURE__ */ new Map();
|
|
7055
7055
|
}
|
|
7056
|
-
get
|
|
7057
|
-
return this.
|
|
7056
|
+
get edgeMap() {
|
|
7057
|
+
return this._edgeMap;
|
|
7058
7058
|
}
|
|
7059
7059
|
/**
|
|
7060
7060
|
* The function creates a new vertex with an optional value and returns it.
|
|
@@ -7069,7 +7069,7 @@ var dataStructureTyped = (() => {
|
|
|
7069
7069
|
return new UndirectedVertex(key, value != null ? value : key);
|
|
7070
7070
|
}
|
|
7071
7071
|
/**
|
|
7072
|
-
* The function creates an undirected edge between two
|
|
7072
|
+
* The function creates an undirected edge between two vertexMap with an optional weight and value.
|
|
7073
7073
|
* @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
|
|
7074
7074
|
* @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
|
|
7075
7075
|
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
|
|
@@ -7082,14 +7082,14 @@ var dataStructureTyped = (() => {
|
|
|
7082
7082
|
return new UndirectedEdge(v1, v2, weight != null ? weight : 1, value);
|
|
7083
7083
|
}
|
|
7084
7084
|
/**
|
|
7085
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
7085
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
7086
7086
|
* Space Complexity: O(1)
|
|
7087
7087
|
*/
|
|
7088
7088
|
/**
|
|
7089
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
7089
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
7090
7090
|
* Space Complexity: O(1)
|
|
7091
7091
|
*
|
|
7092
|
-
* The function `getEdge` returns the first edge that connects two
|
|
7092
|
+
* The function `getEdge` returns the first edge that connects two vertexMap, or undefined if no such edge exists.
|
|
7093
7093
|
* @param {VO | VertexKey | undefined} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
7094
7094
|
* object), `undefined`, or `VertexKey` (a string or number representing the ID of a vertex).
|
|
7095
7095
|
* @param {VO | VertexKey | undefined} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `VO` (vertex
|
|
@@ -7098,29 +7098,29 @@ var dataStructureTyped = (() => {
|
|
|
7098
7098
|
*/
|
|
7099
7099
|
getEdge(v1, v2) {
|
|
7100
7100
|
var _a;
|
|
7101
|
-
let
|
|
7101
|
+
let edgeMap = [];
|
|
7102
7102
|
if (v1 !== void 0 && v2 !== void 0) {
|
|
7103
7103
|
const vertex1 = this._getVertex(v1);
|
|
7104
7104
|
const vertex2 = this._getVertex(v2);
|
|
7105
7105
|
if (vertex1 && vertex2) {
|
|
7106
|
-
|
|
7106
|
+
edgeMap = (_a = this._edgeMap.get(vertex1)) == null ? void 0 : _a.filter((e) => e.vertexMap.includes(vertex2.key));
|
|
7107
7107
|
}
|
|
7108
7108
|
}
|
|
7109
|
-
return
|
|
7109
|
+
return edgeMap ? edgeMap[0] || void 0 : void 0;
|
|
7110
7110
|
}
|
|
7111
7111
|
/**
|
|
7112
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
7112
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
7113
7113
|
* Space Complexity: O(1)
|
|
7114
7114
|
*/
|
|
7115
7115
|
/**
|
|
7116
|
-
* Time Complexity: O(|E|), where |E| is the number of
|
|
7116
|
+
* Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
|
|
7117
7117
|
* Space Complexity: O(1)
|
|
7118
7118
|
*
|
|
7119
|
-
* The function removes an edge between two
|
|
7119
|
+
* The function removes an edge between two vertexMap in a graph and returns the removed edge.
|
|
7120
7120
|
* @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
|
|
7121
7121
|
* @param {VO | VertexKey} v2 - VO | VertexKey - This parameter can be either a vertex object (VO) or a vertex ID
|
|
7122
7122
|
* (VertexKey). It represents the second vertex of the edge that needs to be removed.
|
|
7123
|
-
* @returns the removed edge (EO) if it exists, or undefined if either of the
|
|
7123
|
+
* @returns the removed edge (EO) if it exists, or undefined if either of the vertexMap (VO) does not exist.
|
|
7124
7124
|
*/
|
|
7125
7125
|
deleteEdgeBetween(v1, v2) {
|
|
7126
7126
|
const vertex1 = this._getVertex(v1);
|
|
@@ -7128,26 +7128,26 @@ var dataStructureTyped = (() => {
|
|
|
7128
7128
|
if (!vertex1 || !vertex2) {
|
|
7129
7129
|
return void 0;
|
|
7130
7130
|
}
|
|
7131
|
-
const v1Edges = this.
|
|
7131
|
+
const v1Edges = this._edgeMap.get(vertex1);
|
|
7132
7132
|
let removed = void 0;
|
|
7133
7133
|
if (v1Edges) {
|
|
7134
|
-
removed = arrayRemove(v1Edges, (e) => e.
|
|
7134
|
+
removed = arrayRemove(v1Edges, (e) => e.vertexMap.includes(vertex2.key))[0] || void 0;
|
|
7135
7135
|
}
|
|
7136
|
-
const v2Edges = this.
|
|
7136
|
+
const v2Edges = this._edgeMap.get(vertex2);
|
|
7137
7137
|
if (v2Edges) {
|
|
7138
|
-
arrayRemove(v2Edges, (e) => e.
|
|
7138
|
+
arrayRemove(v2Edges, (e) => e.vertexMap.includes(vertex1.key));
|
|
7139
7139
|
}
|
|
7140
7140
|
return removed;
|
|
7141
7141
|
}
|
|
7142
7142
|
/**
|
|
7143
|
-
* Time Complexity: O(E), where E is the number of
|
|
7143
|
+
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
7144
7144
|
* Space Complexity: O(1)
|
|
7145
7145
|
*/
|
|
7146
7146
|
/**
|
|
7147
|
-
* Time Complexity: O(E), where E is the number of
|
|
7147
|
+
* Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
|
|
7148
7148
|
* Space Complexity: O(1)
|
|
7149
7149
|
*
|
|
7150
|
-
* The function `deleteEdge` deletes an edge between two
|
|
7150
|
+
* The function `deleteEdge` deletes an edge between two vertexMap in a graph.
|
|
7151
7151
|
* @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
|
|
7152
7152
|
* either an edge object or a vertex key.
|
|
7153
7153
|
* @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
|
|
@@ -7166,8 +7166,8 @@ var dataStructureTyped = (() => {
|
|
|
7166
7166
|
return;
|
|
7167
7167
|
}
|
|
7168
7168
|
} else {
|
|
7169
|
-
oneSide = this._getVertex(edgeOrOneSideVertexKey.
|
|
7170
|
-
otherSide = this._getVertex(edgeOrOneSideVertexKey.
|
|
7169
|
+
oneSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[0]);
|
|
7170
|
+
otherSide = this._getVertex(edgeOrOneSideVertexKey.vertexMap[1]);
|
|
7171
7171
|
}
|
|
7172
7172
|
if (oneSide && otherSide) {
|
|
7173
7173
|
return this.deleteEdgeBetween(oneSide, otherSide);
|
|
@@ -7201,17 +7201,17 @@ var dataStructureTyped = (() => {
|
|
|
7201
7201
|
const neighbors = this.getNeighbors(vertexOrKey);
|
|
7202
7202
|
if (vertex) {
|
|
7203
7203
|
neighbors.forEach((neighbor) => {
|
|
7204
|
-
const neighborEdges = this.
|
|
7204
|
+
const neighborEdges = this._edgeMap.get(neighbor);
|
|
7205
7205
|
if (neighborEdges) {
|
|
7206
7206
|
const restEdges = neighborEdges.filter((edge) => {
|
|
7207
|
-
return !edge.
|
|
7207
|
+
return !edge.vertexMap.includes(vertexKey);
|
|
7208
7208
|
});
|
|
7209
|
-
this.
|
|
7209
|
+
this._edgeMap.set(neighbor, restEdges);
|
|
7210
7210
|
}
|
|
7211
7211
|
});
|
|
7212
|
-
this.
|
|
7212
|
+
this._edgeMap.delete(vertex);
|
|
7213
7213
|
}
|
|
7214
|
-
return this.
|
|
7214
|
+
return this._vertexMap.delete(vertexKey);
|
|
7215
7215
|
}
|
|
7216
7216
|
/**
|
|
7217
7217
|
* Time Complexity: O(1)
|
|
@@ -7221,17 +7221,17 @@ var dataStructureTyped = (() => {
|
|
|
7221
7221
|
* Time Complexity: O(1)
|
|
7222
7222
|
* Space Complexity: O(1)
|
|
7223
7223
|
*
|
|
7224
|
-
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of
|
|
7224
|
+
* The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edgeMap connected to that
|
|
7225
7225
|
* vertex.
|
|
7226
7226
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
|
|
7227
7227
|
* @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
|
|
7228
|
-
*
|
|
7228
|
+
* edgeMap connected to that vertex.
|
|
7229
7229
|
*/
|
|
7230
7230
|
degreeOf(vertexOrKey) {
|
|
7231
7231
|
var _a;
|
|
7232
7232
|
const vertex = this._getVertex(vertexOrKey);
|
|
7233
7233
|
if (vertex) {
|
|
7234
|
-
return ((_a = this.
|
|
7234
|
+
return ((_a = this._edgeMap.get(vertex)) == null ? void 0 : _a.length) || 0;
|
|
7235
7235
|
} else {
|
|
7236
7236
|
return 0;
|
|
7237
7237
|
}
|
|
@@ -7244,51 +7244,51 @@ var dataStructureTyped = (() => {
|
|
|
7244
7244
|
* Time Complexity: O(1)
|
|
7245
7245
|
* Space Complexity: O(1)
|
|
7246
7246
|
*
|
|
7247
|
-
* The function returns the
|
|
7247
|
+
* The function returns the edgeMap of a given vertex or vertex ID.
|
|
7248
7248
|
* @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`. A `VertexKey` is a
|
|
7249
7249
|
* unique identifier for a vertex in a graph, while `VO` represents the type of the vertex.
|
|
7250
|
-
* @returns an array of
|
|
7250
|
+
* @returns an array of edgeMap.
|
|
7251
7251
|
*/
|
|
7252
7252
|
edgesOf(vertexOrKey) {
|
|
7253
7253
|
const vertex = this._getVertex(vertexOrKey);
|
|
7254
7254
|
if (vertex) {
|
|
7255
|
-
return this.
|
|
7255
|
+
return this._edgeMap.get(vertex) || [];
|
|
7256
7256
|
} else {
|
|
7257
7257
|
return [];
|
|
7258
7258
|
}
|
|
7259
7259
|
}
|
|
7260
7260
|
/**
|
|
7261
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
7261
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
7262
7262
|
* Space Complexity: O(|E|)
|
|
7263
7263
|
*/
|
|
7264
7264
|
/**
|
|
7265
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
7265
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
7266
7266
|
* Space Complexity: O(|E|)
|
|
7267
7267
|
*
|
|
7268
|
-
* The function "edgeSet" returns an array of unique
|
|
7268
|
+
* The function "edgeSet" returns an array of unique edgeMap from a set of edgeMap.
|
|
7269
7269
|
* @returns The method `edgeSet()` returns an array of type `EO[]`.
|
|
7270
7270
|
*/
|
|
7271
7271
|
edgeSet() {
|
|
7272
7272
|
const edgeSet = /* @__PURE__ */ new Set();
|
|
7273
|
-
this.
|
|
7274
|
-
|
|
7273
|
+
this._edgeMap.forEach((edgeMap) => {
|
|
7274
|
+
edgeMap.forEach((edge) => {
|
|
7275
7275
|
edgeSet.add(edge);
|
|
7276
7276
|
});
|
|
7277
7277
|
});
|
|
7278
7278
|
return [...edgeSet];
|
|
7279
7279
|
}
|
|
7280
7280
|
/**
|
|
7281
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
7281
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
7282
7282
|
* Space Complexity: O(|E|)
|
|
7283
7283
|
*/
|
|
7284
7284
|
/**
|
|
7285
|
-
* Time Complexity: O(|V| + |E|), where |V| is the number of
|
|
7285
|
+
* Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
|
|
7286
7286
|
* Space Complexity: O(|E|)
|
|
7287
7287
|
*
|
|
7288
|
-
* The function "getNeighbors" returns an array of neighboring
|
|
7288
|
+
* The function "getNeighbors" returns an array of neighboring vertexMap for a given vertex or vertex ID.
|
|
7289
7289
|
* @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
|
|
7290
7290
|
* (`VertexKey`).
|
|
7291
|
-
* @returns an array of
|
|
7291
|
+
* @returns an array of vertexMap (VO[]).
|
|
7292
7292
|
*/
|
|
7293
7293
|
getNeighbors(vertexOrKey) {
|
|
7294
7294
|
const neighbors = [];
|
|
@@ -7296,7 +7296,7 @@ var dataStructureTyped = (() => {
|
|
|
7296
7296
|
if (vertex) {
|
|
7297
7297
|
const neighborEdges = this.edgesOf(vertex);
|
|
7298
7298
|
for (const edge of neighborEdges) {
|
|
7299
|
-
const neighbor = this._getVertex(edge.
|
|
7299
|
+
const neighbor = this._getVertex(edge.vertexMap.filter((e) => e !== vertex.key)[0]);
|
|
7300
7300
|
if (neighbor) {
|
|
7301
7301
|
neighbors.push(neighbor);
|
|
7302
7302
|
}
|
|
@@ -7312,18 +7312,18 @@ var dataStructureTyped = (() => {
|
|
|
7312
7312
|
* Time Complexity: O(1)
|
|
7313
7313
|
* Space Complexity: O(1)
|
|
7314
7314
|
*
|
|
7315
|
-
* The function "getEndsOfEdge" returns the
|
|
7315
|
+
* The function "getEndsOfEdge" returns the vertexMap at the ends of an edge if the edge exists in the graph, otherwise
|
|
7316
7316
|
* it returns undefined.
|
|
7317
7317
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
7318
|
-
* @returns The function `getEndsOfEdge` returns an array containing two
|
|
7318
|
+
* @returns The function `getEndsOfEdge` returns an array containing two vertexMap `[VO, VO]` if the edge exists in the
|
|
7319
7319
|
* graph. If the edge does not exist, it returns `undefined`.
|
|
7320
7320
|
*/
|
|
7321
7321
|
getEndsOfEdge(edge) {
|
|
7322
|
-
if (!this.hasEdge(edge.
|
|
7322
|
+
if (!this.hasEdge(edge.vertexMap[0], edge.vertexMap[1])) {
|
|
7323
7323
|
return void 0;
|
|
7324
7324
|
}
|
|
7325
|
-
const v1 = this._getVertex(edge.
|
|
7326
|
-
const v2 = this._getVertex(edge.
|
|
7325
|
+
const v1 = this._getVertex(edge.vertexMap[0]);
|
|
7326
|
+
const v2 = this._getVertex(edge.vertexMap[1]);
|
|
7327
7327
|
if (v1 && v2) {
|
|
7328
7328
|
return [v1, v2];
|
|
7329
7329
|
} else {
|
|
@@ -7338,21 +7338,21 @@ var dataStructureTyped = (() => {
|
|
|
7338
7338
|
* Time Complexity: O(1)
|
|
7339
7339
|
* Space Complexity: O(1)
|
|
7340
7340
|
*
|
|
7341
|
-
* The function adds an edge to the graph by updating the adjacency list with the
|
|
7341
|
+
* The function adds an edge to the graph by updating the adjacency list with the vertexMap of the edge.
|
|
7342
7342
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
7343
7343
|
* @returns a boolean value.
|
|
7344
7344
|
*/
|
|
7345
7345
|
_addEdgeOnly(edge) {
|
|
7346
|
-
for (const end of edge.
|
|
7346
|
+
for (const end of edge.vertexMap) {
|
|
7347
7347
|
const endVertex = this._getVertex(end);
|
|
7348
7348
|
if (endVertex === void 0)
|
|
7349
7349
|
return false;
|
|
7350
7350
|
if (endVertex) {
|
|
7351
|
-
const
|
|
7352
|
-
if (
|
|
7353
|
-
|
|
7351
|
+
const edgeMap = this._edgeMap.get(endVertex);
|
|
7352
|
+
if (edgeMap) {
|
|
7353
|
+
edgeMap.push(edge);
|
|
7354
7354
|
} else {
|
|
7355
|
-
this.
|
|
7355
|
+
this._edgeMap.set(endVertex, [edge]);
|
|
7356
7356
|
}
|
|
7357
7357
|
}
|
|
7358
7358
|
}
|
|
@@ -7399,23 +7399,23 @@ var dataStructureTyped = (() => {
|
|
|
7399
7399
|
};
|
|
7400
7400
|
var MapGraph = class extends DirectedGraph {
|
|
7401
7401
|
/**
|
|
7402
|
-
* The constructor function initializes the
|
|
7403
|
-
* @param {MapGraphCoordinate}
|
|
7402
|
+
* The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
|
|
7403
|
+
* @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
|
|
7404
7404
|
* starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
|
|
7405
7405
|
* graph.
|
|
7406
7406
|
* @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
|
|
7407
7407
|
* `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
|
|
7408
7408
|
* it will default to `undefined`.
|
|
7409
7409
|
*/
|
|
7410
|
-
constructor(
|
|
7410
|
+
constructor(originCoord, bottomRight) {
|
|
7411
7411
|
super();
|
|
7412
|
-
__publicField(this, "
|
|
7412
|
+
__publicField(this, "_originCoord", [0, 0]);
|
|
7413
7413
|
__publicField(this, "_bottomRight");
|
|
7414
|
-
this.
|
|
7414
|
+
this._originCoord = originCoord;
|
|
7415
7415
|
this._bottomRight = bottomRight;
|
|
7416
7416
|
}
|
|
7417
|
-
get
|
|
7418
|
-
return this.
|
|
7417
|
+
get originCoord() {
|
|
7418
|
+
return this._originCoord;
|
|
7419
7419
|
}
|
|
7420
7420
|
get bottomRight() {
|
|
7421
7421
|
return this._bottomRight;
|
|
@@ -7431,7 +7431,7 @@ var dataStructureTyped = (() => {
|
|
|
7431
7431
|
* @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
|
|
7432
7432
|
* @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
|
|
7433
7433
|
*/
|
|
7434
|
-
createVertex(key, value, lat = this.
|
|
7434
|
+
createVertex(key, value, lat = this.originCoord[0], long = this.originCoord[1]) {
|
|
7435
7435
|
return new MapVertex(key, value, lat, long);
|
|
7436
7436
|
}
|
|
7437
7437
|
/**
|
|
@@ -7534,7 +7534,7 @@ var dataStructureTyped = (() => {
|
|
|
7534
7534
|
return "MAL_NODE" /* MAL_NODE */;
|
|
7535
7535
|
}
|
|
7536
7536
|
};
|
|
7537
|
-
var BinaryTree = class _BinaryTree extends
|
|
7537
|
+
var BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
7538
7538
|
/**
|
|
7539
7539
|
* The constructor function initializes a binary tree object with optional elements and options.
|
|
7540
7540
|
* @param [elements] - An optional iterable of BTNodeExemplar objects. These objects represent the
|
|
@@ -7601,31 +7601,32 @@ var dataStructureTyped = (() => {
|
|
|
7601
7601
|
return exemplar instanceof BinaryTreeNode;
|
|
7602
7602
|
}
|
|
7603
7603
|
/**
|
|
7604
|
-
* The function `exemplarToNode` converts an exemplar
|
|
7605
|
-
*
|
|
7606
|
-
* @param
|
|
7607
|
-
* function. It
|
|
7608
|
-
*
|
|
7604
|
+
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
7605
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
|
|
7606
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
7607
|
+
* `exemplarToNode` function. It represents the value associated with the exemplar node. If no value
|
|
7608
|
+
* is provided, it will be `undefined`.
|
|
7609
|
+
* @returns a value of type N (node), or null, or undefined.
|
|
7609
7610
|
*/
|
|
7610
|
-
exemplarToNode(exemplar) {
|
|
7611
|
+
exemplarToNode(exemplar, value) {
|
|
7611
7612
|
if (exemplar === void 0)
|
|
7612
7613
|
return;
|
|
7613
7614
|
let node;
|
|
7614
7615
|
if (exemplar === null) {
|
|
7615
7616
|
node = null;
|
|
7616
7617
|
} else if (this.isEntry(exemplar)) {
|
|
7617
|
-
const [key,
|
|
7618
|
+
const [key, value2] = exemplar;
|
|
7618
7619
|
if (key === void 0) {
|
|
7619
7620
|
return;
|
|
7620
7621
|
} else if (key === null) {
|
|
7621
7622
|
node = null;
|
|
7622
7623
|
} else {
|
|
7623
|
-
node = this.createNode(key,
|
|
7624
|
+
node = this.createNode(key, value2);
|
|
7624
7625
|
}
|
|
7625
7626
|
} else if (this.isNode(exemplar)) {
|
|
7626
7627
|
node = exemplar;
|
|
7627
7628
|
} else if (this.isNotNodeInstance(exemplar)) {
|
|
7628
|
-
node = this.createNode(exemplar);
|
|
7629
|
+
node = this.createNode(exemplar, value);
|
|
7629
7630
|
} else {
|
|
7630
7631
|
return;
|
|
7631
7632
|
}
|
|
@@ -7647,14 +7648,16 @@ var dataStructureTyped = (() => {
|
|
|
7647
7648
|
/**
|
|
7648
7649
|
* Time Complexity O(log n) - O(n)
|
|
7649
7650
|
* Space Complexity O(1)
|
|
7650
|
-
*
|
|
7651
|
-
* The `add` function adds a new node to a binary tree, either by
|
|
7652
|
-
*
|
|
7653
|
-
* @
|
|
7651
|
+
*
|
|
7652
|
+
* The `add` function adds a new node to a binary tree, either by creating a new node or replacing an
|
|
7653
|
+
* existing node with the same key.
|
|
7654
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
|
|
7655
|
+
* @param {V} [value] - The value to be inserted into the binary tree.
|
|
7656
|
+
* @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
|
|
7654
7657
|
*/
|
|
7655
|
-
add(keyOrNodeOrEntry) {
|
|
7658
|
+
add(keyOrNodeOrEntry, value) {
|
|
7656
7659
|
let inserted;
|
|
7657
|
-
const newNode = this.exemplarToNode(keyOrNodeOrEntry);
|
|
7660
|
+
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
|
|
7658
7661
|
if (newNode === void 0)
|
|
7659
7662
|
return;
|
|
7660
7663
|
const _bfs = (root, newNode2) => {
|
|
@@ -9199,26 +9202,28 @@ var dataStructureTyped = (() => {
|
|
|
9199
9202
|
return exemplar instanceof BSTNode;
|
|
9200
9203
|
}
|
|
9201
9204
|
/**
|
|
9202
|
-
* The function `exemplarToNode` takes an exemplar and returns a
|
|
9203
|
-
*
|
|
9204
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N
|
|
9205
|
-
* @
|
|
9205
|
+
* The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
|
|
9206
|
+
* otherwise it returns undefined.
|
|
9207
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
|
|
9208
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
9209
|
+
* `exemplarToNode` function. It represents the value associated with the exemplar node.
|
|
9210
|
+
* @returns a node of type N or undefined.
|
|
9206
9211
|
*/
|
|
9207
|
-
exemplarToNode(exemplar) {
|
|
9212
|
+
exemplarToNode(exemplar, value) {
|
|
9208
9213
|
let node;
|
|
9209
9214
|
if (exemplar === null || exemplar === void 0) {
|
|
9210
9215
|
return;
|
|
9211
9216
|
} else if (this.isNode(exemplar)) {
|
|
9212
9217
|
node = exemplar;
|
|
9213
9218
|
} else if (this.isEntry(exemplar)) {
|
|
9214
|
-
const [key,
|
|
9219
|
+
const [key, value2] = exemplar;
|
|
9215
9220
|
if (key === void 0 || key === null) {
|
|
9216
9221
|
return;
|
|
9217
9222
|
} else {
|
|
9218
|
-
node = this.createNode(key,
|
|
9223
|
+
node = this.createNode(key, value2);
|
|
9219
9224
|
}
|
|
9220
9225
|
} else if (this.isNotNodeInstance(exemplar)) {
|
|
9221
|
-
node = this.createNode(exemplar);
|
|
9226
|
+
node = this.createNode(exemplar, value);
|
|
9222
9227
|
} else {
|
|
9223
9228
|
return;
|
|
9224
9229
|
}
|
|
@@ -9231,15 +9236,17 @@ var dataStructureTyped = (() => {
|
|
|
9231
9236
|
/**
|
|
9232
9237
|
* Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
|
|
9233
9238
|
* Space Complexity: O(1) - Constant space is used.
|
|
9234
|
-
*
|
|
9235
|
-
* The `add` function adds a new node to a binary
|
|
9236
|
-
*
|
|
9237
|
-
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can
|
|
9238
|
-
* @
|
|
9239
|
-
*
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9239
|
+
*
|
|
9240
|
+
* The `add` function adds a new node to a binary tree, updating the value if the key already exists
|
|
9241
|
+
* or inserting a new node if the key is unique.
|
|
9242
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
|
|
9243
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key that is
|
|
9244
|
+
* being added to the binary tree.
|
|
9245
|
+
* @returns The method `add` returns either the newly added node (`newNode`) or `undefined` if the
|
|
9246
|
+
* node was not added.
|
|
9247
|
+
*/
|
|
9248
|
+
add(keyOrNodeOrEntry, value) {
|
|
9249
|
+
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
|
|
9243
9250
|
if (newNode === void 0)
|
|
9244
9251
|
return;
|
|
9245
9252
|
if (this.root === void 0) {
|
|
@@ -10214,17 +10221,19 @@ var dataStructureTyped = (() => {
|
|
|
10214
10221
|
/**
|
|
10215
10222
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
10216
10223
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
10217
|
-
*
|
|
10224
|
+
*
|
|
10218
10225
|
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
10219
10226
|
* a new node.
|
|
10220
|
-
* @param keyOrNodeOrEntry - The
|
|
10227
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
10221
10228
|
* entry.
|
|
10222
|
-
* @
|
|
10229
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key that is
|
|
10230
|
+
* being added to the binary tree.
|
|
10231
|
+
* @returns The method is returning either the inserted node or undefined.
|
|
10223
10232
|
*/
|
|
10224
|
-
add(keyOrNodeOrEntry) {
|
|
10233
|
+
add(keyOrNodeOrEntry, value) {
|
|
10225
10234
|
if (keyOrNodeOrEntry === null)
|
|
10226
10235
|
return void 0;
|
|
10227
|
-
const inserted = super.add(keyOrNodeOrEntry);
|
|
10236
|
+
const inserted = super.add(keyOrNodeOrEntry, value);
|
|
10228
10237
|
if (inserted)
|
|
10229
10238
|
this._balancePath(inserted);
|
|
10230
10239
|
return inserted;
|
|
@@ -10637,28 +10646,28 @@ var dataStructureTyped = (() => {
|
|
|
10637
10646
|
return exemplar instanceof RedBlackTreeNode;
|
|
10638
10647
|
}
|
|
10639
10648
|
/**
|
|
10640
|
-
* The function `exemplarToNode` takes an exemplar and
|
|
10641
|
-
*
|
|
10642
|
-
* @param
|
|
10643
|
-
*
|
|
10644
|
-
*
|
|
10645
|
-
* @returns a
|
|
10649
|
+
* The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
|
|
10650
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
|
|
10651
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
10652
|
+
* `exemplarToNode` function. It represents the value associated with the exemplar node. If a value
|
|
10653
|
+
* is provided, it will be used when creating the new node. If no value is provided, the new node
|
|
10654
|
+
* @returns a node of type N or undefined.
|
|
10646
10655
|
*/
|
|
10647
|
-
exemplarToNode(exemplar) {
|
|
10656
|
+
exemplarToNode(exemplar, value) {
|
|
10648
10657
|
let node;
|
|
10649
10658
|
if (exemplar === null || exemplar === void 0) {
|
|
10650
10659
|
return;
|
|
10651
10660
|
} else if (this.isNode(exemplar)) {
|
|
10652
10661
|
node = exemplar;
|
|
10653
10662
|
} else if (this.isEntry(exemplar)) {
|
|
10654
|
-
const [key,
|
|
10663
|
+
const [key, value2] = exemplar;
|
|
10655
10664
|
if (key === void 0 || key === null) {
|
|
10656
10665
|
return;
|
|
10657
10666
|
} else {
|
|
10658
|
-
node = this.createNode(key,
|
|
10667
|
+
node = this.createNode(key, value2, 1 /* RED */);
|
|
10659
10668
|
}
|
|
10660
10669
|
} else if (this.isNotNodeInstance(exemplar)) {
|
|
10661
|
-
node = this.createNode(exemplar,
|
|
10670
|
+
node = this.createNode(exemplar, value, 1 /* RED */);
|
|
10662
10671
|
} else {
|
|
10663
10672
|
return;
|
|
10664
10673
|
}
|
|
@@ -10669,13 +10678,19 @@ var dataStructureTyped = (() => {
|
|
|
10669
10678
|
* Space Complexity: O(1)
|
|
10670
10679
|
*/
|
|
10671
10680
|
/**
|
|
10672
|
-
*
|
|
10673
|
-
*
|
|
10674
|
-
*
|
|
10675
|
-
* `
|
|
10681
|
+
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
10682
|
+
* Space Complexity: O(1)
|
|
10683
|
+
*
|
|
10684
|
+
* The `add` function adds a new node to a binary search tree and performs necessary rotations and
|
|
10685
|
+
* color changes to maintain the red-black tree properties.
|
|
10686
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
10687
|
+
* entry.
|
|
10688
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key that is
|
|
10689
|
+
* being added to the binary search tree.
|
|
10690
|
+
* @returns The method `add` returns either the newly added node (`N`) or `undefined`.
|
|
10676
10691
|
*/
|
|
10677
|
-
add(keyOrNodeOrEntry) {
|
|
10678
|
-
const newNode = this.exemplarToNode(keyOrNodeOrEntry);
|
|
10692
|
+
add(keyOrNodeOrEntry, value) {
|
|
10693
|
+
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
|
|
10679
10694
|
if (newNode === void 0)
|
|
10680
10695
|
return;
|
|
10681
10696
|
newNode.left = this.Sentinel;
|
|
@@ -11176,27 +11191,30 @@ var dataStructureTyped = (() => {
|
|
|
11176
11191
|
}
|
|
11177
11192
|
/**
|
|
11178
11193
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
11179
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`,
|
|
11180
|
-
*
|
|
11194
|
+
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
|
|
11195
|
+
* can be one of the following:
|
|
11196
|
+
* @param {V} [value] - The `value` parameter is an optional argument that represents the value
|
|
11197
|
+
* associated with the node. It is of type `V`, which can be any data type. If no value is provided,
|
|
11198
|
+
* it defaults to `undefined`.
|
|
11181
11199
|
* @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
|
|
11182
|
-
* times the
|
|
11183
|
-
* @returns a
|
|
11200
|
+
* times the value should be added to the node. If not provided, it defaults to 1.
|
|
11201
|
+
* @returns a node of type `N` or `undefined`.
|
|
11184
11202
|
*/
|
|
11185
|
-
exemplarToNode(exemplar, count = 1) {
|
|
11203
|
+
exemplarToNode(exemplar, value, count = 1) {
|
|
11186
11204
|
let node;
|
|
11187
11205
|
if (exemplar === void 0 || exemplar === null) {
|
|
11188
11206
|
return;
|
|
11189
11207
|
} else if (this.isNode(exemplar)) {
|
|
11190
11208
|
node = exemplar;
|
|
11191
11209
|
} else if (this.isEntry(exemplar)) {
|
|
11192
|
-
const [key,
|
|
11210
|
+
const [key, value2] = exemplar;
|
|
11193
11211
|
if (key === void 0 || key === null) {
|
|
11194
11212
|
return;
|
|
11195
11213
|
} else {
|
|
11196
|
-
node = this.createNode(key,
|
|
11214
|
+
node = this.createNode(key, value2, count);
|
|
11197
11215
|
}
|
|
11198
11216
|
} else if (this.isNotNodeInstance(exemplar)) {
|
|
11199
|
-
node = this.createNode(exemplar,
|
|
11217
|
+
node = this.createNode(exemplar, value, count);
|
|
11200
11218
|
} else {
|
|
11201
11219
|
return;
|
|
11202
11220
|
}
|
|
@@ -11209,17 +11227,21 @@ var dataStructureTyped = (() => {
|
|
|
11209
11227
|
/**
|
|
11210
11228
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
|
|
11211
11229
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
11212
|
-
*
|
|
11213
|
-
* The
|
|
11214
|
-
*
|
|
11215
|
-
*
|
|
11216
|
-
* @param [
|
|
11217
|
-
*
|
|
11218
|
-
*
|
|
11219
|
-
* @
|
|
11220
|
-
|
|
11221
|
-
|
|
11222
|
-
|
|
11230
|
+
*
|
|
11231
|
+
* The function overrides the add method of a binary tree node and adds a new node to the tree.
|
|
11232
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
11233
|
+
* entry. It represents the key, node, or entry that you want to add to the binary tree.
|
|
11234
|
+
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
11235
|
+
* binary tree node. It is an optional parameter, meaning it can be omitted when calling the `add`
|
|
11236
|
+
* method.
|
|
11237
|
+
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
11238
|
+
* be added to the binary tree. By default, it is set to 1, meaning that the key-value pair will be
|
|
11239
|
+
* added once. However, you can specify a different value for `count` if you want to add
|
|
11240
|
+
* @returns The method is returning either the newly inserted node or `undefined` if the insertion
|
|
11241
|
+
* was not successful.
|
|
11242
|
+
*/
|
|
11243
|
+
add(keyOrNodeOrEntry, value, count = 1) {
|
|
11244
|
+
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
|
|
11223
11245
|
if (newNode === void 0)
|
|
11224
11246
|
return;
|
|
11225
11247
|
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
@@ -11272,7 +11294,7 @@ var dataStructureTyped = (() => {
|
|
|
11272
11294
|
return;
|
|
11273
11295
|
const m = l + Math.floor((r - l) / 2);
|
|
11274
11296
|
const midNode = sorted[m];
|
|
11275
|
-
this.add(
|
|
11297
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
11276
11298
|
buildBalanceBST(l, m - 1);
|
|
11277
11299
|
buildBalanceBST(m + 1, r);
|
|
11278
11300
|
};
|
|
@@ -11287,7 +11309,7 @@ var dataStructureTyped = (() => {
|
|
|
11287
11309
|
if (l <= r) {
|
|
11288
11310
|
const m = l + Math.floor((r - l) / 2);
|
|
11289
11311
|
const midNode = sorted[m];
|
|
11290
|
-
this.add(
|
|
11312
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
11291
11313
|
stack.push([m + 1, r]);
|
|
11292
11314
|
stack.push([l, m - 1]);
|
|
11293
11315
|
}
|
|
@@ -11395,7 +11417,7 @@ var dataStructureTyped = (() => {
|
|
|
11395
11417
|
*/
|
|
11396
11418
|
clone() {
|
|
11397
11419
|
const cloned = this.createTree();
|
|
11398
|
-
this.bfs((node) => cloned.add(
|
|
11420
|
+
this.bfs((node) => cloned.add(node.key, node.value, node.count));
|
|
11399
11421
|
return cloned;
|
|
11400
11422
|
}
|
|
11401
11423
|
/**
|