Options
All
  • Public
  • Public/Protected
  • All
Menu

Models a graph in-memory. Class holds vertices and edges contained in the graph. Provides methods to convert to other common graph represnetations.

Hierarchy

  • Graph

Index

Constructors

constructor

Properties

edges

edges: Edge[]

Edges in graph.

vertices

vertices: Vertex[]

Vertices in graph.

Methods

addEdge

  • addEdge(edge: Edge): void
  • Adds edge to the graph. Updates incoming/outgoing edges for source/target vertices.

    Parameters

    • edge: Edge

      Edge to be added.

    Returns void

addVertex

  • addVertex(vertex: Vertex): void

clearGraph

  • clearGraph(): void
  • Clears out the graph removing all vertices and edges.

    Returns void

getNextVertexId

  • getNextVertexId(): number
  • Used to determine ID that could be used for creating a new vertex for this graph. ID is "generated" by finding the biggest existing ID and adding +1.

    Returns number

    ID that can be used to create a vertex without collision with existing vertex.

hasEdge

  • hasEdge(edge: Edge): boolean
  • Checks if edge with specified source/target already exists in the graph.

    Parameters

    • edge: Edge

      Edge to check for.

    Returns boolean

removeEdge

  • removeEdge(edgeToRemove: Edge): void
  • Removes an edge from the graph.

    Parameters

    • edgeToRemove: Edge

      Edge to be removed.

    Returns void

removeVertex

  • removeVertex(vertexToRemove: Vertex): void
  • Removes vertex from the graph.

    Parameters

    • vertexToRemove: Vertex

      Vertex to be removed.

    Returns void

removeVertexByIndex

  • removeVertexByIndex(index: number): void
  • Removes vertex from the graph based on index.

    Parameters

    • index: number

      Index at which vertex to be removed is found.

    Returns void

toAdjacencyList

  • toAdjacencyList(): any[]
  • Coverts graph to adjacency list where graph is represented as a list of edges where each list element is an object of form {source, target, weight} where source is source vertex ID, target is target vertex ID and weight is the weight of represented edge. If weight is not specified for the edge it will be null.

    Returns any[]

    Adjacency list representation of the graph in format {source, target, weight}.

toAdjacencyMatrix

  • toAdjacencyMatrix(defaultWeight?: number): number[][]
  • Converts graph to adjacency matrix where graph is represneted as V x V array where array elements are weights of edges (0 indicates no edge). Array is indexed using IDs of vertices. If edge does not a weight defaultWeight will be used.

    Parameters

    • Default value defaultWeight: number = 1

      Weight to be used when edge has no weight specified.

    Returns number[][]

    Adjacency matrix represntation of the graph.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc