edgegraph.builder.adjlist.create_adj_dict

edgegraph.builder.adjlist.create_adj_dict#

edgegraph.builder.adjlist.create_adj_dict(uni)#

Create an adjacency dict from a graph. Effectively the reverse of load_adj_dict().

This function returns an adjacency dictionary from a graph. This dictionary lists all unique vertices as the keys, and then all vertices which they link to are given as a list in the value. For example, consider the following graph:

object v0
object v1
object v2
object v3
object v4
object v5

v0 -- v1
v0 -- v2
v0 -- v3
v1 -- v2
v1 -- v3
v1 -- v4
v2 -- v3
v2 -- v4
v2 -- v5
v3 -- v3

The adjacency dictionary returned would look like:

{
v0: [v1, v2, v3],
v1: [v0, v2, v3, v4],
v2: [v0, v1, v3, v4, v5],
v3: [v0, v1, v2, v3],      # origin in list -> self-edge
v4: [v1, v2],
v5: [v2],
}

Directed edges (DirectedEdge and subclasses thereof) are respected, and a vertex will only be considered linked to another if it follows the forward direction. Undirected edges (UnDirectedEdge and subclasses thereof) are considered linked in either direction.

Note

You may assume that create_adj_dict(load_adj_dict(d)) returns exactly d for some adjacency dict d. However, this is NOT ALWAYS TRUE, especially when dealing with undirected edges!! This function adds all reachable vertices to the list for each vertex; which means for an undirected edge, both vertices will be listed in the adjacency entries for each of them.

This is expected and desired behavior.

See also

The load_adj_dict() function is more-or-less the inverse of this one, accepting the adjacency dictionary as an argument and returning a formed graph.

Parameters:

uni (Universe) – The Universe graph container to analyze.

Returns:

A dictionary containing adjacency information for the given universe.

Return type:

dict[Vertex, list[Vertex]]