https://github.com/planetis-m/patgraph
Efficient graph data structure library. The graph is a seq of nodes plus a seq of edges.
https://github.com/planetis-m/patgraph
graph nim nim-lang
Last synced: 23 days ago
JSON representation
Efficient graph data structure library. The graph is a seq of nodes plus a seq of edges.
- Host: GitHub
- URL: https://github.com/planetis-m/patgraph
- Owner: planetis-m
- Created: 2019-12-29T19:00:31.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-11T19:12:50.000Z (about 2 years ago)
- Last Synced: 2024-05-02T04:20:17.767Z (12 months ago)
- Topics: graph, nim, nim-lang
- Language: Nim
- Homepage:
- Size: 104 KB
- Stars: 17
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Patgraph — graph data structure library for Nim
## About
This nimble package contains a ``Graph[N, E]`` graph datastructure using an adjacency list representation.
It is based on [petgraph's](https://github.com/petgraph/petgraph/blob/master/src/graph_impl/mod.rs) library.[Documentation](https://planetis-m.github.io/patgraph/patgraph.html)
### Example
```nim
import patgraphvar graph: Graph[string, float]
let nodeA = graph.addNode("a")
let nodeB = graph.addNode("b")
let nodeC = graph.addNode("c")
let nodeD = graph.addNode("d")
let nodeE = graph.addNode("e")
let nodeF = graph.addNode("f")
let nodeG = graph.addNode("g")
let nodeH = graph.addNode("h")graph.extendWithEdges([
(nodeA, nodeB, 0.0),
(nodeA, nodeC, 0.25),
(nodeB, nodeD, 0.5),
(nodeB, nodeE, 0.75),
(nodeC, nodeF, 1.0),
(nodeC, nodeG, 1.25),
(nodeE, nodeF, 1.5),
(nodeE, nodeH, 1.75),
(nodeF, nodeG, 2.0)])echo graph
# a -> [c: 0.25, b: 0.0]
# b -> [e: 0.75, d: 0.5]
# c -> [g: 1.25, f: 1.0]
# d -> []
# e -> [h: 1.75, f: 1.5]
# f -> [g: 2.0]
# g -> []
# h -> []for n in graph.neighbors(nodeC):
echo graph[n]
# g
# f
```### License
This library is distributed under the MIT license. For more information see `LICENSE`.