forked from datavis-tech/graph-data-structure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
46 lines (46 loc) · 1.83 KB
/
index.d.ts
File metadata and controls
46 lines (46 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
declare type NodeId = string;
declare type EdgeWeight = number;
declare type EdgeId = string;
export interface Serialized {
nodes: {
id: NodeId;
}[];
links: {
source: NodeId;
target: NodeId;
weight: EdgeWeight;
id: EdgeId;
}[];
}
declare function Graph(serialized?: Serialized): GraphInstance;
export default Graph;
export interface GraphInstance {
addNode: (node: NodeId) => GraphInstance;
removeNode: (node: NodeId) => GraphInstance;
nodes: () => NodeId[];
adjacent: (node: NodeId) => NodeId[];
addEdge: (u: NodeId, v: NodeId, weight?: number, edgeId?: string) => GraphInstance;
getEdges: () => Record<string, string[]>;
removeEdge: (u: NodeId, v: NodeId) => GraphInstance;
hasEdge: (u: NodeId, v: NodeId) => boolean;
setEdgeWeight: (u: NodeId, v: NodeId, weight: EdgeWeight) => GraphInstance;
getEdgeWeight: (u: NodeId, v: NodeId) => EdgeWeight;
setEdgeId: (u: NodeId, v: NodeId, edgeId: string) => GraphInstance;
getEdgeId: (u: NodeId, v: NodeId) => string;
indegree: (node: NodeId) => number;
outdegree: (node: NodeId) => number;
depthFirstSearch: (sourceNodes?: string[] | undefined, options?: {
includeSourceNodes: boolean;
errorOnCycle: boolean;
}) => string[] | Record<string, string>;
hasCycle: () => boolean;
getCycles: (sourceNodes?: string[] | undefined) => [NodeId, NodeId][];
walk: (onElement: (node: NodeId) => void) => void;
lowestCommonAncestors: (node1: NodeId, node2: NodeId) => string[];
topologicalSort: (sourceNodes?: string[] | undefined, includeSourceNodes?: boolean) => string[];
shortestPath: (source: NodeId, destination: NodeId) => string[] & {
weight?: number | undefined;
};
serialize: () => Serialized;
deserialize: (serialized: Serialized) => GraphInstance;
}