graph-builder
Version:
A graph builder library for modeling abstract graph structures.
35 lines (34 loc) • 1.33 kB
TypeScript
/**
* An interface for representing and manipulating an origin node's adjacent nodes and edge values in
* a {@link Graph}.
*
* @public
*/
export interface GraphConnections<N, V> {
adjacentNodes(): Set<N>;
predecessors(): Set<N>;
successors(): Set<N>;
/**
* Returns the value associated with the edge connecting the origin node to `node`, or undefined
* if there is no such edge.
*/
value(node: N): V | undefined;
/** Remove `node` from the set of predecessors. */
removePredecessor(node: N): void;
/**
* Remove `node` from the set of successors. Returns the value previously associated with
* the edge connecting the two nodes.
*/
removeSuccessor(node: N): V | undefined;
/**
* Add `node` as a predecessor to the origin node. In the case of an undirected graph, it
* also becomes a successor. Associates `value` with the edge connecting the two nodes.
*/
addPredecessor(node: N, value: V): void;
/**
* Add `node` as a successor to the origin node. In the case of an undirected graph, it also
* becomes a predecessor. Associates `value` with the edge connecting the two nodes. Returns
* the value previously associated with the edge connecting the two nodes.
*/
addSuccessor(node: N, value: V): V | undefined;
}