A simple undirected graph object with nodes and implicit edges

new Graph(graph: [Object])
Parameters
graph ([Object]) The graph to initialize
Name Description
graph.nodes Array<GraphNode> The nodes of the graph - must have id , and can optionally have weight , nType , and neighbors
graph.edges Array<Array> The edges of the graph - two element array of IDs of the nodes on each end of the edge
Properties
nodes (Object) : The nodes in the graph
nodeCount (number) : The number of nodes
edgeCount (number) : The number of edges
Example

Example valid graph parameter

{ nodes: [
    { id: 1, props: { weight: 0, nType: 1 } },
    { id: 2, props: { weight: 0, nType: 1 } },
    { id: 3, props: { weight: 1, nType: 2 } },
    { id: 4, props: { weight: 2, nType: 2 } }
],
edges: [
    [1, 3],
    [3, 4],
    [4, 2]
] }
Instance Members
find(id)
exists(id)
addNode(id, props)
deleteNode(id)
eachNode(fn)
eachNeighbor(id, fn)
addEdge(source, target)
addOrCreateEdge(source, target)
deleteEdge(source, target)
connected(source, target)
update(id, props)

A node in a graph

new GraphNode(id: number, props: [Object])
Parameters
id (number) The ID of the node to create
props ([Object]) The properties to initialize the node with
Name Description
props.weight number The initial weight of the node
props.nType number The initial nType of the node
props.neighbors Array<number> The initial neighbors of the node
Properties
id (number) : The ID of the node
weight (number) : The weight of the node ( default 0 ) (e.g., distance in path algorithm)
nType (number) : An integer that represents the type of node ( default 0 ) (e.g., an enumeration)
neighbors (Array<number>) : A list of node IDs that are neighbors of the node ( default [] )

A runner for Dijkstra's shortest path algorithm

Dijkstra()
Static Members
run(graph, pathType, source, target)
getPath(prevList, target)

A binary min heap implemented with an array

new MinHeap(scoreFunction: function, idFunction: function, valueProp: string)
Parameters
scoreFunction (function) Must return the property used for ordering
idFunction (function) Must return the property used as the key
valueProp (string) The name of the property to be modified in decreaseKey()
Properties
content (Array) : The elements in the array-implemented heap
scoreFunction (function) : A function that returns the property used for ordering the elements
idFunction (function) : A function that returns the property used as the key of the elements
map (Object) : A map between the element IDs and their index in content
Instance Members
size()
exists(elt)
push(elt)
pop()
bubbleUp(n)
sinkDown(n)
decreaseKey(id, value)