Skip to content

Commit

Permalink
Make it possible to check if a Dag contains a value
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 21, 2024
1 parent 66f25d7 commit 18db50d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/dag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ case class Dag[NodeType] private(edgeMap: Map[NodeType, Set[NodeType]] = Map()):
def remove(key: NodeType, value: NodeType): Dag[NodeType] =
Dag(edgeMap.updated(key, edgeMap.get(key).fold(Set())(_ - value)))

def has(key: NodeType): Boolean = edgeMap.contains(key)

def traversal[NodeType2](lambda: (Set[NodeType2], NodeType) -> NodeType2): Map[NodeType, NodeType2] =
sorted.foldLeft(Map[NodeType, NodeType2]()):
(map, next) => map.updated(next, lambda(apply(next).map(map), next))
Expand Down

0 comments on commit 18db50d

Please sign in to comment.