fp-search-algorithms
Version:
Functional Programming Style Search Algorithms and Unordered Containers
165 lines (164 loc) • 3.69 kB
TypeScript
/**
* Tuple representing an Edge between to Vertices
*
* @category Structures
*/
export type Edge<V> = [from: V, to: V];
/**
* Port of Erlang's digraph
* WIP
*
* @category Structures
*/
export declare class DirectedGraph<V, L = unknown> {
private cyclical;
private vertices;
private edges;
constructor(options?: {
cyclical?: boolean;
});
/**
* @group Vertices
*/
addVertex(vertex: V): DirectedGraph<V, L>;
/**
* @group Vertices
*/
deleteVertex(vertex: V): boolean;
/**
* @group Vertices
*/
deleteVertices(vertices: V[]): boolean[];
private inEdgesIterator;
private outEdgesIterator;
private edgesIterator;
/**
* Return all edges fora given vertex in an unspecified order
*
* @group Vertices
* */
getEdges(vertex: V): Edge<V>[];
/**
* @group Vertices
*/
inDegree(vertex: V): number;
/**
* @group Vertices
*/
outDegree(vertex: V): number;
/**
* @group Vertices
*/
inNeighbors(vertex: V): V[];
/**
* @group Vertices
*/
outNeighbors(vertex: V): V[];
/**
* @group Edges
*/
addEdge(from: V, to: V): this;
/**
* @group Edges
*/
deleteEdge(edge: Edge<V>): boolean;
/**
* @group Edges
*/
deleteEdges(edges: Edge<V>[]): boolean[];
/**
* @group Edges
*/
inEdges(vertex: V): Edge<V>[];
/**
* @group Edges
*/
outEdges(vertex: V): Edge<V>[];
/** return all vertices */
/**
* Returns number of vertices
*
* @group Helpers
*/
numVertices(): number;
/**
* Returns number of edges
*
* @group Helpers
*/
numEdges(): number;
/**
* If a simple cycle of length two or more exists through a vertex, the cycle is returned as a list [V, ..., V] of vertices.
* If a loop through the vertex exists, the loop is returned as a list [V]. If no cycles exist, undefined is returned.
*
* @group Advanced
*/
getCycle(vertex: V): V[] | undefined;
/**
* Tries to find an as short as possible simple cycle through a vertex.
* Returns the cycle as a list [V, ..., V] of vertices, or undefined if no simple cycle exists.
* Notice that a loop through the vertex is returned as list [V, V].
*
* @group Advanced
*/
getShortCycle(vertex: V): V[] | undefined;
/**
* @group Advanced
*/
getPath(from: V, to: V): V[] | undefined;
/**
* @group Advanced
*/
getShortPath(from: V, to: V): V[] | undefined;
/**
* Delete all paths found between two vertices.
* Returns false if not paths found, otherwise returns true
*
* @group Advanced
*/
deletePath(from: V, to: V): boolean;
/**
* @group Advanced
*/
components(): V[][];
/**
* Returns true if and only if the DirectedGraph is acyclic.
*
* @group Advanced
*/
isAcyclic(): boolean;
/**
* Returns true if and only if the DirectedGraph is a tree.
*
* @group Advanced
*/
isTree(): boolean;
/**
* @group Advanced
*/
reachable(vertices: V[]): V[];
/**
* @group Advanced
*/
reachableNeighbors(vertices: V[]): V[];
/**
* @group Advanced
*/
postOrder(): V[];
/**
* @group Advanced
*/
preOrder(): V[];
/**
* @group Advanced
*/
topsort(): V[];
/**
* TODO: find a better name
* TODO: look into optimizing this for javascript
*/
private onePath;
private shortPath;
private followPath;
private postGenerate;
}