bitwalker / bitwalker/libgraph

Duplicated edges from Graph.edges(g, v) when v has a self-reference?

Offen
#65 5 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Elixir
Sterne
571
Forks
76
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Hi and first of all, thanks for maintaining this library. It has turned out to be essential to me since I started using it.

I'm a big fan of pattern matching over edges in the graph and it's a very intuitive way to write complicated case handling. However I just discovered that I'm getting duplicated edges when I am matching on, eg.

```
case graph |> Graph.edges(metric_key) do
%{v1: ^metric_key, v2: ^metric_key} -> ...
... other cases
end
```

From a glance at the code, a possible cause could be if a self-referencing edge could be described by both `v_in` and `v_out`:
https://github.com/bitwalker/libgraph/blob/15ff0b9ba8c22a9dfec5bc04096fb7025e58f34b/lib/graph.ex#L451

But the description would have to differ, otherwise the MapSet would make it unique.. Do you think this is a correct cause and if so, is it an intended one?

I don't suppose there is any inherent disadvantage in just matching instead on all edges as such:
```
case graph |> Graph.edges() do
%{v1: ^metric_key, v2: ^metric_key} -> ...
... other cases
_ -> [] # not the stuff we're interested in
end |> List.flatten()
```
Looking at the code, it seems to be pretty much the same amount of work being done -- and in my situation, I always need to flat_map anyway in what I am doing.

However, someone else may be tripped up on it and have a situation where getting duplicates could cause confusion down the line.

Best regards,
Dennis

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne in lib/graph.ex ungefähr bei Zeile 451 und reproduziere Graph.edges(graph, metric_key) mit einer Kante, die auf sich selbst verweist. Vergleiche die zurückgegebenen Kanten mit Graph.edges(graph) und untersuche, wie die v_in- und v_out-Pfade kombiniert und dedupliziert werden. Erledigt ist die Aufgabe, wenn das vorgesehene Verhalten für Selbstreferenzen festgelegt und durch einen Regressionstest abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
elixir
Bereich
data
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.