@eggjs/tegg-common-util
Version:
common util for tegg
67 lines (66 loc) • 2.05 kB
TypeScript
import type { GraphNodeObj } from '@eggjs/tegg-types';
declare const inspect: unique symbol;
export interface EdgeMeta {
equal(meta: EdgeMeta): boolean;
toString(): string;
}
export declare class GraphNode<T extends GraphNodeObj, M extends EdgeMeta = EdgeMeta> {
val: T;
toNodeMap: Map<string, {
node: GraphNode<T, M>;
meta?: M;
}>;
fromNodeMap: Map<string, {
node: GraphNode<T, M>;
meta?: M;
}>;
constructor(val: T);
get id(): string;
addToVertex(node: GraphNode<T, M>, meta?: M): boolean;
addFromVertex(node: GraphNode<T, M>, meta?: M): boolean;
[inspect](): {
val: T;
toNodes: {
node: GraphNode<T, M>;
meta?: M;
}[];
fromNodes: {
node: GraphNode<T, M>;
meta?: M;
}[];
};
toJSON(): {
val: T;
toNodes: {
node: GraphNode<T, M>;
meta?: M;
}[];
fromNodes: {
node: GraphNode<T, M>;
meta?: M;
}[];
};
toString(): string;
}
export declare class GraphPath<T extends GraphNodeObj, M extends EdgeMeta = EdgeMeta> {
nodeIdMap: Map<string, number>;
nodes: Array<{
node: GraphNode<T, M>;
meta?: M;
}>;
pushVertex(node: GraphNode<T, M>, meta?: M): boolean;
popVertex(): void;
toString(): string;
[inspect](): string;
}
export declare class Graph<T extends GraphNodeObj, M extends EdgeMeta = EdgeMeta> {
nodes: Map<string, GraphNode<T, M>>;
addVertex(node: GraphNode<T, M>): boolean;
addEdge(from: GraphNode<T, M>, to: GraphNode<T, M>, meta?: M): boolean;
findToNode(id: string, meta: M): GraphNode<T, M> | undefined;
appendVertexToPath(node: GraphNode<T, M>, accessPath: GraphPath<T, M>, meta?: M): boolean;
loopPath(): GraphPath<T, M> | undefined;
accessNode(node: GraphNode<T, M>, nodes: Array<GraphNode<T, M>>, accessed: boolean[], res: Array<GraphNode<T, M>>): void;
sort(): Array<GraphNode<T, M>>;
}
export {};