import Node from './node'; import Edge from './edge'; export default class Graph { nodes: Node[]; edges: Edge[]; private nodeMap; private edgeMap; /** * Creates a new graph. */ constructor(); /** * Finds a node by name. * @param name The name of the node. */ findNode(id: string): Node | null; /** * Returns whether a node with a given id exists in the graph. * @param id The id of the node. */ hasNode(id: string): boolean; /** * Finds an edge by name. * @param name The name of the edge. */ findEdge(name: string): Edge | null; /** * Returns whether an edge with a given name exists in the graph. * @param name The name of the edge. */ hasEdge(name: string): boolean; /** * Adds a node to the graph. * @param node The node to be added. */ addNode(node: Node): void; /** * Adds an edge to the graph. * @param edge The edge to be added. */ addEdge(edge: Edge): void; /** * Removes a node from the graph, returns whether the removal * was successful. * @param node The node to be removed. */ removeNode(node: Node): boolean; /** * Removes an edge from the graph, returns whether the removal * was successful. * @param edge The edge to be removed. */ removeEdge(edge: Edge): boolean; /** * Returns the roots of the graph. */ roots(): Node[]; /** * Returns the leaves of the graph. */ leaves(): Node[]; }