Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

digraph / digraph_utils: Adding edges to a subgraph fails unexpectedly #9191

Open
al2o3cr opened this issue Dec 15, 2024 · 0 comments
Open
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@al2o3cr
Copy link

al2o3cr commented Dec 15, 2024

Describe the bug

(discovered while solving AoC 2024 Day 5)

Adding edges to a graph that was created with digraph_utils:subgraph can fail with bad_edge unexpectedly.

The cause: when digraph_utils:subgraph copies edges into the result, it does not copy $eid in ntab so edge names are reused.

To Reproduce

%% simple reproduction for subgraph bug
main([]) ->
  G = digraph:new(),
  digraph:add_vertex(G, 1),
  digraph:add_vertex(G, 2),
  digraph:add_edge(G, 1, 2),

  SG = digraph_utils:subgraph(G, [1,2]),
  Result1 = digraph:add_edge(SG, 2, 1),
  io:format("~p~n", [Result1]),
  Result2 = digraph:add_edge(SG, 2, 1),
  io:format("~p~n", [Result2]).

prints (on OTP 27.1.2):

mattjones@Matts-Mac-Studio day5 % escript bug.erl
{error,{bad_edge,[2,1]}}
['$e'|1]

Expected behavior

The first call to digraph:add_edge should succeed.

Affected versions
Tested on 27.1.2, but digraph_utils.erl has not changed much over the years so likely many previous versions.

@al2o3cr al2o3cr added the bug Issue is reported as a bug label Dec 15, 2024
@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Dec 16, 2024
@lucioleKi lucioleKi self-assigned this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

3 participants