tstruct
Version:
Data structures & basic algorithms library
41 lines (40 loc) • 1.2 kB
TypeScript
export interface Connection<T> {
from: T;
to: T;
weight?: number;
bidirectional?: boolean;
}
export interface IGraph<T> {
add(vertex: T): void;
connect(connection: Connection<T>): void;
connectionExists(connection: Connection<T>): boolean;
exists(node: T): boolean;
getVertices(): T[];
getEdges(): Connection<T>[];
getEdgesFor(vertex: T): Connection<T>[];
minimumSpanningTree(): Graph<T>;
shortestPath(from: T, to: T): T[];
}
export declare class Graph<T> implements IGraph<T> {
private _adjacencyList;
private _hasNegativeWeights;
constructor();
add(vertex: T): void;
connect(connection: Connection<T>): void;
exists(node: T): boolean;
connectionExists(connection: Connection<T>): boolean;
getVertices(): T[];
getEdges(): Connection<T>[];
getEdgesFor(vertex: T): Connection<T>[];
minimumSpanningTree(): Graph<T>;
shortestPath(from: T, to: T): T[];
bellmanFord(from: T, to: T): {
distance: number;
path: T[];
};
dijkstra(from: T, to: T): {
distance: number;
path: T[];
};
private newConnectionPriorityQueue;
}