/** * Describes how to interact with an arbitrary edge type. * * Your graph's edges can be any format, as long as you supply the appropriate accessors. * * type Vertex = object * type Edge1 = {from: Vertex, to: Vertex} * const getEdge1 = {from: (e: Edge1) => e.from, to: (e: Edge1) => e.to} * * type Edge2 = {parent: Vertex, child: Vertex} * const getEdge2 = {from: (e: Edge1) => e.parent, to: (e: Edge1) => e.child} */ export interface GetEdge { from: (edge: E) => V; to: (edge: E) => V; } /** * A list of edges starting at vertex `from` that lead to vertex `to`. * * Returned by the various path-building functions in this module. Don't construct these yourself. */ export interface Path { readonly from: V; readonly to: V; readonly path: E[]; } /** * Construct every possible path between every node in your graph, grouped by the node they *start* at. * * Every node has a zero-length path from itself. * * // a -> d * // b -> c -> d * * import {Graph} from "@erosson/polynomial" * const paths = Graph.allOutgoingPaths([{from: 'a', to: 'd'}, {from: 'b', to: 'c'}, {from: 'c', to: 'd'}]) * paths.get('a') // length 2: [a -> a], [a -> d] * paths.get('b') // length 3: [b -> b], [b -> c], [b -> c -> d] * paths.get('c') // length 2: [c -> c], [c -> d] * paths.get('d') // length 1: [d -> d] * * The default edge accessors are the `from` and `to` keys. Pass a pair of getters, and your edges can be any other format: * * import {Graph} from "@erosson/polynomial" * const paths = Graph.allOutgoingPaths([{parent: 'a', child: 'd'}, {parent: 'b', child: 'c'}, {parent: 'c', child: 'd'}], { * from: (e) -> e.parent, * to: (e) -> e.child, * }) */ export declare function allOutgoingPaths(edges: readonly E[], nodes?: readonly V[]): ReadonlyMap[]>; export declare function allOutgoingPaths(edges: readonly E[], nodes: readonly V[], fn: GetEdge): ReadonlyMap[]>; /** * Construct every possible path between every node in your graph, grouped by the node they *finish* at. * * Every node has a zero-length path to itself. * * // a -> d * // b -> c -> d * * import {Graph} from "@erosson/polynomial" * const paths = Graph.allIncomingPaths([{from: 'a', to: 'd'}, {from: 'b', to: 'c'}, {from: 'c', to: 'd'}]) * paths.get('a') // length 1: [a -> a] * paths.get('b') // length 1: [b -> b] * paths.get('c') // length 2: [c -> c], [b -> c] * paths.get('d') // length 4: [d -> d], [a -> d], [c -> d], [b -> c -> d] * * The default edge accessors are the `from` and `to` keys. Pass a pair of getters, and your edges can be any other format: * * import {Graph} from "@erosson/polynomial" * const paths = Graph.allIncomingPaths([{parent: 'a', child: 'd'}, {parent: 'b', child: 'c'}, {parent: 'c', child: 'd'}], { * from: (e) -> e.parent, * to: (e) -> e.child, * }) */ export declare function allIncomingPaths(edges: readonly E[], nodes?: readonly V[]): ReadonlyMap[]>; export declare function allIncomingPaths(edges: readonly E[], nodes: readonly V[], fn: GetEdge): ReadonlyMap[]>;