-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgraph.ts
More file actions
32 lines (29 loc) · 808 Bytes
/
graph.ts
File metadata and controls
32 lines (29 loc) · 808 Bytes
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
export class Vertex {
constructor(
public readonly id: string,
public value: number,
public readonly ins: string[] = [],
public readonly outs: string[] = []
) {}
}
export class Edge {
constructor(
public readonly id: string,
public readonly from: string,
public readonly to: string,
public weight: number | null,
public name: string | null,
public readonly directed: boolean
) {}
/**
* Checks if an edge is defined between provided vertexIds.
* Order in which vertices are given does not matter.
*/
between(aId: string, bId: string) {
return (this.from === aId && this.to === bId) || (this.from === bId && this.to === aId);
}
}
export type Graph = {
readonly edges: Record<string, Edge>;
readonly vertices: Record<string, Vertex>;
};