• 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,
    })

    Type Parameters

    • V

    • E extends {
          from: V;
          to: V;
      }

    Parameters

    • edges: readonly E[]
    • Optional nodes: readonly V[]

    Returns ReadonlyMap<V, readonly Path<V, E>[]>

  • Type Parameters

    • V

    • E

    Parameters

    • edges: readonly E[]
    • nodes: readonly V[]
    • fn: GetEdge<V, E>

    Returns ReadonlyMap<V, readonly Path<V, E>[]>

Generated using TypeDoc