Skip to content

Instantly share code, notes, and snippets.

@giuliohome
Created August 9, 2018 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuliohome/c9d4e4104e618d3cc94d2d09436c0952 to your computer and use it in GitHub Desktop.
Save giuliohome/c9d4e4104e618d3cc94d2d09436c0952 to your computer and use it in GitHub Desktop.
more robust check
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
@giuliohome
Copy link
Author

for the simple case, if the map is guaranteed to be a tree without cycles, see https://gist.github.com/giuliohome/007d25d53d939966f4271acca6d73862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment