UNPKG

@endo/compartment-mapper

Version:

The compartment mapper assembles Node applications in a sandbox

66 lines 2.25 kB
/** * A generic graph implementation. * * @template {GenericGraphNode} [T=string] The type of nodes in the graph. If * `T` is not a string, relative paths will be compared by coercion to strings. */ export class GenericGraph<T extends GenericGraphNode = string> { /** * Returns a shallow copy of the `Set` of nodes in the graph. */ get nodes(): Set<T>; /** * Adds a node to the graph. * If node was already added, this function does nothing. * If node was not already added, this function sets up an empty adjacency list. * @param {T} node Node to add * @returns {this} This graph instance */ addNode(node: T): this; /** * Removes a node from the graph. * Also removes incoming and outgoing edges. * @param {T} node * @returns {this} */ removeNode(node: T): this; /** * Gets the adjacent nodes set for the given node. * @param {T} node * @returns {Set<T>|undefined} */ adjacent(node: T): Set<T> | undefined; /** * Adds an edge from the `source` node to `target` node. * * This method will create the `source` and `target` node(s) if they do not * already exist. * * If {@link T `T`} is an object, the comparison is by-reference. * * @param {T} source Source node * @param {T} target Target node * @returns {this} This graph instance */ addEdge(source: T, target: T): this; /** * Removes the edge from the `source` node to `target` node. * Does not remove the nodes themselves. * Does nothing if the edge does not exist. * @param {T} source * @param {T} target * @returns {this} */ removeEdge(source: T, target: T): this; /** * Returns true if there is an edge from the `source` node to `target` node. * @param {T} source * @param {T} target * @returns {boolean} */ hasEdge(source: T, target: T): boolean; #private; } export function makeShortestPath<T extends GenericGraphNode = string>(graph: GenericGraph<T>): (source: NoInfer<T>, target: NoInfer<T>) => [T, T, ...T[]]; import type { GenericGraphNode } from './types/generic-graph.js'; //# sourceMappingURL=generic-graph.d.ts.map