Created
August 9, 2018 14:12
-
-
Save giuliohome/c9d4e4104e618d3cc94d2d09436c0952 to your computer and use it in GitHub Desktop.
more robust check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec bfs2robust (fanout: Map<'node, 'node seq> -> 'node -> 'node seq) (tree: Map<'node, 'node seq>) (node: 'node) : 'node seq = | |
let single = seq [node] | |
match fanout tree node with | |
| e when e = Seq.empty -> single | |
| s -> Seq.fold (fun acc item -> | |
bfs2robust fanout (tree |> Map.remove node) item | |
|> Seq.append acc) single s |> Seq.distinct |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the simple case, if the map is guaranteed to be a tree without cycles, see https://gist.github.com/giuliohome/007d25d53d939966f4271acca6d73862