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

    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