graph-by-ivan-tulaev
Version:
Graph library for traversing and processing any directional graphs.
56 lines (41 loc) • 2.38 kB
TypeScript
export declare type AddNextNodesToExecutionSequence<N> = (nodes: Array<N>, executionSequence: Array<N>) => void;
export declare function addToEnd<N>(nodes: Array<N>, executionSequence: Array<N>): void;
export declare function addToStart<N>(nodes: Array<N>, executionSequence: Array<N>): void;
export declare type ExecuteCurrentFunction<N> = (node: N) => void;
export declare function getFirst<N>(executionSequence: Array<N>): N | undefined;
export declare function getFirstUnvisited<N>(visited: Set<N>, initialGraph: Graph<N>): N | undefined;
export declare function getLast<N>(executionSequence: Array<N>): N | undefined;
export declare type GetNextFromExecutionSequence<N> = (executionSequence: Array<N>) => N | undefined;
export declare type GetNextNodesFunction<N> = (node: N, graph: Graph<N>, visited: Set<N>) => Array<N> | undefined;
export declare function getNotVisitedIncomingNodes<N>(node: N, graph: Graph<N>, visited: Set<N>): N[];
export declare function getNotVisitedOutgoingNodes<N>(node: N, graph: Graph<N>, visited: Set<N>): N[];
export declare type GetStartElementFunction<N> = (visited: Set<N>, initialGraph: Graph<N>) => N | undefined;
export declare class Graph<N> {
notDirected: boolean;
private _adjacencyList;
constructor(notDirected?: boolean);
get nodes(): N[];
addNode(node: N): void;
deleteNode(node: N): void;
get edges(): Set<IEdge<N>>;
addEdge(edge: IEdge<N>): void;
deleteEdge(edge: IEdge<N>): void;
getIncomingEdgesFor(node: N): Set<IEdge<N>>;
getOutgoingEdgesFor(node: N): Set<IEdge<N>>;
/**
* @param getStartElement
* @param getNextFromExecutionSequence
* @param getNextNodes will be sorted
* @param addNextNodesToExecutionSequence
* @param executeCurrent
*/
genericTraversing(getStartElement: GetStartElementFunction<N>, getNextFromExecutionSequence: GetNextFromExecutionSequence<N>, getNextNodes: GetNextNodesFunction<N>, addNextNodesToExecutionSequence: AddNextNodesToExecutionSequence<N>, executeCurrent?: ExecuteCurrentFunction<N>): void;
getSeparatedGraphs(): Graph<N>[];
isNodeTraced(node: N, to: N | Array<N>, backward?: boolean): boolean;
static mergeGraphs<N>(graphs: Set<Graph<N>>): Graph<N>;
}
export declare interface IEdge<N> {
source: N;
target: N;
}
export { }