Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Graph

A graph is a collection of vertices and edges (maps to other vertices). It exposes 2 functions: add_vertex and get_vertex that do as their names suggest, add and retrieve vertices to and from the graph respectively.

graph = new Graph();
graph.add_vertex(myvertex1, myvertex2, myvertex3);  // Adds the 3 vertices to the graph
console.log(graph.get_vertex({id: 1, type: "testvertex"});)  // Vertex with id 1 and type "testvertex"

Hierarchy

  • Graph

Index

Properties

Private vertexIndex

vertexIndex: object

Holds all the vertices in the graph indexed by a json string of the form:

{id: 123, type: "MyVertexType"}

Type declaration

Accessors

Private vertices

  • Returns a flat Array of vertices in this graph.

    Returns Vertex[]

Methods

add_vertex

  • add_vertex(...args: Vertex[]): void
  • Adds the given verted to the graph. If a vertex with this combination of id and type already exists then it throws an error instead.

    Parameters

    Returns void

Private check_argument_duplicates

  • check_argument_duplicates(vertices: Vertex[]): void
  • A helper function for argument sanitisation. This funciton makes sure that none of its arguments have the same id and type. If one is found it will throw an error.

    Parameters

    Returns void

Private check_exist_in_graph

  • check_exist_in_graph(vertices: Vertex[]): void
  • A helper function for argument sanitisation. This funciton makes sure that all of its arguments exist in the graph. If not then it will throw an error

    Parameters

    Returns void

Private check_is_vertex

  • check_is_vertex(vertices: Vertex[]): void
  • A helper function for argument sanitisation. This funciton makes sure that all of its arguments are instances of Vertex. If one is found that is not a vertex then it will throw an error.

    Parameters

    Returns void

Private check_no_graph_duplicates

  • check_no_graph_duplicates(vertices: Vertex[]): void
  • A helper function for argument sanitisation. This funciton makes sure that none of its arguments have the same id and type as a vertex in the graph. If one is found it will throw an error.

    Parameters

    Returns void

del_vertex

  • del_vertex(...args: Vertex[]): void
  • Removes the given vertices from the graph

    Parameters

    Returns void

get_vertex

  • get_vertex(__namedParameters: object): Vertex | undefined
  • Returns the vertex with the given id and type. If no type is given then null is assumed.

    Parameters

    • __namedParameters: object
      • id: string | number
      • type: undefined | string

    Returns Vertex | undefined

Private relationship

  • relationship(edge: Edge, currentVertex: Vertex): object
  • Returns an object with a getter funciton for returning all the vertices that the given vertex is connected to by the given Edge rule. If no matches are found and multiple is flase then null is returned else an empty array and returned

    Parameters

    Returns object

Private set_edges

  • set_edges(vertex: Vertex): void
  • Helper function for [[addVerted]] used to add the edges on a vertex when it is inserted into the graph.

    Parameters

    Returns void

Generated using TypeDoc