Skip to content

graph overview


Table of contents


utils

Graph (class)

Signature

export declare class Graph<T> {
  constructor(data: T)
}

fromArray (static method)

Creates a new Graph instance from an array of elements, where each element in the array is a node in the graph. The first element of the array is used as the root node of the graph.

Signature

static fromArray<T>(array: T[], closed: boolean = false): Graph<T>

fromSquareGrid (static method)

Creates a new Graph instance from a two-dimensional square grid of elements, where each element in the grid is a node in the graph. The top-left element of the grid is used as the root node of the graph. The nodes in the graph are created in the same order as the elements in the grid, from left to right and then from top to bottom.

Signature

static fromSquareGrid<T>(grid: T[][]): Graph<T>

addAdjacent (method)

Signature

addAdjacent(node: Graph<T>): boolean

removeAdjacent (method)

Signature

removeAdjacent(node: Graph<T>): boolean

addEdge (method)

Create an edge between two nodes

Signature

addEdge(source: Graph<T>, destination: Graph<T>): boolean

removeEdge (method)

Remove an edge between two nodes

Signature

removeEdge(source: Graph<T>, destination: Graph<T>): boolean

walkRead (method)

Signature

walkRead(depth: number): Set<Graph<T>>

walkReadPreserveDepth (method)

Signature

walkReadPreserveDepth(depth: number): Set<Graph<T>>[]

nodes (method)

Signature

nodes(): Graph<T>[]

data (property)

Signature

data: T