State in Erlang digraphs

The Erlang digraph module surprised me with a state change.

When working with other data structure modules in Erlang, for example, the sets module, an instance of the transferred data structure, is not changed. The function returns a new modified version, for example.

>S = sets:new(). >sets:size(S). 0 >T = sets:add_element(S, "element"). >sets:size(S). 0 >sets:size(T). 1 

This is not a behavior when working with the digraph module.

 >G = digraph:new(). >digraph:no_vertices(G). 0 >digraph:add_vertex(G, "vertex"). >digraph:no_vertices(G). 1 

First, why is the digraph library different in this regard?

Secondly, and more importantly, how does the digraph add a new state to an existing binding?

I assume that the state is stored in another process that the digraph module identifies using the existing and unchanged G binding. Is that so? Or are there other ways to change state related to binding?

+6
erlang directed-graph
source share
1 answer
  • Probably for efficiency
  • It uses ETS to store a digraph. The return value from the new one is actually a reference to the ets tables.

Launch the toolbar: start (). from your erlang shell and open the table visualization application - you will see a set of ets tables for the digraph utility.

 edges vertices neighbours 

The values ​​in the return value from the digraph: the new call is the identifiers of the tables of the tables of these tables ...

+9
source share

All Articles