UNPKG

graph-builder

Version:

A graph builder library for modeling abstract graph structures.

56 lines (55 loc) 2.55 kB
import { Graph } from "./Graph"; /** * An immutable pair representing the two endpoints of an edge in a graph. The {@link EndpointPair} * of a directed edge is an ordered pair of nodes ({@link EndpointPair.source} and * {@link EndpointPair.target}). The {@link EndpointPair} of an undirected edge is an * unordered pair of nodes ({@link EndpointPair.nodeU} and {@link EndpointPair.nodeV}). * * The edge is a self-loop if, and only if, the two endpoints are equal. * * @public */ export declare abstract class EndpointPair<N> implements Iterable<N> { readonly nodeU: N; readonly nodeV: N; constructor(nodeU: N, nodeV: N); /** Returns an {@link EndpointPair} representing the endpoints of a directed edge. */ static ordered<N>(source: N, target: N): EndpointPair<N>; /** Returns an {@link EndpointPair} representing the endpoints of an undirected edge. */ static unordered<N>(nodeU: N, nodeV: N): EndpointPair<N>; /** Returns an {@link EndpointPair} representing the endpoints of an edge in `graph`. */ static of<N>(graph: Graph<any>, nodeU: N, nodeV: N): EndpointPair<N>; /** Returns an {@link EndpointPair} representing the endpoints of an edge in `network`. */ /** * If this {@link EndpointPair} {@link EndpointPair.isOrdered}, returns the node which is the source. * * Throws an error if this {@link EndpointPair} is not ordered. */ abstract source(): N; /** * If this {@link EndpointPair} {@link EndpointPair.isOrdered}, returns the node which is the target. * * Throws an error if this {@link EndpointPair} is not ordered. */ abstract target(): N; /** * Returns the node that is adjacent to `node` along the origin edge. * * Throws an error if this {@link EndpointPair} does not contain `node`. */ adjacentNode(node: N): N; /** * Returns `true` if this {@link EndpointPair} is an ordered pair (i.e. represents the * endpoints of a directed edge). */ abstract isOrdered(): boolean; /** Iterates in the order {@link EndpointPair.nodeU}, {@link EndpointPair.nodeV}. */ [Symbol.iterator](): IterableIterator<N>; /** * Two ordered {@link EndpointPair}s are equal if their {@link EndpointPair.source} * and {@link EndpointPair.target} are equal. Two unordered {@link EndpointPair}s are * equal if they contain the same nodes. An ordered {@link EndpointPair} is never * equal to an unordered {@link EndpointPair}. */ abstract equals(obj?: Object): boolean; }