class Sodium::Graph(T)
- Sodium::Graph(T)
- Reference
- Object
Included Modules
- Iterator(T)
Direct Known Subclasses
Defined in:
sodium/graph.crConstructors
-
.new
Initialize empty graph
Instance Method Summary
-
#/(partition : Hash(T, Enumerable(T)))
Compute quotient graph with respect to the given partition
-
#[](node : T)
Get node from graph
-
#[]?(node : T)
Check if graph contains node and possibly returns object
-
#add_cycle(nodes : Array(T))
Add cycle to graph
-
#add_edge(u : T, v : T, **attr)
Add edge between u and v to graph
-
#add_edges_from(list : Enumerable(Tuple(T, T)))
Add edges from enumerable to graph
-
#add_node(n : T, **attr)
Add node to graph or update node attributes
-
#add_nodes_from(list : Enumerable(T))
Add nodes from enumerable to graph
-
#add_path(nodes : Enumerable(T))
Add path of nodes to graph
-
#add_star(nodes : Array(T))
Add star to graph (first node in array is center)
-
#add_weighted_edges_from(list : Enumerable(Tuple(T, T, Int32)))
Add weighted edgres from enumerable of form (u, v, weight) to graph
-
#adjacency_list
Return adjacency list in order of #nodes()
-
#clear
Clear graph
-
#copy
Return shallow copy of graph
-
#degree(node : T)
Return degree of node
-
#edges
Return all edges in graph
-
#get_edge_data(u : T, v : T)
Return associated data of specified edge
-
#has_edge?(u : T, v : T)
Check if graph contains edge
-
#has_node?(node : T)
Check if graph contains node
-
#neighbours(node)
Return neighbours of node
-
#next
Iterator
: Get next node -
#nodes
Return all nodes in graph
-
#nodes_with_data
Return all nodes in graph with data
-
#nodes_with_selfloops
Return nodes with self loop
-
#number_of_edges(list : Enumerable(Tuple(T, T)))
Return number of edges between nodes
-
#number_of_nodes
Return number of nodes in graph
-
#number_of_selfloops
Return number of edges with self loops
-
#order
Return order of graph
-
#remove_edge(u : T, v : T)
Remove edge from graph
-
#remove_edges_from(list : Enumerable(Tuple(T, T)))
Remove edges given in enumerable from graph
-
#remove_node(n : T)
Remove node from graph
-
#remove_nodes_from(list : Enumerable(T))
Remove nodes given in enumerable from graph
-
#rewind
Iterator
: Rewind -
#selfloop_edges
Return edges with self loops
-
#selfloop_edges_with_data
Return self-looping edges with data
-
#size
Return number of edges
Constructor Detail
Instance Method Detail
Compute quotient graph with respect to the given partition
The partition is given in the form of a Hash map of objects representing the partition's parts to the vertices included in each part.
g = Sodium::Graph(Int32).new
g.add_edges_from([{1, 2}, {3, 4}, {5, 6}])
h = g / g.nodes.group_by { |n| n % 3 }
h.edges # => [{1, 2}, {1, 0}, {2, 0}]
Add weighted edgres from enumerable of form (u, v, weight) to graph