UNPKG

graph-by-ivan-tulaev

Version:

Graph library for traversing and processing any directional graphs.

58 lines (43 loc) 2.56 kB
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>, executionSequence: Array<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 getNextNodes get not visited outgoing elements by default * @param getStartElement get first unvisited by default * @param getNextFromExecutionSequence get last by default * @param addNextNodesToExecutionSequence add to end by default * @param executeCurrent */ genericTraversing(getNextNodes?: GetNextNodesFunction<N>, getStartElement?: GetStartElementFunction<N>, getNextFromExecutionSequence?: GetNextFromExecutionSequence<N>, addNextNodesToExecutionSequence?: AddNextNodesToExecutionSequence<N>, executeCurrent?: ExecuteCurrentFunction<N>): void; createCopy(): Graph<unknown>; 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 { }