https://github.com/calvinlfer/dag-validator
A simple Directed Acyclic Graph validator that detects if cycles are present
https://github.com/calvinlfer/dag-validator
dag fp functional-programming scala
Last synced: 5 months ago
JSON representation
A simple Directed Acyclic Graph validator that detects if cycles are present
- Host: GitHub
- URL: https://github.com/calvinlfer/dag-validator
- Owner: calvinlfer
- Created: 2018-06-19T18:36:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-19T18:51:27.000Z (over 7 years ago)
- Last Synced: 2025-07-01T05:07:24.981Z (5 months ago)
- Topics: dag, fp, functional-programming, scala
- Language: Scala
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Directed Acyclic Graph Validator ##
*Cycle detection for DAGs*
[](https://travis-ci.org/calvinlfer/dag-validator)
### Example Usage ###
Here is an example of an valid directed graph which has no cycles
```scala
import com.experiments.calvin.dag.DagValidator
object Dag extends DagValidator
import Dag._
val graph: Graph[Int] = Graph(
1 -> List(2, 3),
2 -> List(3),
3 -> Nil
)
detectCycle(graph)
// false
```
Here's an example of a graph with cycles
```scala
import com.experiments.calvin.dag.DagValidator
object Dag extends DagValidator
import Dag._
val graphWithCycle: Graph[String] = Map(
"A" -> List("B"),
"B" -> List("C"),
"C" -> List("E"),
"E" -> List("F", "D"),
"D" -> List("B"),
"F" -> Nil
)
detectCycle(graphWithCycle)
// true
```
### Credits ###
* [Tushar Roy](https://www.educative.io/page/11000001/60001)