@cedoor/nfa
Version:
TypeScript implementation of some network flow algorithms.
73 lines (72 loc) • 2.12 kB
TypeScript
import Node from "./node";
/**
* The Graph class is a data structure that allow you to create a directed
* graph, in which to add, remove and modify nodes and arcs
* in constant time. Nodes and arcs are stored in maps.
*/
export default class Graph {
private nodes;
constructor(graphData?: GraphData);
/**
* Adds a node in the graph.
* @param {Node} The node to add.
*/
addNode(node: Node): void;
/**
* Removes a node from the graph.
* @param {number} The id of the node to remove.
*/
removeNode(id: number): void;
/**
* Returns a node from the graph.
* @param {number} The id of the node to return.
* @returns {Node} The node to return.
*/
getNode(id: number): Node;
/**
* Checks if there is a node in the graph.
* @param {number} The id of the node to check.
* @param {boolean} True if the node exists, false otherwise.
*/
hasNode(id: number): boolean;
/**
* Returns all the nodes of the graph.
* @returns {Node[]} The graph nodes.
*/
getNodes(): Node[];
/**
* Returns the number of the nodes of the graph.
* @returns {number} The number of the graph nodes.
*/
size(): number;
/**
* Returns an instance of the copy of the current graph.
*/
copy(): Graph;
/**
* Checks the integrity of the graph. All the arcs
* must have an existing head node.
* @returns {number} True if the graph is correct, false otherwise.
*/
checkIntegrity(): boolean;
/**
* Returns the graph data of the graph.
* @returns {GraphData} The graph data.
*/
export(): GraphData;
}
/**
* Type used to define the structure of the graph data
* which can be passed into the graph class constructor
* to create a graph using external data (i.e. JSON data).
*/
export declare type GraphData = {
id: number;
balance: number;
arcs: {
head: number;
cost: number;
capacity: number;
flow?: number;
}[];
}[];