Class DirectedGraph<V, E, VO, EO>

Type Parameters

Hierarchy

Implements

  • IGraph<V, E, VO, EO>

Constructors

Methods

  • Time Complexity: O(n) Space Complexity: O(1)

    The function is an implementation of the Symbol.iterator method that returns an iterable iterator.

    Parameters

    • Rest ...args: any[]

      The args parameter in the code snippet represents a rest parameter. It allows the function to accept any number of arguments as an array. In this case, the args parameter is used to pass any additional arguments to the _getIterator method.

    Returns IterableIterator<[VertexKey, undefined | V]>

  • Time Complexity: O(1) Space Complexity: O(1)

    The function _addEdge adds an edge to a graph if the source and destination vertexMap exist.

    Parameters

    • edge: EO

      The parameter edge is of type EO, which represents an edge in a graph. It is the edge that needs to be added to the graph.

    Returns boolean

    a boolean value. It returns true if the edge was successfully added to the graph, and false if either the source or destination vertex does not exist in the graph.

  • Time Complexity: O(1) - Depends on the implementation in the concrete class. Space Complexity: O(1) - Depends on the implementation in the concrete class.

    Parameters

    • edge: EO

    Returns boolean

  • Time Complexity: O(1) - Depends on the implementation in the concrete class. Space Complexity: O(1) - Depends on the implementation in the concrete class.

    Parameters

    • src: VertexKey | VO
    • dest: VertexKey | VO
    • Optional weight: number
    • Optional value: E

    Returns boolean

  • Time Complexity: O(1) - Constant time for Map operations. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    Parameters

    • vertex: VO

    Returns boolean

  • Time Complexity: O(1) - Constant time for Map operations. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    Parameters

    • key: VertexKey
    • Optional value: V

    Returns boolean

  • Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm). Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).

    one to rest pairs The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios. The bellmanFord function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.

    Parameters

    • src: VertexKey | VO

      The src parameter is the source vertex from which the Bellman-Ford algorithm will start calculating the shortest paths. It can be either a vertex object or a vertex ID.

    • Optional scanNegativeCycle: boolean

      A boolean flag indicating whether to scan for negative cycles in the graph.

    • Optional getMin: boolean

      The getMin parameter is a boolean flag that determines whether the algorithm should calculate the minimum distance from the source vertex to all other vertexMap in the graph. If getMin is set to true, the algorithm will find the minimum distance and update the min variable with the minimum

    • Optional genPath: boolean

      A boolean flag indicating whether to generate paths for all vertexMap from the source vertex.

    Returns {
        distMap: Map<VO, number>;
        hasNegativeCycle: undefined | boolean;
        min: number;
        minPath: VO[];
        paths: VO[][];
        preMap: Map<VO, VO>;
    }

    The function bellmanFord returns an object with the following properties:

    • distMap: Map<VO, number>
    • hasNegativeCycle: undefined | boolean
    • min: number
    • minPath: VO[]
    • paths: VO[][]
    • preMap: Map<VO, VO>
  • Time Complexity: O(1) Space Complexity: O(1)

    The clear function resets the vertex map, in-edge map, and out-edge map.

    Returns void

  • The clone function creates a new DirectedGraph object with the same vertices and edges as the original.

    Returns DirectedGraph<V, E, VO, EO>

    A new instance of the directedgraph class

  • The function creates a directed edge between two vertexMap with an optional weight and value.

    Parameters

    • src: VertexKey

      The source vertex ID of the edge. It represents the starting point of the edge.

    • dest: VertexKey

      The dest parameter is the identifier of the destination vertex for the edge.

    • Optional weight: number

      The weight parameter is an optional number that represents the weight of the edge. If no weight is provided, it defaults to 1.

    • Optional value: E

      The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and is used to store additional information or data associated with the edge.

    Returns EO

    a new instance of a DirectedEdge object, casted as type EO.

  • The function creates a new vertex with an optional value and returns it.

    Parameters

    • key: VertexKey

      The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could be a number or a string depending on how you want to identify your vertexMap.

    • Optional value: V

      The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided, it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be assigned the same value as the 'key' parameter

    Returns VO

    a new instance of a DirectedVertex object, casted as type VO.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a VertexKey or a VO.

    Returns number

    The sum of the out-degree and in-degree of the specified vertex or vertex ID.

  • Time Complexity: O(E) where E is the number of edgeMap Space Complexity: O(1)

    The deleteEdge function removes an edge from a graph and returns the removed edge.

    Parameters

    • edgeOrSrcVertexKey: VertexKey | EO

      The edge parameter can be either an EO object (edge object) or a VertexKey (key of a vertex).

    • Optional destVertexKey: VertexKey

      The destVertexKey parameter is an optional parameter that represents the key of the destination vertex of the edge. It is used to specify the destination vertex when the edge parameter is a vertex key. If destVertexKey is not provided, the function assumes that the edge

    Returns undefined | EO

    the removed edge (EO) or undefined if no edge was removed.

  • Time Complexity: O(|E|) where |E| is the number of edgeMap Space Complexity: O(1)

    The function removes an edge between two vertexMap in a graph and returns the removed edge.

    Parameters

    • srcOrKey: VertexKey | VO

      The source vertex or its ID.

    • destOrKey: VertexKey | VO

      The destOrKey parameter represents the destination vertex or its ID.

    Returns undefined | EO

    the removed edge (EO) if it exists, or undefined if either the source or destination vertex does not exist.

  • Time Complexity: O(|E|) where |E| is the number of edgeMap Space Complexity: O(1)

    The function removes edgeMap between two vertexMap and returns the removed edgeMap.

    Parameters

    • v1: VertexKey | VO

      The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique identifier of a vertex in a graph, while VO represents the actual vertex object.

    • v2: VertexKey | VO

      The parameter v2 represents either a VertexKey or a VO object. It is used to specify the second vertex in the edge that needs to be removed.

    Returns EO[]

    an array of removed edgeMap (EO[]).

  • Time Complexity: O(1) - Constant time for Map operations. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    The deleteVertex function removes a vertex from a graph by its ID or by the vertex object itself.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a vertex object (VO) or a vertex ID (VertexKey).

    Returns boolean

    The method is returning a boolean value.

  • Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap). Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).

    Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative. The dijkstra function implements Dijkstra's algorithm to find the shortest path between a source vertex and an optional destination vertex, and optionally returns the minimum distance, the paths, and other information.

    Parameters

    • src: VertexKey | VO

      The src parameter represents the source vertex from which the Dijkstra algorithm will start. It can be either a vertex object or a vertex ID.

    • Optional dest: VertexKey | VO = undefined

      The dest parameter is the destination vertex or vertex ID. It specifies the vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm will calculate the shortest paths to all other vertexMap from the source vertex.

    • Optional getMinDist: boolean = false

      The getMinDist parameter is a boolean flag that determines whether the minimum distance from the source vertex to the destination vertex should be calculated and returned in the result. If getMinDist is set to true, the minDist property in the result will contain the minimum distance

    • Optional genPaths: boolean = false

      The genPaths parameter is a boolean flag that determines whether or not to generate paths in the Dijkstra algorithm. If genPaths is set to true, the algorithm will calculate and return the shortest paths from the source vertex to all other vertexMap in the graph. If genPaths @returns The function dijkstrareturns an object of typeDijkstraResult`.

    Returns DijkstraResult<VO>

  • Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization). Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).

    The function dijkstraWithoutHeap implements Dijkstra's algorithm to find the shortest path between two vertexMap in a graph without using a heap data structure.

    Parameters

    • src: VertexKey | VO

      The source vertex from which to start the Dijkstra's algorithm. It can be either a vertex object or a vertex ID.

    • Optional dest: VertexKey | VO = undefined

      The dest parameter in the dijkstraWithoutHeap function is an optional parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its identifier. If no destination is provided, the value is set to undefined.

    • Optional getMinDist: boolean = false

      The getMinDist parameter is a boolean flag that determines whether the minimum distance from the source vertex to the destination vertex should be calculated and returned in the result. If getMinDist is set to true, the minDist property in the result will contain the minimum distance

    • Optional genPaths: boolean = false

      The genPaths parameter is a boolean flag that determines whether or not to generate paths in the Dijkstra algorithm. If genPaths is set to true, the algorithm will calculate and return the shortest paths from the source vertex to all other vertexMap in the graph. If genPaths @returns The function dijkstraWithoutHeapreturns an object of typeDijkstraResult`.

    Returns DijkstraResult<VO>

  • Time Complexity: O(|E|) where |E| is the number of edgeMap Space Complexity: O(|E|)

    The edgeSet function returns an array of all the edgeMap in the graph.

    Returns EO[]

    The edgeSet() method returns an array of edgeMap (EO[]).

  • Time Complexity: O(1) Space Complexity: O(1)

    The function "edgesOf" returns an array of both outgoing and incoming edgeMap of a given vertex or vertex ID.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a VertexKey or a VO.

    Returns EO[]

    The function edgesOf returns an array of edgeMap.

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields key-value pairs from the object, where the value can be undefined.

    Returns IterableIterator<[VertexKey, undefined | V]>

  • Time Complexity: O(n) Space Complexity: O(1)

    The every function checks if every element in a collection satisfies a given condition.

    Parameters

    • predicate: EntryCallback<VertexKey, undefined | V, boolean>

      The predicate parameter is a callback function that takes three arguments: value, key, and index. It should return a boolean value indicating whether the condition is met for the current element in the iteration.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the predicate function. If thisArg is provided, it will be passed as the first argument to the predicate function. If thisArg is not provided

    Returns boolean

    The every method is returning a boolean value. It returns true if every element in the collection satisfies the provided predicate function, and false otherwise.

  • Time Complexity: O(n) Space Complexity: O(n)

    The filter function iterates over key-value pairs in a data structure and returns an array of pairs that satisfy a given predicate.

    Parameters

    • predicate: EntryCallback<VertexKey, undefined | V, boolean>

      The predicate parameter is a callback function that takes four arguments: value, key, index, and this. It is used to determine whether an element should be included in the filtered array. The callback function should return true if the element should be included, and @param {any} [thisArg] - ThethisArgparameter is an optional argument that allows you to specify the value ofthiswithin thepredicatefunction. It is used when you want to bind a specific object as the context for thepredicatefunction. IfthisArgis provided, it will be @returns Thefiltermethod returns an array of key-value pairs[VertexKey, V | undefined][]` that satisfy the given predicate function.

    • Optional thisArg: any

    Returns [VertexKey, undefined | V][]

  • Time Complexity: O(n) Space Complexity: O(1)

    The find function iterates over the entries of a collection and returns the first value for which the callback function returns true.

    Parameters

    • callbackfn: EntryCallback<VertexKey, undefined | V, [VertexKey, undefined | V]>

      The callback function that will be called for each entry in the collection. It takes three arguments: the value of the entry, the key of the entry, and the index of the entry in the collection. It should return a boolean value indicating whether the current entry matches the desired condition.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as this when executing the callbackfn function. If thisArg is provided, it will be passed as the this value to the callbackfn function. If thisArg @returns The method findreturns the value of the first element in the iterable that satisfies the provided callback function. If no element satisfies the callback function,undefined` is returned.

    Returns undefined | [VertexKey, undefined | V]

  • Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm). Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).

    Not support graph with negative weight cycle all pairs The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes. The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a graph.

    Returns {
        costs: number[][];
        predecessor: (undefined | VO)[][];
    }

    The function floydWarshall() returns an object with two properties: costs and predecessor. The costs property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The predecessor property is a 2D array of vertexMap (or undefined) representing the predecessor vertexMap in the shortest path between vertexMap in the

    • costs: number[][]
    • predecessor: (undefined | VO)[][]
  • Time Complexity: O(n) Space Complexity: O(1)

    The forEach function iterates over each key-value pair in a collection and executes a callback function for each pair.

    Parameters

    • callbackfn: EntryCallback<VertexKey, undefined | V, void>

      The callback function that will be called for each element in the collection. It takes four parameters: the value of the current element, the key of the current element, the index of the current element, and the collection itself.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the callback function. If thisArg is provided, it will be used as the this value when calling the callback function. If thisArg is not provided, `

    Returns void

  • Time Complexity: O(n) Space Complexity: O(1)

    The get function retrieves the value associated with a given key from a collection.

    Parameters

    • key: VertexKey

      K (the type of the key) - This parameter represents the key that is being searched for in the collection.

    Returns undefined | V

    The get method returns the value associated with the specified key if it exists in the collection, otherwise it returns undefined.

  • Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths). Space Complexity: O(P) - Linear space, where P is the number of paths found.

    The function getAllPathsBetween finds all paths between two vertexMap in a graph using depth-first search.

    Parameters

    • v1: VertexKey | VO

      The parameter v1 represents either a vertex object (VO) or a vertex ID (VertexKey). It is the starting vertex for finding paths.

    • v2: VertexKey | VO

      The parameter v2 represents either a vertex object (VO) or a vertex ID (VertexKey).

    • limit: number = 1000

      The count of limitation of result array.

    Returns VO[][]

    The function getAllPathsBetween returns an array of arrays of vertexMap (VO[][]).

  • Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm). Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).

    The function returns a map that associates each vertex object with its corresponding depth-first number.

    Returns Map<VO, number>

    A Map object with keys of type VO and values of type number.

  • Time Complexity: O(|E|) where |E| is the number of edgeMap Space Complexity: O(1)

    The function getDestinations returns an array of destination vertexMap connected to a given vertex.

    Parameters

    • vertex: undefined | VertexKey | VO

      The vertex parameter represents the starting vertex from which we want to find the destinations. It can be either a VO object, a VertexKey value, or undefined.

    Returns VO[]

    an array of vertexMap (VO[]).

  • Time Complexity: O(|V|) where |V| is the number of vertexMap Space Complexity: O(1)

    The getEdge function retrieves an edge between two vertexMap based on their source and destination IDs.

    Parameters

    • srcOrKey: undefined | VertexKey | VO

      The source vertex or its ID. It can be either a vertex object or a vertex ID.

    • destOrKey: undefined | VertexKey | VO

      The destOrKey parameter in the getEdge function represents the destination vertex of the edge. It can be either a vertex object (VO), a vertex ID (VertexKey), or undefined if the destination is not specified.

    Returns undefined | EO

    the first edge found between the source and destination vertexMap, or undefined if no such edge is found.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function "getEdgeDest" returns the destination vertex of an edge.

    Parameters

    • e: EO

      The parameter "e" is of type "EO", which represents an edge in a graph.

    Returns undefined | VO

    either a vertex object of type VO or undefined.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function "getEdgeSrc" returns the source vertex of an edge, or undefined if the edge does not exist.

    Parameters

    • e: EO

      The parameter "e" is of type EO, which represents an edge in a graph.

    Returns undefined | VO

    either a vertex object (VO) or undefined.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function "getEndsOfEdge" returns the source and destination vertexMap of an edge if it exists in the graph, otherwise it returns undefined.

    Parameters

    • edge: EO

      The parameter edge is of type EO, which represents an edge in a graph.

    Returns undefined | [VO, VO]

    The function getEndsOfEdge returns an array containing two vertexMap [VO, VO] if the edge exists in the graph. If the edge does not exist, it returns undefined.

  • The function returns a Map object that contains the low values of each vertex in a Tarjan algorithm.

    Returns Map<VO, number>

    The method getLowMap() is returning a Map object with keys of type VO and values of type number.

  • Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm). Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).

    The function getMinCostBetween calculates the minimum cost between two vertexMap in a graph, either based on edge weights or using a breadth-first search algorithm.

    Parameters

    • v1: VertexKey | VO

      The parameter v1 represents the starting vertex or its ID.

    • v2: VertexKey | VO

      The parameter v2 represents the destination vertex or its ID. It is the vertex to which you want to find the minimum cost or weight from the source vertex v1.

    • Optional isWeight: boolean

      isWeight is an optional parameter that indicates whether the graph edgeMap have weights. If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of the edgeMap. If isWeight is set to false or not provided, the function will calculate the

    Returns undefined | number

    The function getMinCostBetween returns a number representing the minimum cost between two vertexMap (v1 and v2). If the isWeight parameter is true, it calculates the minimum weight among all paths between the vertexMap. If isWeight is false or not provided, it uses a breadth-first search (BFS) algorithm to calculate the minimum number of

  • Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS). Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).

    The function getMinPathBetween returns the minimum path between two vertexMap in a graph, either based on weight or using a breadth-first search algorithm.

    Parameters

    • v1: VertexKey | VO

      The parameter v1 represents the starting vertex of the path. It can be either a vertex object (VO) or a vertex ID (VertexKey).

    • v2: VertexKey | VO

      VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum path.

    • Optional isWeight: boolean

      A boolean flag indicating whether to consider the weight of edgeMap in finding the minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set to false, the function will use breadth-first search (BFS) to find the minimum path.

    • isDFS: boolean = false

      If set to true, it enforces the use of getAllPathsBetween to first obtain all possible paths, followed by iterative computation of the shortest path. This approach may result in exponential time complexity, so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.

    Returns undefined | VO[]

    The function getMinPathBetween returns an array of vertexMap (VO[]) representing the minimum path between two vertexMap (v1 and v2). If there is no path between the vertexMap, it returns undefined.

  • Time Complexity: O(|E|) where |E| is the number of edgeMap Space Complexity: O(1)

    The function getNeighbors returns an array of neighboring vertexMap of a given vertex or vertex ID in a graph.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a vertex object (VO) or a vertex ID (VertexKey).

    Returns VO[]

    an array of vertexMap (VO[]).

  • Time Complexity: O(L), where L is the length of the path. Space Complexity: O(1) - Constant space.

    The function calculates the sum of weights along a given path.

    Parameters

    • path: VO[]

      An array of vertexMap (VO) representing a path in a graph.

    Returns number

    The function getPathSumWeight returns the sum of the weights of the edgeMap in the given path.

  • The function "getSCCs" returns a map of strongly connected components (SCCs) using the Tarjan algorithm.

    Returns Map<number, VO[]>

    a map where the keys are numbers and the values are arrays of VO objects.

  • Time Complexity: O(1) - Constant time for Map lookup. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.

    Parameters

    • vertexKey: VertexKey

      The vertexKey parameter is the identifier of the vertex that you want to retrieve from the _vertexMap map.

    Returns undefined | VO

    The method getVertex returns the vertex with the specified vertexKey if it exists in the _vertexMap map. If the vertex does not exist, it returns undefined.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function checks if a given key exists in a collection.

    Parameters

    • key: VertexKey

      The parameter "key" is of type K, which means it can be any type. It represents the key that we want to check for existence in the data structure.

    Returns boolean

    a boolean value. It returns true if the key is found in the collection, and false otherwise.

  • Time Complexity: O(1) - Depends on the implementation in the concrete class. Space Complexity: O(1) - Depends on the implementation in the concrete class.

    The function checks if there is an edge between two vertexMap and returns a boolean value indicating the result.

    Parameters

    • v1: VertexKey | VO

      The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique identifier of a vertex in a graph, while VO represents the type of the vertex object itself.

    • v2: VertexKey | VO

      The parameter v2 represents the second vertex in the edge. It can be either a VertexKey or a VO type, which represents the type of the vertex.

    Returns boolean

    A boolean value is being returned.

  • Time Complexity: O(n) Space Complexity: O(1)

    The function checks if a given value exists in a collection.

    Parameters

    • value: undefined | V

      The parameter "value" is the value that we want to check if it exists in the collection.

    Returns boolean

    a boolean value, either true or false.

  • Time Complexity: O(1) - Constant time for Map lookup. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    The function checks if a vertex exists in a graph.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a vertex object (VO) or a vertex ID (VertexKey).

    Returns boolean

    a boolean value.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function "inDegreeOf" returns the number of incoming edgeMap for a given vertex.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a VertexKey or a VO.

    Returns number

    The number of incoming edgeMap of the specified vertex or vertex ID.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function incomingEdgesOf returns an array of incoming edgeMap for a given vertex or vertex ID.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a vertex object (VO) or a vertex ID (VertexKey).

    Returns EO[]

    The method incomingEdgesOf returns an array of edgeMap (EO[]).

  • The isEmpty function checks if the graph is empty.

    Returns boolean

    A boolean value

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields the keys of a data structure.

    Returns IterableIterator<VertexKey>

  • Time Complexity: O(n) Space Complexity: O(n)

    The map function iterates over the elements of a collection and applies a callback function to each element, returning an array of the results.

    Type Parameters

    • T

    Parameters

    • callback: EntryCallback<VertexKey, undefined | V, T>

      The callback parameter is a function that will be called for each element in the map. It takes four arguments:

    • Optional thisArg: any

      The thisArg parameter is an optional argument that allows you to specify the value of this within the callback function. If thisArg is provided, it will be used as the this value when calling the callback function. If thisArg is not provided, @returns Themapfunction is returning an array of typeT[]`.

    Returns T[]

  • Time Complexity: O(1) Space Complexity: O(1)

    The function outDegreeOf returns the number of outgoing edgeMap from a given vertex.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can be either a VertexKey or a VO.

    Returns number

    The number of outgoing edgeMap from the specified vertex or vertex ID.

  • Time Complexity: O(1) Space Complexity: O(1)

    The function outgoingEdgesOf returns an array of outgoing edgeMap from a given vertex or vertex ID.

    Parameters

    • vertexOrKey: VertexKey | VO

      The parameter vertexOrKey can accept either a vertex object (VO) or a vertex ID (VertexKey).

    Returns EO[]

    The method outgoingEdgesOf returns an array of edgeMap (EO[]).

  • Time Complexity: O(n) Space Complexity: O(1)

    The reduce function iterates over key-value pairs and applies a callback function to each pair, accumulating a single value.

    Type Parameters

    • U

    Parameters

    • callbackfn: ReduceEntryCallback<VertexKey, undefined | V, U>

      The callback function that will be called for each element in the collection. It takes four arguments: the current accumulator value, the current value of the element, the key of the element, and the index of the element in the collection. It should return the updated accumulator value.

    • initialValue: U

      The initialValue parameter is the initial value of the accumulator. It is the value that will be used as the first argument to the callbackfn function when reducing the elements of the collection.

    Returns U

    The reduce method is returning the final value of the accumulator after iterating over all the elements in the collection.

  • Time Complexity: O(K), where K is the number of vertexMap to be removed. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    The function removes all vertexMap from a graph and returns a boolean indicating if any vertexMap were removed.

    Parameters

    • vertexMap: VertexKey[] | VO[]

      The vertexMap parameter can be either an array of vertexMap (VO[]) or an array of vertex IDs (VertexKey[]).

    Returns boolean

    a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertexMap were removed.

  • Time Complexity: O(1) - Constant time for Map and Edge operations. Space Complexity: O(1) - Constant space, as it creates only a few variables.

    The function sets the weight of an edge between two vertexMap in a graph.

    Parameters

    • srcOrKey: VertexKey | VO

      The srcOrKey parameter can be either a VertexKey or a VO object. It represents the source vertex of the edge.

    • destOrKey: VertexKey | VO

      The destOrKey parameter represents the destination vertex of the edge. It can be either a VertexKey or a vertex object VO.

    • weight: number

      The weight parameter represents the weight of the edge between the source vertex (srcOrKey) and the destination vertex (destOrKey).

    Returns boolean

    a boolean value. If the edge exists between the source and destination vertexMap, the function will update the weight of the edge and return true. If the edge does not exist, the function will return false.

  • Time Complexity: O(n) Space Complexity: O(1)

    The "some" function iterates over a collection and returns true if at least one element satisfies a given predicate.

    Parameters

    • predicate: EntryCallback<VertexKey, undefined | V, boolean>

      The predicate parameter is a callback function that takes three arguments: value, key, and index. It should return a boolean value indicating whether the condition is met for the current element in the iteration.

    • Optional thisArg: any

      The thisArg parameter is an optional argument that specifies the value to be used as the this value when executing the predicate function. If thisArg is provided, it will be passed as the first argument to the predicate function. If thisArg is

    Returns boolean

    a boolean value. It returns true if the predicate function returns true for any pair in the collection, and false otherwise.

  • Time Complexity: O(V + E) Space Complexity: O(V) Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs. Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.

    The function tarjan implements the Tarjan's algorithm to find strongly connected components in a graph.

    Returns {
        SCCs: Map<number, VO[]>;
        dfnMap: Map<VO, number>;
        lowMap: Map<VO, number>;
    }

    The function tarjan() returns an object with three properties: dfnMap, lowMap, and SCCs.

    • SCCs: Map<number, VO[]>
    • dfnMap: Map<VO, number>
    • lowMap: Map<VO, number>
  • Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap Space Complexity: O(|V|)

    The topologicalSort function performs a topological sort on a graph and returns an array of vertexMap or vertex IDs in the sorted order, or undefined if the graph contains a cycle.

    Parameters

    • Optional propertyName: "key" | "vertex"

      The propertyName parameter is an optional parameter that specifies the property to use for sorting the vertexMap. It can have two possible values: 'vertex' or 'key'. If 'vertex' is specified, the vertexMap themselves will be used for sorting. If 'key' is specified, the ids of

    Returns undefined | (VertexKey | VO)[]

    an array of vertexMap or vertex IDs in topological order. If there is a cycle in the graph, it returns undefined.

  • Time Complexity: O(n) Space Complexity: O(n)

    The function returns an iterator that yields the values of a collection.

    Returns IterableIterator<undefined | V>

Generated using TypeDoc