graph-typed 1.19.3 → 1.19.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,180 +1,30 @@
1
1
  # What
2
-
3
2
  ## Brief
4
- Javascript & TypeScript Data Structure Library.
5
-
6
- Binary Tree, Binary Search Tree (BST), AVL Tree, Tree Multiset, Segment Tree, Binary Indexed Tree, Graph, Directed Graph, Undirected Graph, Linked List, Singly Linked List, Doubly Linked List, Queue, Object Deque, Array Deque, Stack, Hash, Coordinate Set, Coordinate Map, Heap, Priority Queue, Max Priority Queue, Min Priority Queue, Trie
7
-
8
- ## Algorithms list only a few out, you can discover more in API docs
3
+ This is a standalone Graph data structure from the data-structure-typed collection. If you wish to access more data structures or advanced features, you can transition to directly installing the complete [data-structure-typed](https://www.npmjs.com/package/data-structure-typed) package
9
4
 
10
- DFS, DFSIterative, BFS, morris, Bellman-Ford Algorithm, Dijkstra's Algorithm, Floyd-Warshall Algorithm, Tarjan's Algorithm
11
-
12
- ## Code design
13
- By strictly adhering to object-oriented design (BinaryTree -> BST -> AVLTree -> TreeMultiset), you can seamlessly inherit the existing data structures to implement the customized ones you need. Object-oriented design stands as the optimal approach to data structure design.
14
5
 
15
6
  # How
16
7
 
17
8
  ## install
18
- ### yarn
19
-
9
+ ### npm
20
10
  ```bash
21
- yarn add data-structure-typed
11
+ npm i graph-typed
22
12
  ```
23
-
24
- ### npm
25
-
13
+ ### yarn
26
14
  ```bash
27
- npm install data-structure-typed
15
+ yarn add graph-typed
28
16
  ```
29
17
 
30
- ### Binary Search Tree (BST) snippet
31
-
18
+ ### snippet
32
19
  #### TS
33
20
  ```typescript
34
- import {BST, BSTNode} from 'data-structure-typed';
35
-
36
- const bst = new BST();
37
- bst.add(11);
38
- bst.add(3);
39
- bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
40
- bst.size === 16; // true
41
- bst.has(6); // true
42
- const node6 = bst.get(6);
43
- bst.getHeight(6) === 2; // true
44
- bst.getHeight() === 5; // true
45
- bst.getDepth(6) === 3; // true
46
- const leftMost = bst.getLeftMost();
47
- leftMost?.id === 1; // true
48
- expect(leftMost?.id).toBe(1);
49
- bst.remove(6);
50
- bst.get(6); // null
51
- bst.isAVLBalanced(); // true or false
52
- const bfsIDs = bst.BFS();
53
- bfsIDs[0] === 11; // true
54
- expect(bfsIDs[0]).toBe(11);
55
-
56
- const objBST = new BST<BSTNode<{ id: number, keyA: number }>>();
57
- objBST.add(11, {id: 11, keyA: 11});
58
- objBST.add(3, {id: 3, keyA: 3});
59
-
60
- objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
61
- {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
62
- {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
63
- {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
64
- {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
65
-
66
- objBST.remove(11);
67
-
68
-
69
- const avlTree = new AVLTree();
70
- avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
71
- avlTree.isAVLBalanced(); // true
72
- avlTree.remove(10);
73
- avlTree.isAVLBalanced(); // true
74
21
 
75
22
  ```
76
23
  #### JS
77
24
  ```javascript
78
- const {BST, BSTNode} = require('data-structure-typed');
79
-
80
- const bst = new BST();
81
- bst.add(11);
82
- bst.add(3);
83
- bst.addMany([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
84
- bst.size === 16; // true
85
- bst.has(6); // true
86
- const node6 = bst.get(6);
87
- bst.getHeight(6) === 2; // true
88
- bst.getHeight() === 5; // true
89
- bst.getDepth(6) === 3; // true
90
- const leftMost = bst.getLeftMost();
91
- leftMost?.id === 1; // true
92
- expect(leftMost?.id).toBe(1);
93
- bst.remove(6);
94
- bst.get(6); // null
95
- bst.isAVLBalanced(); // true or false
96
- const bfsIDs = bst.BFS();
97
- bfsIDs[0] === 11; // true
98
- expect(bfsIDs[0]).toBe(11);
99
-
100
- const objBST = new BST();
101
- objBST.add(11, {id: 11, keyA: 11});
102
- objBST.add(3, {id: 3, keyA: 3});
103
-
104
- objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8},
105
- {id: 13, keyA: 13}, {id: 16, keyA: 16}, {id: 2, keyA: 2},
106
- {id: 6, keyA: 6}, {id: 9, keyA: 9}, {id: 12, keyA: 12},
107
- {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7},
108
- {id: 10, keyA: 10}, {id: 5, keyA: 5}]);
109
-
110
- objBST.remove(11);
111
-
112
-
113
- const avlTree = new AVLTree();
114
- avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5])
115
- avlTree.isAVLBalanced(); // true
116
- avlTree.remove(10);
117
- avlTree.isAVLBalanced(); // true
118
-
119
- ```
120
-
121
- ### Directed Graph simple snippet
122
25
 
123
- #### TS or JS
124
- ```typescript
125
- import {DirectedGraph} from 'data-structure-typed';
126
-
127
- const graph = new DirectedGraph();
128
-
129
- graph.addVertex('A');
130
- graph.addVertex('B');
131
-
132
- graph.hasVertex('A'); // true
133
- graph.hasVertex('B'); // true
134
- graph.hasVertex('C'); // false
135
-
136
- graph.addEdge('A', 'B');
137
- graph.hasEdge('A', 'B'); // true
138
- graph.hasEdge('B', 'A'); // false
139
-
140
- graph.removeEdgeSrcToDest('A', 'B');
141
- graph.hasEdge('A', 'B'); // false
142
-
143
- graph.addVertex('C');
144
-
145
- graph.addEdge('A', 'B');
146
- graph.addEdge('B', 'C');
147
-
148
- const topologicalOrderIds = graph.topologicalSort(); // ['A', 'B', 'C']
149
- ```
150
-
151
- ### Undirected Graph snippet
152
-
153
- #### TS or JS
154
- ```typescript
155
- import {UndirectedGraph} from 'data-structure-typed';
156
-
157
- const graph = new UndirectedGraph();
158
- graph.addVertex('A');
159
- graph.addVertex('B');
160
- graph.addVertex('C');
161
- graph.addVertex('D');
162
- graph.removeVertex('C');
163
- graph.addEdge('A', 'B');
164
- graph.addEdge('B', 'D');
165
-
166
- const dijkstraResult = graph.dijkstra('A');
167
- Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.id) // ['A', 'B', 'D']
168
26
  ```
169
27
 
170
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/dfs-pre-order.webp)
171
-
172
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/test-graphs.webp)
173
-
174
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/cut-off-trees-for-golf.webp)
175
-
176
- ![](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/examples/parenthesis-check.webp)
177
-
178
28
 
179
29
  ## API docs & Examples
180
30
 
@@ -182,10 +32,6 @@ import {UndirectedGraph} from 'data-structure-typed';
182
32
 
183
33
  [Live Examples](https://data-structure-typed-examples.vercel.app)
184
34
 
185
- <a href="https://data-structure-typed-examples.vercel.app" target="_blank">Live Examples</a>
186
-
187
- [//]: # ([Examples Repository]&#40;https://github.com/zrwusa/data-structure-typed-examples&#41;)
188
-
189
35
  <a href="https://github.com/zrwusa/data-structure-typed-examples" target="_blank">Examples Repository</a>
190
36
 
191
37
  ## Data Structures
@@ -203,10 +49,10 @@ import {UndirectedGraph} from 'data-structure-typed';
203
49
  <tbody>
204
50
  <tr>
205
51
  <td>Binary Tree</td>
206
- <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
207
- </img></td>
208
- <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt="">
209
- </img></td>
52
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""/>
53
+ </td>
54
+ <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""/>
55
+ </td>
210
56
  <td><a href="https://data-structure-typed-docs.vercel.app/classes/BinaryTree.html"><span>Binary Tree</span></a></td>
211
57
  <td><img src="https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/assets/tick.svg" alt=""></td>
212
58
  </tr>
@@ -653,46 +499,6 @@ import {UndirectedGraph} from 'data-structure-typed';
653
499
 
654
500
  ![complexities of data structures](https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/assets/data-structure-complexities.jpg)
655
501
 
656
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/bst-rotation.gif&#41;)
657
-
658
- [//]: # ()
659
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/binary-tree/avl-tree-inserting.gif&#41;)
660
-
661
- [//]: # ()
662
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan.webp&#41;)
663
-
664
- [//]: # ()
665
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list.jpg&#41;)
666
-
667
- [//]: # ()
668
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-list-pros-cons.jpg&#41;)
669
-
670
- [//]: # ()
671
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix.jpg&#41;)
672
-
673
- [//]: # ()
674
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/adjacency-matrix-pros-cons.jpg&#41;)
675
-
676
- [//]: # ()
677
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/dfs-can-do.jpg&#41;)
678
-
679
- [//]: # ()
680
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list.jpg&#41;)
681
-
682
- [//]: # ()
683
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/edge-list-pros-cons.jpg&#41;)
684
-
685
- [//]: # ()
686
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/max-flow.jpg&#41;)
687
-
688
- [//]: # ()
689
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/mst.jpg&#41;)
690
-
691
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-articulation-point-bridge.png&#41;)
692
-
693
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-complicate-simple.png&#41;)
694
-
695
- [//]: # (![]&#40;https://github.com/zrwusa/assets/blob/master/images/data-structure-typed/graph/tarjan-strongly-connected-component.png&#41;)
696
502
 
697
503
 
698
504
 
package/dist/index.d.ts CHANGED
@@ -1,2 +1,8 @@
1
- export * from './directed-graph';
2
- export * from './undirected-graph';
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ export { AbstractVertex, AbstractEdge, AbstractGraph, DirectedVertex, DirectedEdge, DirectedGraph, UndirectedVertex, UndirectedEdge, UndirectedGraph } from 'data-structure-typed';
package/dist/index.js CHANGED
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./directed-graph"), exports);
18
- __exportStar(require("./undirected-graph"), exports);
3
+ exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = exports.DirectedGraph = exports.DirectedEdge = exports.DirectedVertex = exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ var data_structure_typed_1 = require("data-structure-typed");
12
+ Object.defineProperty(exports, "AbstractVertex", { enumerable: true, get: function () { return data_structure_typed_1.AbstractVertex; } });
13
+ Object.defineProperty(exports, "AbstractEdge", { enumerable: true, get: function () { return data_structure_typed_1.AbstractEdge; } });
14
+ Object.defineProperty(exports, "AbstractGraph", { enumerable: true, get: function () { return data_structure_typed_1.AbstractGraph; } });
15
+ Object.defineProperty(exports, "DirectedVertex", { enumerable: true, get: function () { return data_structure_typed_1.DirectedVertex; } });
16
+ Object.defineProperty(exports, "DirectedEdge", { enumerable: true, get: function () { return data_structure_typed_1.DirectedEdge; } });
17
+ Object.defineProperty(exports, "DirectedGraph", { enumerable: true, get: function () { return data_structure_typed_1.DirectedGraph; } });
18
+ Object.defineProperty(exports, "UndirectedVertex", { enumerable: true, get: function () { return data_structure_typed_1.UndirectedVertex; } });
19
+ Object.defineProperty(exports, "UndirectedEdge", { enumerable: true, get: function () { return data_structure_typed_1.UndirectedEdge; } });
20
+ Object.defineProperty(exports, "UndirectedGraph", { enumerable: true, get: function () { return data_structure_typed_1.UndirectedGraph; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graph-typed",
3
- "version": "1.19.3",
3
+ "version": "1.19.6",
4
4
  "description": "Graph. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -62,7 +62,7 @@
62
62
  "typescript": "^4.9.5"
63
63
  },
64
64
  "dependencies": {
65
- "data-structure-typed": "^1.19.3",
65
+ "data-structure-typed": "1.19.6",
66
66
  "zod": "^3.22.2"
67
67
  }
68
68
  }
package/tsconfig.json CHANGED
@@ -3,9 +3,10 @@
3
3
  "declaration": true,
4
4
  "outDir": "./dist",
5
5
  "module": "commonjs",
6
- "target": "es5",
6
+ "target": "es6",
7
7
  "lib": [
8
- "esnext",
8
+ // "es2015",
9
+ "esnext"
9
10
  ],
10
11
  "strict": true,
11
12
  "esModuleInterop": true,
@@ -30,8 +31,9 @@
30
31
  "src",
31
32
  ],
32
33
  "exclude": [
33
- // "node_modules/data-structure-typed",
34
+ // "node_modules/data-structure-typed",
34
35
  "node_modules",
35
36
  "dist"
36
37
  ]
37
- }
38
+ }
39
+
@@ -1,200 +0,0 @@
1
- import { AbstractEdge, AbstractGraph, AbstractVertex } from 'data-structure-typed';
2
- import type { VertexId } from 'data-structure-typed';
3
- import { IDirectedGraph } from 'data-structure-typed';
4
- export declare class DirectedVertex<T = number> extends AbstractVertex<T> {
5
- /**
6
- * The constructor function initializes a vertex with an optional value.
7
- * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
8
- * used to uniquely identify the vertex within a graph or data structure.
9
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
10
- * vertex. If no value is provided, the vertex will be initialized with a default value.
11
- */
12
- constructor(id: VertexId, val?: T);
13
- }
14
- export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
15
- /**
16
- * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
17
- * and value.
18
- * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
19
- * a graph.
20
- * @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
21
- * `VertexId`, which is likely a unique identifier for a vertex in a graph.
22
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
23
- * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
24
- * the edge.
25
- */
26
- constructor(src: VertexId, dest: VertexId, weight?: number, val?: T);
27
- private _src;
28
- get src(): VertexId;
29
- set src(v: VertexId);
30
- private _dest;
31
- get dest(): VertexId;
32
- set dest(v: VertexId);
33
- }
34
- export declare class DirectedGraph<V extends DirectedVertex<any> = DirectedVertex, E extends DirectedEdge<any> = DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
35
- /**
36
- * The constructor function initializes an instance of a class.
37
- */
38
- constructor();
39
- private _outEdgeMap;
40
- get outEdgeMap(): Map<V, E[]>;
41
- private _inEdgeMap;
42
- get inEdgeMap(): Map<V, E[]>;
43
- /**
44
- * 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.
45
- * 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.
46
- */
47
- /**
48
- * The function creates a new vertex with an optional value and returns it.
49
- * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
50
- * could be a number or a string depending on how you want to identify your vertices.
51
- * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
52
- * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
53
- * assigned the same value as the 'id' parameter
54
- * @returns a new instance of a DirectedVertex object, casted as type V.
55
- */
56
- createVertex(id: VertexId, val?: V['val']): V;
57
- /**
58
- * 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.
59
- * 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.
60
- */
61
- /**
62
- * The function creates a directed edge between two vertices with an optional weight and value.
63
- * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
64
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
65
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
66
- * weight is provided, it defaults to 1.
67
- * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
68
- * is used to store additional information or data associated with the edge.
69
- * @returns a new instance of a DirectedEdge object, casted as type E.
70
- */
71
- createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
72
- /**
73
- * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
74
- * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
75
- * @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
76
- * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
77
- * destination is not specified.
78
- * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
79
- */
80
- getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
81
- /**
82
- * The function removes an edge between two vertices in a graph and returns the removed edge.
83
- * @param {V | VertexId} srcOrId - The source vertex or its ID.
84
- * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
85
- * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
86
- */
87
- removeEdgeSrcToDest(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
88
- /**
89
- * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
90
- * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
91
- * and `dest`, which represent the source and destination vertices of the edge, respectively.
92
- * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
93
- */
94
- removeEdge(edge: E): E | null;
95
- /**
96
- * The function removes edges between two vertices and returns the removed edges.
97
- * @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
98
- * unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
99
- * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
100
- * the second vertex in the edge that needs to be removed.
101
- * @returns an array of removed edges (E[]).
102
- */
103
- removeEdgesBetween(v1: VertexId | V, v2: VertexId | V): E[];
104
- /**
105
- * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
106
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
107
- * (`VertexId`).
108
- * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
109
- */
110
- incomingEdgesOf(vertexOrId: V | VertexId): E[];
111
- /**
112
- * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
113
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
114
- * (`VertexId`).
115
- * @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
116
- */
117
- outgoingEdgesOf(vertexOrId: V | VertexId): E[];
118
- /**
119
- * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
120
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
121
- * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
122
- */
123
- degreeOf(vertexOrId: VertexId | V): number;
124
- /**
125
- * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
126
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
127
- * @returns The number of incoming edges of the specified vertex or vertex ID.
128
- */
129
- inDegreeOf(vertexOrId: VertexId | V): number;
130
- /**
131
- * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
132
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
133
- * @returns The number of outgoing edges from the specified vertex or vertex ID.
134
- */
135
- outDegreeOf(vertexOrId: VertexId | V): number;
136
- /**
137
- * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
138
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
139
- * @returns The function `edgesOf` returns an array of edges.
140
- */
141
- edgesOf(vertexOrId: VertexId | V): E[];
142
- /**
143
- * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
144
- * @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
145
- * @returns either a vertex object (V) or null.
146
- */
147
- getEdgeSrc(e: E): V | null;
148
- /**
149
- * The function "getEdgeDest" returns the destination vertex of an edge.
150
- * @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
151
- * @returns either a vertex object of type V or null.
152
- */
153
- getEdgeDest(e: E): V | null;
154
- /**
155
- * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
156
- * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
157
- * find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
158
- * @returns an array of vertices (V[]).
159
- */
160
- getDestinations(vertex: V | VertexId | null): V[];
161
- /**
162
- * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
163
- * in the sorted order, or null if the graph contains a cycle.
164
- * @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
165
- * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
166
- * specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
167
- * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
168
- */
169
- topologicalSort(propertyName?: 'vertex' | 'id'): Array<V | VertexId> | null;
170
- /**
171
- * The `edgeSet` function returns an array of all the edges in the graph.
172
- * @returns The `edgeSet()` method returns an array of edges (`E[]`).
173
- */
174
- edgeSet(): E[];
175
- /**
176
- * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
177
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
178
- * (`VertexId`).
179
- * @returns an array of vertices (V[]).
180
- */
181
- getNeighbors(vertexOrId: V | VertexId): V[];
182
- /**
183
- * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
184
- * otherwise it returns null.
185
- * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
186
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
187
- * graph. If the edge does not exist, it returns `null`.
188
- */
189
- getEndsOfEdge(edge: E): [V, V] | null;
190
- /**
191
- * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
192
- * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
193
- * needs to be added to the graph.
194
- * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
195
- * source or destination vertex does not exist in the graph.
196
- */
197
- protected _addEdgeOnly(edge: E): boolean;
198
- protected _setOutEdgeMap(value: Map<V, E[]>): void;
199
- protected _setInEdgeMap(value: Map<V, E[]>): void;
200
- }