MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / Graph

Class Graph

code/chapter/22_fast.js:1–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1var Graph = class Graph {
2 #nodes = [];
3
4 get size() {
5 return this.#nodes.length;
6 }
7
8 addNode() {
9 let id = this.#nodes.length;
10 this.#nodes.push(new Set());
11 return id;
12 }
13
14 addEdge(nodeA, nodeB) {
15 this.#nodes[nodeA].add(nodeB);
16 this.#nodes[nodeB].add(nodeA);
17 }
18
19 neighbors(node) {
20 return this.#nodes[node];
21 }
22}
23
24function randomLayout(graph) {
25 let layout = [];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected