Files
povtornyy-ekzamen-graf-s-re…/README.md
T

60 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Graph with Reflection and Rewriting
This project implements a simple graph data structure in JavaScript that supports **reflection** and **rewriting** operations through dedicated node types.
## Features
- **Graph**: Stores nodes and directed edges.
- **Node**: Base class for all nodes.
- **ReflectionNode**: Creates copies of its target nodes and their outgoing edges.
- **RewritingNode**: Replaces a target node with a new node while preserving graph connectivity.
- **Traversal**: Depthfirst traversal of the graph.
## Installation
```bash
npm install
```
## Running Tests
```bash
npm test
```
The test suite verifies:
- Reflection node correctly duplicates target nodes.
- Rewriting node correctly replaces target nodes.
- Circular references are handled safely.
- Graph traversal works after modifications.
## Usage Example
```js
const { Graph, Node, ReflectionNode, RewritingNode } = require('./src/index');
const graph = new Graph();
graph.addNode(new Node('A'));
graph.addNode(new Node('B'));
graph.addNode(new Node('C'));
graph.addEdge('A', 'B');
graph.addEdge('B', 'C');
const r = new ReflectionNode('R');
graph.addNode(r);
graph.addEdge('R', 'B');
r.reflect(graph);
const w = new RewritingNode('W');
graph.addNode(w);
graph.addEdge('W', 'C');
const d = new Node('D');
w.rewrite(graph, 'C', d);
console.log(graph.traverse('A'));
```
## License
MIT