CSBiology / FSharp.FGL

Functional graph library for F#
https://csbiology.github.io/FSharp.FGL/
MIT License
61 stars 11 forks source link

[BUG] Edges.fold processes edges twice in directed Graph #48

Closed 7enderhead closed 2 years ago

7enderhead commented 2 years ago

Describe the bug Directed.Edges.fold processes each directed edge in both directions, although only one direction is given.

To Reproduce dotnet fsi session:

> let dg: Graph<string,unit,unit> =
-     Directed.Graph.create [] []
-     |> Vertices.add ("1", ())
-     |> Vertices.add ("2", ())
-     |> Vertices.add ("3", ())
-     |> Edges.add ("1", "2", ());;
val dg: Graph<string,unit,unit> =
  map
    [("1", (map [], (), map [("2", null)]));
     ("2", (map [("1", null)], (), map [])); ("3", (map [], (), map []))]

> 
- Directed.Edges.count dg;;
val it: int = 1

> 
- Directed.Edges.iter (fun v1 v2 _ -> printfn $"{v1} -> {v2}") dg;;
1 -> 2
val it: unit = ()

> Directed.Edges.fold (fun r v1 v2 e -> r + sprintf $"\n{v1} -> {v2}") String.Empty dg;;
val it: string = "
1 -> 2
2 -> 1"

Expected behavior Directed.Edges.fold should only process each directed edge once, in the given direction.

OS and framework information (please complete the following information):

LibraChris commented 2 years ago

Thank you for pointing this out, I will fix it as soon as possible.

LibraChris commented 2 years ago

@7enderhead Just for clarification, did you use the nuget package of FSharp.FGL? I can only reproduce the bug in the nuget package but not the library dll. If that is the case, publishing an updated version of the nuget package will fix this bug and I apologize for the inconvenience.

7enderhead commented 2 years ago

I'm using nuget package FSharp.FGL 0.0.2.

LibraChris commented 2 years ago

ok then this is a bugfix that was not yet in the nuget package. I will create and publish the new version of the package right away.

LibraChris commented 2 years ago

The updated package is now online. Thanks again for pointing this out.