digraph(3erl)
π NAME π
okay bestie, we're talking about digraph(3erl) β Erlang Module Definition energy β and it's literally all about Directed graphs. slay.
β¨ DESCRIPTION β¨
This module gives you a version of labeled directed graphs (aka "digraphs"). π
The digraphs managed by this module are stored in ETS tables. That implies the following, so listen up:
- Only the process that created the digraph is allowed to update it.
- Digraphs will not be garbage collected. The ETS tables used for a digraph will only be deleted when
delete/1is called or the process that created the digraph terminates. - A digraph is a mutable data structure.
What makes the graphs provided here non-proper directed graphs is that multiple edges between vertices are allowed. However, the customary definition of directed graphs is used here. π«Ά
- A directed graph (or just "digraph") is a pair
(V, E)of a finite setVof vertices and a finite setEof directed edges (or just "edges"). The set of edgesEis a subset ofV x V(the Cartesian product ofVwith itself).
In this module, V is allowed to be empty. The so obtained unique digraph is called the empty digraph. Both vertices and edges are represented by unique Erlang terms.
- Digraphs can be annotated with more information. Such information can be attached to the vertices and to the edges of the digraph. An annotated digraph is called a labeled digraph, and the information attached to a vertex or an edge is called a label. Labels are Erlang terms. π
- An edge
e = (v, w)is said to emanate from vertexvand to be incident on vertexw. - The out-degree of a vertex is the number of edges emanating from that vertex.
- The in-degree of a vertex is the number of edges incident on that vertex.
- If an edge is emanating from
vand incident onw, thenwis said to be an out-neighbor ofv, andvis said to be an in-neighbor ofw. - A path
Pfromv[1]tov[k]in a digraph(V, E)is a non-empty sequencev[1], v[2], ..., v[k]of vertices inVsuch that there is an edge(v[i],v[i+1])inEfor1 <= i < k. - The length of path
Pisk-1. - Path
Pis simple if all vertices are distinct, except that the first and the last vertices can be the same. - Path
Pis a cycle if the length ofPis not zero andv[1] = v[k]. - A loop is a cycle of length one.
- A simple cycle is a path that is both a cycle and simple.
- An acyclic digraph is a digraph without cycles. periodt. π₯
𧬠DATA TYPES π§¬
d_type() = d_cyclicity() | d_protection()
d_cyclicity() = acyclic | cyclic
d_protection() = private | protected
graph()
edge()
label() = term()
vertex()
graph()β A digraph as returned bynew/0,1. πedge()β okay bestie, this one is just listed here with no extra description on the page.label()βlabel() = term()vertex()β also just vibing here with no extra description on the page. πΈ
β¨ EXPORTS β¨
okay bestie, this is the whole function roster π signatures are exact, vibes are immaculate, let's go.
π add_edge π
add_edge(G, V1, V2) -> edge() | {error, add_edge_err_rsn()}
add_edge(G, V1, V2, Label) -> edge() | {error, add_edge_err_rsn()}
add_edge(G, E, V1, V2, Label) ->
edge() | {error, add_edge_err_rsn()}
Types:
G = graph()
E = edge()
V1 = V2 = vertex()
Label = label()
add_edge_err_rsn() =
{bad_edge, Path :: [vertex()]} | {bad_vertex, V :: vertex()}
add_edge/5 creates (or modifies) edge E of digraph G, using Label as the (new) label of the edge. The edge is emanating from V1 and incident on V2. Returns E. β¨
add_edge(G, V1, V2, Label) is equivalent to add_edge(G, E, V1, V2, Label), where E is a created edge. The created edge is represented by term ['$e' | N], where N is an integer >= 0.
add_edge(G, V1, V2) is equivalent to add_edge(G, V1, V2, []).
if the edge would create a cycle in an acyclic digraph,{error, {bad_edge, Path}}is returned. IfGalready has an edge with valueEconnecting a different pair of vertices,{error, {bad_edge, [V1, V2]}}is returned. If either ofV1orV2is not a vertex of digraphG,{error, {bad_vertex, V}}is returned,V = V1orV = V2. π
π add_vertex π
add_vertex(G) -> vertex()
add_vertex(G, V) -> vertex()
add_vertex(G, V, Label) -> vertex()
Types:
G = graph()
V = vertex()
Label = label()
add_vertex/3 creates (or modifies) vertex V of digraph G, using Label as the (new) label of the vertex. Returns V. π
add_vertex(G, V) is equivalent to add_vertex(G, V, []).
add_vertex/1 creates a vertex using the empty list as label, and returns the created vertex. The created vertex is represented by term ['$v' | N], where N is an integer >= 0.
π¦ del_edge π¦
del_edge(G, E) -> true
Types:
G = graph()
E = edge()
Deletes edge E from digraph G. bye edge, slay. β¨
πΈ del_edges πΈ
del_edges(G, Edges) -> true
Types:
G = graph()
Edges = [edge()]
Deletes the edges in list Edges from digraph G. group removal, iconic. π
π§ del_path π§
del_path(G, V1, V2) -> true
Types:
G = graph()
V1 = V2 = vertex()
Deletes edges from digraph G until there are no paths from vertex V1 to vertex V2.
A sketch of the procedure employed:
- Find an arbitrary simple path
v[1], v[2], ..., v[k]fromV1toV2inG. - Remove all edges of
Gemanating fromv[i]and incident tov[i+1]for1 <= i < k(including multiple edges). - Repeat until there is no path between
V1andV2.
π del_vertex π
del_vertex(G, V) -> true
Types:
G = graph()
V = vertex()
Deletes vertex V from digraph G. Any edges emanating from V or incident on V are also deleted. no cap, it takes the whole vibe with it. π
π del_vertices π
del_vertices(G, Vertices) -> true
Types:
G = graph()
Vertices = [vertex()]
Deletes the vertices in list Vertices from digraph G.
π₯ delete π₯
delete(G) -> true
Types:
G = graph()
Deletes digraph G. This call is important as digraphs are implemented with ETS. There is no garbage collection of ETS tables. However, the digraph is deleted if the process that created the digraph terminates.
bestie, this one is highkey important β ETS tables do not clean themselves up, periodt. π
β edge β
edge(G, E) -> {E, V1, V2, Label} | false
Types:
G = graph()
E = edge()
V1 = V2 = vertex()
Label = label()
Returns {E, V1, V2, Label}, where Label is the label of edge E emanating from V1 and incident on V2 of digraph G. If no edge E of digraph G exists, false is returned.
π edges π
edges(G) -> Edges
Types:
G = graph()
Edges = [edge()]
Returns a list of all edges of digraph G, in some unspecified order.
edges(G, V) -> Edges
Types:
G = graph()
V = vertex()
Edges = [edge()]
Returns a list of all edges emanating from or incident on V of digraph G, in some unspecified order.
π«Ά get_cycle π«Ά
get_cycle(G, V) -> Vertices | false
Types:
G = graph()
V = vertex()
Vertices = [vertex(), ...]
If a simple cycle of length two or more exists through vertex V, the cycle is returned as a list [V, ..., V] of vertices. If a loop through V exists, the loop is returned as a list [V]. If no cycles through V exist, false is returned.
get_path/3 is used for finding a simple cycle through V.
π¦ get_path π¦
get_path(G, V1, V2) -> Vertices | false
Types:
G = graph()
V1 = V2 = vertex()
Vertices = [vertex(), ...]
Tries to find a simple path from vertex V1 to vertex V2 of digraph G. Returns the path as a list [V1, ..., V2] of vertices, or false if no simple path from V1 to V2 of length one or more exists.
Digraph G is traversed in a depth-first manner, and the first found path is returned.
π« get_short_cycle π«
get_short_cycle(G, V) -> Vertices | false
Types:
G = graph()
V = vertex()
Vertices = [vertex(), ...]
Tries to find an as short as possible simple cycle through vertex V of digraph G. Returns the cycle as a list [V, ..., V] of vertices, or false if no simple cycle through V exists. Notice that a loop through V is returned as list [V, V].
get_short_path/3 is used for finding a simple cycle through V.
π get_short_path π
get_short_path(G, V1, V2) -> Vertices | false
Types:
G = graph()
V1 = V2 = vertex()
Vertices = [vertex(), ...]
Tries to find an as short as possible simple path from vertex V1 to vertex V2 of digraph G. Returns the path as a list [V1, ..., V2] of vertices, or false if no simple path from V1 to V2 of length one or more exists.
Digraph G is traversed in a breadth-first manner, and the first found path is returned.
π in_degree π
in_degree(G, V) -> integer() >= 0
Types:
G = graph()
V = vertex()
Returns the in-degree of vertex V of digraph G.
π§ in_edges π§
in_edges(G, V) -> Edges
Types:
G = graph()
V = vertex()
Edges = [edge()]
Returns a list of all edges incident on V of digraph G, in some unspecified order.
πͺ© in_neighbours πͺ©
in_neighbours(G, V) -> Vertex
Types:
G = graph()
V = vertex()
Vertex = [vertex()]
Returns a list of all in-neighbors of V of digraph G, in some unspecified order.
π info π
info(G) -> InfoList
Types:
G = graph()
InfoList =
[{cyclicity, Cyclicity :: d_cyclicity()} |
{memory, NoWords :: integer() >= 0} |
{protection, Protection :: d_protection()}]
d_cyclicity() = acyclic | cyclic
d_protection() = private | protected
Returns a list of {Tag, Value} pairs describing digraph G. The following pairs are returned:
{cyclicity, Cyclicity}, whereCyclicityiscyclicoracyclic, according to the options given tonew.{memory, NoWords}, whereNoWordsis the number of words allocated to the ETS tables.{protection, Protection}, whereProtectionisprotectedorprivate, according to the options given tonew.
β¨ new β¨
new() -> graph()
Equivalent to new([]).
new(Type) -> graph()
Types:
Type = [d_type()]
d_type() = d_cyclicity() | d_protection()
d_cyclicity() = acyclic | cyclic
d_protection() = private | protected
Returns an empty digraph with properties according to the options in Type:
cyclic: Allows cycles in the digraph (default).acyclic: The digraph is to be kept acyclic.protected: Other processes can read the digraph (default).private: The digraph can be read and modified by the creating process only.
If an unrecognized type option T is specified or Type is not a proper list, a badarg exception is raised.
π no_edges π
no_edges(G) -> integer() >= 0
Types:
G = graph()
Returns the number of edges of digraph G.
π§Έ no_vertices π§Έ
no_vertices(G) -> integer() >= 0
Types:
G = graph()
Returns the number of vertices of digraph G.
πΊ out_degree πΊ
out_degree(G, V) -> integer() >= 0
Types:
G = graph()
V = vertex()
Returns the out-degree of vertex V of digraph G.
π out_edges π
out_edges(G, V) -> Edges
Types:
G = graph()
V = vertex()
Edges = [edge()]
Returns a list of all edges emanating from V of digraph G, in some unspecified order.
π¦ out_neighbours π¦
out_neighbours(G, V) -> Vertices
Types:
G = graph()
V = vertex()
Vertices = [vertex()]
Returns a list of all out-neighbors of V of digraph G, in some unspecified order.
πΈ vertex πΈ
vertex(G, V) -> {V, Label} | false
Types:
G = graph()
V = vertex()
Label = label()
Returns {V, Label}, where Label is the label of the vertex V of digraph G, or false if no vertex V of digraph G exists.
π vertices π
vertices(G) -> Vertices
Types:
G = graph()
Vertices = [vertex()]
Returns a list of all vertices of digraph G, in some unspecified order.
π SEE ALSO π
digraph_utils(3erl), ets(3erl)
okay that's the whole exports menu, bestie β and the footer energy is Ericsson AB Β· stdlib 4.3.1.3 Β· digraph(3erl), source/version/date sign-off slay. mwah, periodt. ππ
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms