46 lines
859 B
Markdown
46 lines
859 B
Markdown
# Graph with Reflection and Rewriting Nodes
|
||
|
||
This project implements a simple directed graph data structure in JavaScript that supports three types of nodes:
|
||
|
||
- **Generic Node** – the base node type.
|
||
- **Reflection Node** – represents a node that reflects on itself.
|
||
- **Rewriting Node** – represents a node that rewrites or transforms data.
|
||
|
||
## Installation
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
## Running Tests
|
||
|
||
```bash
|
||
npm test
|
||
```
|
||
|
||
## Usage
|
||
|
||
```js
|
||
import { Graph, Node, ReflectionNode, RewritingNode } from './src/index.js';
|
||
|
||
const graph = new Graph();
|
||
|
||
const n1 = new Node('n1');
|
||
const r1 = new ReflectionNode('r1');
|
||
const w1 = new RewritingNode('w1');
|
||
|
||
graph.addNode(n1);
|
||
graph.addNode(r1);
|
||
graph.addNode(w1);
|
||
|
||
graph.addEdge('n1', 'r1');
|
||
graph.addEdge('r1', 'w1');
|
||
|
||
graph.traverse('n1', (node) => {
|
||
console.log(node.id, node.type);
|
||
});
|
||
```
|
||
|
||
## License
|
||
|
||
MIT |