-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.ts
More file actions
45 lines (37 loc) · 787 Bytes
/
interfaces.ts
File metadata and controls
45 lines (37 loc) · 787 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
33
34
35
36
37
38
39
40
41
42
43
44
45
// DG - Directed Graph
// DAG - Directed Acyclic Graph
// [parent, child, distance]
export type Edge<T> = [T, T, number];
export interface EdgeDef<T> {
from: T;
to: T;
distance: number;
}
export type TransitiveClosure<T> = {
parent: T;
child: T;
distance: number;
};
export const INF = Number.MAX_SAFE_INTEGER;
export function add(x: number, y: number): number {
if (x === INF || y === INF) {
return INF;
}
return x + y;
}
export interface ShortestPath<T> {
path: T[];
distance: number;
}
export interface ShortestPathAlgo<T, E extends EdgeDef<T>> {
calculate(
srcNode: T,
dstNode: T,
distFn: (edge: E) => number,
): ShortestPath<T>;
}
export interface PriorityQueue<T> {
push(node: T): void;
pop(): T | undefined;
size: number;
}