-
Notifications
You must be signed in to change notification settings - Fork 3k
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
stdlib: Make vertex and edge ids in digraph unique #9361
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,8 @@ subgraph(Config) when is_list(Config) -> | |
{fg,f,g,fgl} = digraph:edge(SG, fg), | ||
{fg2,f,g,fgl2} = digraph:edge(SG, fg2), | ||
{_, {_, acyclic}} = lists:keysearch(cyclicity, 1, digraph:info(SG)), | ||
digraph:add_edge(SG, f, g), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't fail if I remove the bug fix. You will need to test the return value. |
||
digraph:add_vertex(SG, b), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This cannot fail because you are specifying the name of the new vertex. You will need to call |
||
true = digraph:delete(SG), | ||
|
||
SG1 = digraph_utils:subgraph(G, [f, g, h], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
erlang:unique_integer/0
will usually return a negative integer. The documentation says that the integer is greater than or equal to zero.This way of solving the problem works fine on a 64-bit system. In practice, all integers will always be small integers (fitting in a word).
However, on a 32-bit system, the integers from
erlang:unique_integer/0
can start to become bignums that no longer fit in a word. That could degrade performance in a long-running system.So I think it would be better to not change how the integers are generated in
digraph
, but instead changedigraph_utils:subgraph()
to ensure that the$eid
and$vid
values are copied into the new digraph. One way to implement that would be to add a new functiondigraph:new(G, Type)
, which would create a new digraph and inherit the$eid
and$vid
values fromG
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, setting
$eid
and$vid
according to the number of vertices and edges in a subgraph would be another way to fix it. I'll make an internal function to do that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly, performance will degrade (slightly) once the line is crossed, but
erlang:unique_integer([positive])
will still be much faster than the current dance in ETS:We can also store a "baseline" number that is the
erlang:unique_integer()
when the graph was first created, and make all edge identifiers relative to that, eating the bignum cost only once per edge unless a graph becomes too long-lived.Another variant is to use the
counters
module.Would this be exposed to the user? I would expect
digraph:new/2
taking an existing graph to make a copy thereof.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but performance could be degraded for other parts of the system that use
erlang:unique_integer/1
, because it is a global resource.