7832ec4f0788aee92449e6858797ff24c9b3c24e
Graph with Reflection
This project implements an undirected graph using an adjacency list and provides reflection capabilities that record all operations performed on the graph.
Features
- Adjacency List: Efficient storage and traversal of graph nodes and edges.
- Reflection: Every mutating operation (
addNode,addEdge,removeNode,removeEdge) is logged. - API:
addNode(node)addEdge(u, v)removeNode(node)removeEdge(u, v)getNeighbors(node)hasEdge(u, v)getNodes()getLog()– returns a copy of the operation log.
Installation
npm install
Running Tests
npm test
Usage
const { createGraph } = require('./src/index');
const graph = createGraph();
graph.addNode('a');
graph.addNode('b');
graph.addEdge('a', 'b');
console.log(graph.getNeighbors('a')); // ['b']
console.log(graph.getLog());
// [
// { method: 'addNode', args: ['a'] },
// { method: 'addNode', args: ['b'] },
// { method: 'addEdge', args: ['a', 'b'] }
// ]
The getLog() method returns a snapshot of all recorded operations, allowing you to inspect the history of changes made to the graph.
Description
Languages
Python
57.4%
JavaScript
40.7%
HTML
1.9%