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:
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 (
DirectedEdgeand subclasses thereof) are respected, and a vertex will only be considered linked to another if it follows the forward direction. Undirected edges (UnDirectedEdgeand subclasses thereof) are considered linked in either direction.Note
You may assume that
create_adj_dict(load_adj_dict(d))returns exactlydfor some adjacency dictd. 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.