@datastructures/graph
v0.0.1
Published
A minimal functional typed implementation of Graph ππ
Downloads
6
Maintainers
Readme
@datastructures/graph ππ
A minimal functional typed implementation of a graph. π¦
A collection of vertices related by edges
Install
yarn add @datastructures/graph -D
Usage
import { graph, vertex } from '@datastructures/graph'
const chart = graph().addVertex('foo').addVertex('bar')
chart.addEdge('foo', 'bar')
const viewChart = chart.render()
// => { directed: false, vertices: [ { key: 'foo', ...}, { key: 'bar', ...} ], edges: ['foo-bar' ]}
const printChart = chart.print()
API
Vertex
A individual vertice
key
: a string vertex identifier
siblings
: an array of vertices
addSibling
: a methode for adding siblings to a vertex
ex: const item = vertex('foo').addSibling('bar')
Methods
addVertex
: adds a vertex to the graph
ex: const chart = graph().addVertex('foo')
addEdge
: adds an edge to the Graph
ex: const chart = graph().addVertex('foo').addEdge('bar').addEdge('foo', 'bar')
render
: renders the graph
ex: const chart = graph().addVertex('foo').addEdge('bar').addEdge('foo', 'bar').render()
print
: renders a string output of the graph
ex: const chart = graph().addVertex('foo').addEdge('bar').addEdge('foo', 'bar').print()
Data Structures π¦
Basic. Functional. Typed. Data Structures.
Functional typed data structures offering structure clarity and simplicity.