Class Graph<K>

A graph data structure.

Type Parameters

  • K

    The type of the vertices in the graph.

Hierarchy

Constructors

Properties

map: Map<K, K[]> = ...

Accessors

  • get size(): number
  • Returns the number of vertices in the graph.

    Returns number

    The number of vertices in the graph.

  • get vertices(): readonly K[]
  • Returns an array of vertices in the graph.

    Returns readonly K[]

    An array of vertices.

Methods

  • Returns an array of vertices adjacent to the given vertex.

    Parameters

    • vertex: K

      The vertex to get the adjacent vertices for.

    Returns readonly K[]

    An array of adjacent vertices.

  • Returns the shortest path between two vertices in the graph.

    Parameters

    • v1: K

      The starting vertex.

    • v2: K

      The ending vertex.

    Returns readonly K[]

    An array of vertices representing the shortest path.

    Throws

    An error if the path could not be found.

  • Returns true if the graph contains the given vertex, false otherwise.

    Parameters

    • vertex: K

      The vertex to check for.

    Returns boolean

    True if the graph contains the vertex, false otherwise.

  • Returns a boolean indicating if two vertices are adjacent in the graph.

    Parameters

    • v1: K

      The first vertex.

    • v2: K

      The second vertex.

    Returns boolean

    True if the vertices are adjacent, false otherwise.