/** * A vertex (node) in a directed graph, holding metadata and a list of connected edges. * @typeParam VMetadata - The type of metadata stored on vertices * @typeParam EMetadata - The type of metadata stored on edges */ export type Vertex = { metadata: VMetadata; edges: Array>; }; /** * A directed edge connecting two vertices, with its own metadata. * @typeParam EMetadata - The type of metadata stored on edges * @typeParam VMetadata - The type of metadata stored on the connected vertices */ export type Edge = { metadata: EMetadata; from: Vertex; to: Vertex; }; /** * A directed graph data structure supporting vertex/edge management and graph traversal algorithms * including breadth-first search, reverse BFS, and shortest path computation. * * @typeParam VMetadata - The type of metadata stored on vertices * @typeParam EMetadata - The type of metadata stored on edges */ export declare class Graph { private readonly vertices; constructor(); /** * Serializes the graph to a JSON string for debugging. * @param metadataRepr - Optional function to transform metadata values before serialization * @returns A pretty-printed JSON string of the graph structure */ dump(metadataRepr?: (metadata: VMetadata | EMetadata) => any): string; /** * Adds a new vertex to the graph, optionally connecting it to existing vertices via edges. * @param metadata - The metadata to attach to the new vertex * @param fromEdges - Edges pointing from existing vertices to this new vertex * @param toEdges - Edges pointing from this new vertex to existing vertices * @returns The newly created vertex */ addVertex(metadata: VMetadata, fromEdges: Array, 'to'>>, toEdges: Array, 'from'>>): Vertex; /** * Returns a generator that yields all vertices matching the predicate. * @param predicate - A function to test each vertex * @returns A generator of matching vertices */ findVertex(predicate: (vertex: Vertex) => boolean): Generator, null>; /** * Adds a directed edge between two existing vertices. * @param metadata - The metadata to attach to the edge * @param from - The source vertex * @param to - The destination vertex * @returns The newly created edge */ addEdge(metadata: EMetadata, from: Vertex, to: Vertex): Edge; /** * Performs a breadth-first traversal following outgoing edges from the starting vertex or vertices. * @param from - A starting vertex, or a predicate to select multiple starting vertices * @returns A generator yielding vertices in BFS order */ breadthFirstSearch(from: Vertex | ((vertex: Vertex) => boolean)): Generator, null>; /** * Performs a reverse breadth-first traversal following incoming edges from the starting vertex or vertices. * @param to - A starting vertex, or a predicate to select multiple starting vertices * @returns A generator yielding vertices in reverse BFS order */ reverseBreadthFirstSearch(to: Vertex | ((vertex: Vertex) => boolean)): Generator, null>; /** * Finds the shortest path (by edge count) between two vertices using BFS. * @param from - The starting vertex, or a predicate to select starting vertices * @param to - The target vertex, or a predicate to identify target vertices * @returns An array of edges forming the shortest path, or `null` if no path exists */ shortestPath(from: Vertex | ((vertex: Vertex) => boolean), to: Vertex | ((vertex: Vertex) => boolean)): Array> | null; }