data-structure-typed 1.34.7 → 1.34.9
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/.eslintrc.js +1 -0
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +0 -0
- package/README.md +8 -8
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +314 -457
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +64 -90
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +12 -31
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js +157 -244
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +20 -44
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/segment-tree.js +80 -122
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +168 -239
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +351 -585
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js +152 -282
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/map-graph.js +47 -88
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js +91 -180
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.js +85 -247
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +87 -128
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/pair.js.map +1 -1
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-map.js.map +1 -1
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/hash/tree-set.js.map +1 -1
- package/dist/data-structures/heap/heap.js +56 -80
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +57 -70
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.js +63 -84
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/queue.js +57 -157
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/tree.js +33 -46
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/utils/utils.js +22 -107
- package/dist/utils/utils.js.map +1 -1
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +124 -123
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +136 -216
- package/lib/data-structures/binary-tree/avl-tree.d.ts +19 -10
- package/lib/data-structures/binary-tree/avl-tree.js +35 -13
- package/lib/data-structures/binary-tree/binary-tree.d.ts +6 -6
- package/lib/data-structures/binary-tree/binary-tree.js +7 -7
- package/lib/data-structures/binary-tree/bst.d.ts +34 -34
- package/lib/data-structures/binary-tree/bst.js +86 -89
- package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/lib/data-structures/binary-tree/rb-tree.js +4 -4
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +40 -42
- package/lib/data-structures/binary-tree/tree-multiset.js +76 -86
- package/lib/data-structures/graph/abstract-graph.d.ts +62 -62
- package/lib/data-structures/graph/abstract-graph.js +86 -86
- package/lib/data-structures/graph/directed-graph.d.ts +51 -51
- package/lib/data-structures/graph/directed-graph.js +63 -63
- package/lib/data-structures/graph/map-graph.d.ts +13 -13
- package/lib/data-structures/graph/map-graph.js +12 -12
- package/lib/data-structures/graph/undirected-graph.d.ts +30 -30
- package/lib/data-structures/graph/undirected-graph.js +32 -32
- package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
- package/lib/data-structures/priority-queue/priority-queue.js +3 -3
- package/lib/data-structures/tree/tree.d.ts +4 -4
- package/lib/data-structures/tree/tree.js +6 -6
- package/lib/interfaces/abstract-binary-tree.d.ts +37 -42
- package/lib/interfaces/abstract-graph.d.ts +13 -13
- package/lib/interfaces/avl-tree.d.ts +6 -4
- package/lib/interfaces/bst.d.ts +10 -9
- package/lib/interfaces/directed-graph.d.ts +5 -5
- package/lib/interfaces/rb-tree.d.ts +2 -2
- package/lib/interfaces/undirected-graph.d.ts +2 -2
- package/lib/types/data-structures/abstract-binary-tree.d.ts +3 -3
- package/lib/types/data-structures/abstract-binary-tree.js +0 -1
- package/lib/types/data-structures/abstract-graph.d.ts +2 -2
- package/lib/types/data-structures/bst.d.ts +2 -2
- package/lib/types/data-structures/tree-multiset.d.ts +1 -1
- package/lib/types/utils/validate-type.d.ts +8 -8
- package/package.json +6 -6
- package/scripts/rename_clear_files.sh +29 -0
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +241 -293
- package/src/data-structures/binary-tree/avl-tree.ts +43 -14
- package/src/data-structures/binary-tree/binary-tree.ts +8 -8
- package/src/data-structures/binary-tree/bst.ts +101 -96
- package/src/data-structures/binary-tree/rb-tree.ts +9 -9
- package/src/data-structures/binary-tree/tree-multiset.ts +82 -94
- package/src/data-structures/graph/abstract-graph.ts +114 -109
- package/src/data-structures/graph/directed-graph.ts +77 -77
- package/src/data-structures/graph/map-graph.ts +20 -15
- package/src/data-structures/graph/undirected-graph.ts +39 -39
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/tree/tree.ts +7 -7
- package/src/interfaces/abstract-binary-tree.ts +37 -50
- package/src/interfaces/abstract-graph.ts +13 -13
- package/src/interfaces/avl-tree.ts +6 -4
- package/src/interfaces/bst.ts +9 -9
- package/src/interfaces/directed-graph.ts +5 -5
- package/src/interfaces/rb-tree.ts +2 -2
- package/src/interfaces/undirected-graph.ts +2 -2
- package/src/types/data-structures/abstract-binary-tree.ts +3 -4
- package/src/types/data-structures/abstract-graph.ts +2 -2
- package/src/types/data-structures/bst.ts +2 -2
- package/src/types/data-structures/tree-multiset.ts +1 -1
- package/src/types/utils/validate-type.ts +10 -10
- package/test/integration/avl-tree.test.ts +24 -24
- package/test/integration/bst.test.ts +71 -71
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +28 -28
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +4 -12
- package/test/unit/data-structures/binary-tree/bst.test.ts +79 -79
- package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +80 -80
- package/test/unit/data-structures/graph/directed-graph.test.ts +8 -8
- package/test/unit/data-structures/graph/map-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/overall.test.ts +2 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -5
- package/test/unit/data-structures/tree/tree.test.ts +2 -2
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { DijkstraResult,
|
|
1
|
+
import type { DijkstraResult, VertexKey } from '../../types';
|
|
2
2
|
import { IAbstractGraph } from '../../interfaces';
|
|
3
3
|
export declare abstract class AbstractVertex<V = any> {
|
|
4
4
|
/**
|
|
5
|
-
* The function is a protected constructor that takes an
|
|
6
|
-
* @param {
|
|
5
|
+
* The function is a protected constructor that takes an key and an optional value as parameters.
|
|
6
|
+
* @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
|
|
7
7
|
* used to uniquely identify the vertex object.
|
|
8
8
|
* @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the
|
|
9
9
|
* vertex. If no value is provided, it will be set to undefined.
|
|
10
10
|
*/
|
|
11
|
-
protected constructor(
|
|
12
|
-
private
|
|
13
|
-
get
|
|
14
|
-
set
|
|
11
|
+
protected constructor(key: VertexKey, val?: V);
|
|
12
|
+
private _key;
|
|
13
|
+
get key(): VertexKey;
|
|
14
|
+
set key(v: VertexKey);
|
|
15
15
|
private _val;
|
|
16
16
|
get val(): V | undefined;
|
|
17
17
|
set val(value: V | undefined);
|
|
@@ -48,14 +48,14 @@ export declare abstract class AbstractEdge<V = any> {
|
|
|
48
48
|
}
|
|
49
49
|
export declare abstract class AbstractGraph<V extends AbstractVertex<any> = AbstractVertex<any>, E extends AbstractEdge<any> = AbstractEdge<any>> implements IAbstractGraph<V, E> {
|
|
50
50
|
private _vertices;
|
|
51
|
-
get vertices(): Map<
|
|
51
|
+
get vertices(): Map<VertexKey, V>;
|
|
52
52
|
/**
|
|
53
53
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
54
54
|
* 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.
|
|
55
|
-
* @param
|
|
55
|
+
* @param key
|
|
56
56
|
* @param val
|
|
57
57
|
*/
|
|
58
|
-
abstract createVertex(
|
|
58
|
+
abstract createVertex(key: VertexKey, val?: V): V;
|
|
59
59
|
/**
|
|
60
60
|
* In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
|
|
61
61
|
* 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.
|
|
@@ -64,77 +64,77 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
64
64
|
* @param weight
|
|
65
65
|
* @param val
|
|
66
66
|
*/
|
|
67
|
-
abstract createEdge(srcOrV1:
|
|
67
|
+
abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E;
|
|
68
68
|
abstract removeEdge(edge: E): E | null;
|
|
69
|
-
abstract getEdge(
|
|
70
|
-
abstract degreeOf(
|
|
69
|
+
abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null;
|
|
70
|
+
abstract degreeOf(vertexOrKey: V | VertexKey): number;
|
|
71
71
|
abstract edgeSet(): E[];
|
|
72
|
-
abstract edgesOf(
|
|
73
|
-
abstract getNeighbors(
|
|
72
|
+
abstract edgesOf(vertexOrKey: V | VertexKey): E[];
|
|
73
|
+
abstract getNeighbors(vertexOrKey: V | VertexKey): V[];
|
|
74
74
|
abstract getEndsOfEdge(edge: E): [V, V] | null;
|
|
75
75
|
/**
|
|
76
76
|
* The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
|
|
77
|
-
* @param {
|
|
77
|
+
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
78
78
|
* the `_vertices` map.
|
|
79
|
-
* @returns The method `getVertex` returns the vertex with the specified `
|
|
79
|
+
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
80
80
|
* map. If the vertex does not exist, it returns `null`.
|
|
81
81
|
*/
|
|
82
|
-
getVertex(
|
|
82
|
+
getVertex(vertexKey: VertexKey): V | null;
|
|
83
83
|
/**
|
|
84
84
|
* The function checks if a vertex exists in a graph.
|
|
85
|
-
* @param {V |
|
|
86
|
-
* (`
|
|
85
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
86
|
+
* (`VertexKey`).
|
|
87
87
|
* @returns a boolean value.
|
|
88
88
|
*/
|
|
89
|
-
hasVertex(
|
|
89
|
+
hasVertex(vertexOrKey: V | VertexKey): boolean;
|
|
90
90
|
addVertex(vertex: V): boolean;
|
|
91
|
-
addVertex(
|
|
91
|
+
addVertex(key: VertexKey, val?: V['val']): boolean;
|
|
92
92
|
/**
|
|
93
93
|
* The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
|
|
94
|
-
* @param {V |
|
|
95
|
-
* (`
|
|
94
|
+
* @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
|
|
95
|
+
* (`VertexKey`).
|
|
96
96
|
* @returns The method is returning a boolean value.
|
|
97
97
|
*/
|
|
98
|
-
removeVertex(
|
|
98
|
+
removeVertex(vertexOrKey: V | VertexKey): boolean;
|
|
99
99
|
/**
|
|
100
100
|
* The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
|
|
101
|
-
* @param {V[] |
|
|
102
|
-
* of vertex IDs (`
|
|
101
|
+
* @param {V[] | VertexKey[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
|
|
102
|
+
* of vertex IDs (`VertexKey[]`).
|
|
103
103
|
* @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
|
|
104
104
|
* were removed.
|
|
105
105
|
*/
|
|
106
|
-
removeAllVertices(vertices: V[] |
|
|
106
|
+
removeAllVertices(vertices: V[] | VertexKey[]): boolean;
|
|
107
107
|
/**
|
|
108
108
|
* The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
|
|
109
|
-
* @param {
|
|
109
|
+
* @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
|
|
110
110
|
* identifier of a vertex in a graph, while V represents the type of the vertex object itself.
|
|
111
|
-
* @param {
|
|
112
|
-
* `
|
|
111
|
+
* @param {VertexKey | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
|
|
112
|
+
* `VertexKey` or a `V` type, which represents the type of the vertex.
|
|
113
113
|
* @returns A boolean value is being returned.
|
|
114
114
|
*/
|
|
115
|
-
hasEdge(v1:
|
|
115
|
+
hasEdge(v1: VertexKey | V, v2: VertexKey | V): boolean;
|
|
116
116
|
addEdge(edge: E): boolean;
|
|
117
|
-
addEdge(src: V |
|
|
117
|
+
addEdge(src: V | VertexKey, dest: V | VertexKey, weight?: number, val?: E['val']): boolean;
|
|
118
118
|
/**
|
|
119
119
|
* The function sets the weight of an edge between two vertices in a graph.
|
|
120
|
-
* @param {
|
|
120
|
+
* @param {VertexKey | V} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `V` object. It represents
|
|
121
121
|
* the source vertex of the edge.
|
|
122
|
-
* @param {
|
|
123
|
-
* either a `
|
|
124
|
-
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (
|
|
125
|
-
* and the destination vertex (
|
|
122
|
+
* @param {VertexKey | V} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
|
|
123
|
+
* either a `VertexKey` or a vertex object `V`.
|
|
124
|
+
* @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
|
|
125
|
+
* and the destination vertex (destOrKey).
|
|
126
126
|
* @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
|
|
127
127
|
* the weight of the edge and return true. If the edge does not exist, the function will return false.
|
|
128
128
|
*/
|
|
129
|
-
setEdgeWeight(
|
|
129
|
+
setEdgeWeight(srcOrKey: VertexKey | V, destOrKey: VertexKey | V, weight: number): boolean;
|
|
130
130
|
/**
|
|
131
131
|
* The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
|
|
132
|
-
* @param {V |
|
|
132
|
+
* @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
|
|
133
133
|
* It is the starting vertex for finding paths.
|
|
134
|
-
* @param {V |
|
|
134
|
+
* @param {V | VertexKey} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
|
|
135
135
|
* @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
|
|
136
136
|
*/
|
|
137
|
-
getAllPathsBetween(v1: V |
|
|
137
|
+
getAllPathsBetween(v1: V | VertexKey, v2: V | VertexKey): V[][];
|
|
138
138
|
/**
|
|
139
139
|
* The function calculates the sum of weights along a given path.
|
|
140
140
|
* @param {V[]} path - An array of vertices (V) representing a path in a graph.
|
|
@@ -144,8 +144,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
144
144
|
/**
|
|
145
145
|
* The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
|
|
146
146
|
* weights or using a breadth-first search algorithm.
|
|
147
|
-
* @param {V |
|
|
148
|
-
* @param {V |
|
|
147
|
+
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
|
|
148
|
+
* @param {V | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
|
|
149
149
|
* you want to find the minimum cost or weight from the source vertex `v1`.
|
|
150
150
|
* @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
|
|
151
151
|
* If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
|
|
@@ -155,13 +155,13 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
155
155
|
* vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
156
156
|
* minimum number of
|
|
157
157
|
*/
|
|
158
|
-
getMinCostBetween(v1: V |
|
|
158
|
+
getMinCostBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): number | null;
|
|
159
159
|
/**
|
|
160
160
|
* The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
|
|
161
161
|
* using a breadth-first search algorithm.
|
|
162
|
-
* @param {V |
|
|
163
|
-
* object (`V`) or a vertex ID (`
|
|
164
|
-
* @param {V |
|
|
162
|
+
* @param {V | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
|
|
163
|
+
* object (`V`) or a vertex ID (`VertexKey`).
|
|
164
|
+
* @param {V | VertexKey} v2 - V | VertexKey - The second vertex or vertex ID between which we want to find the minimum
|
|
165
165
|
* path.
|
|
166
166
|
* @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
|
|
167
167
|
* minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
|
|
@@ -169,7 +169,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
169
169
|
* @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
|
|
170
170
|
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
|
|
171
171
|
*/
|
|
172
|
-
getMinPathBetween(v1: V |
|
|
172
|
+
getMinPathBetween(v1: V | VertexKey, v2: V | VertexKey, isWeight?: boolean): V[] | null;
|
|
173
173
|
/**
|
|
174
174
|
* Dijkstra algorithm time: O(VE) space: O(V + E)
|
|
175
175
|
* /
|
|
@@ -178,9 +178,9 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
178
178
|
* Dijkstra algorithm time: O(VE) space: O(V + E)
|
|
179
179
|
* The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
|
|
180
180
|
* a graph without using a heap data structure.
|
|
181
|
-
* @param {V |
|
|
181
|
+
* @param {V | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
182
182
|
* vertex object or a vertex ID.
|
|
183
|
-
* @param {V |
|
|
183
|
+
* @param {V | VertexKey | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
184
184
|
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
|
|
185
185
|
* identifier. If no destination is provided, the value is set to `null`.
|
|
186
186
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -191,7 +191,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
191
191
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
192
192
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
|
|
193
193
|
*/
|
|
194
|
-
dijkstraWithoutHeap(src: V |
|
|
194
|
+
dijkstraWithoutHeap(src: V | VertexKey, dest?: V | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
195
195
|
/**
|
|
196
196
|
* Dijkstra algorithm time: O(logVE) space: O(V + E)
|
|
197
197
|
*
|
|
@@ -205,9 +205,9 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
205
205
|
* Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
|
|
206
206
|
* The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
|
|
207
207
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
208
|
-
* @param {V |
|
|
208
|
+
* @param {V | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
209
209
|
* start. It can be either a vertex object or a vertex ID.
|
|
210
|
-
* @param {V |
|
|
210
|
+
* @param {V | VertexKey | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
211
211
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
212
212
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
213
213
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -218,7 +218,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
218
218
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
219
219
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
|
|
220
220
|
*/
|
|
221
|
-
dijkstra(src: V |
|
|
221
|
+
dijkstra(src: V | VertexKey, dest?: V | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
|
|
222
222
|
/**
|
|
223
223
|
* BellmanFord time:O(VE) space:O(V)
|
|
224
224
|
* one to rest pairs
|
|
@@ -230,7 +230,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
230
230
|
* 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 edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
|
|
231
231
|
* The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
|
|
232
232
|
* all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
|
|
233
|
-
* @param {V |
|
|
233
|
+
* @param {V | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
|
|
234
234
|
* start calculating the shortest paths. It can be either a vertex object or a vertex ID.
|
|
235
235
|
* @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
|
|
236
236
|
* @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
|
|
@@ -240,7 +240,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
240
240
|
* vertex.
|
|
241
241
|
* @returns The function `bellmanFord` returns an object with the following properties:
|
|
242
242
|
*/
|
|
243
|
-
bellmanFord(src: V |
|
|
243
|
+
bellmanFord(src: V | VertexKey, scanNegativeCycle?: boolean, getMin?: boolean, genPath?: boolean): {
|
|
244
244
|
hasNegativeCycle: boolean | undefined;
|
|
245
245
|
distMap: Map<V, number>;
|
|
246
246
|
preMap: Map<V, V>;
|
|
@@ -288,7 +288,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
288
288
|
predecessor: (V | null)[][];
|
|
289
289
|
};
|
|
290
290
|
/**
|
|
291
|
-
* Tarjan is an algorithm based on
|
|
291
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
292
292
|
* Tarjan can find cycles in directed or undirected graph
|
|
293
293
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
294
294
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
@@ -296,7 +296,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
296
296
|
* /
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
|
-
* Tarjan is an algorithm based on
|
|
299
|
+
* Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
|
|
300
300
|
* Tarjan can find cycles in directed or undirected graph
|
|
301
301
|
* Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
|
|
302
302
|
* Tarjan solve the bi-connected components of undirected graphs;
|
|
@@ -326,7 +326,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
|
|
|
326
326
|
};
|
|
327
327
|
protected abstract _addEdgeOnly(edge: E): boolean;
|
|
328
328
|
protected _addVertexOnly(newVertex: V): boolean;
|
|
329
|
-
protected _getVertex(
|
|
330
|
-
protected
|
|
331
|
-
protected _setVertices(value: Map<
|
|
329
|
+
protected _getVertex(vertexOrKey: VertexKey | V): V | null;
|
|
330
|
+
protected _getVertexKey(vertexOrKey: V | VertexKey): VertexKey;
|
|
331
|
+
protected _setVertices(value: Map<VertexKey, V>): void;
|
|
332
332
|
}
|