class Sodium::Graph(T)

Included Modules

Direct Known Subclasses

Defined in:

sodium/graph.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

Initialize empty graph


[View source]

Instance Method Detail

def /(partition : Hash(T, Enumerable(T))) #

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}]

[View source]
def [](node : T) #

Get node from graph


[View source]
def []?(node : T) #

Check if graph contains node and possibly returns object


[View source]
def add_cycle(nodes : Array(T)) #

Add cycle to graph


[View source]
def add_edge(u : T, v : T, **attr) #

Add edge between u and v to graph


[View source]
def add_edges_from(list : Enumerable(Tuple(T, T))) #

Add edges from enumerable to graph


[View source]
def add_node(n : T, **attr) #

Add node to graph or update node attributes


[View source]
def add_nodes_from(list : Enumerable(T)) #

Add nodes from enumerable to graph


[View source]
def add_path(nodes : Enumerable(T)) #

Add path of nodes to graph


[View source]
def add_star(nodes : Array(T)) #

Add star to graph (first node in array is center)


[View source]
def add_weighted_edges_from(list : Enumerable(Tuple(T, T, Int32))) #

Add weighted edgres from enumerable of form (u, v, weight) to graph


[View source]
def adjacency_list #

Return adjacency list in order of #nodes()


[View source]
def clear #

Clear graph


[View source]
def copy #

Return shallow copy of graph


[View source]
def degree(node : T) #

Return degree of node


[View source]
def edges #

Return all edges in graph


[View source]
def get_edge_data(u : T, v : T) #

Return associated data of specified edge


[View source]
def has_edge?(u : T, v : T) #

Check if graph contains edge


[View source]
def has_node?(node : T) #

Check if graph contains node


[View source]
def neighbours(node) #

Return neighbours of node


[View source]
def next #

Iterator: Get next node


[View source]
def nodes #

Return all nodes in graph


[View source]
def nodes_with_data #

Return all nodes in graph with data


[View source]
def nodes_with_selfloops #

Return nodes with self loop


[View source]
def number_of_edges(list : Enumerable(Tuple(T, T))) #

Return number of edges between nodes


[View source]
def number_of_nodes #

Return number of nodes in graph


[View source]
def number_of_selfloops #

Return number of edges with self loops


[View source]
def order #

Return order of graph


[View source]
def remove_edge(u : T, v : T) #

Remove edge from graph


[View source]
def remove_edges_from(list : Enumerable(Tuple(T, T))) #

Remove edges given in enumerable from graph


[View source]
def remove_node(n : T) #

Remove node from graph


[View source]
def remove_nodes_from(list : Enumerable(T)) #

Remove nodes given in enumerable from graph


[View source]
def rewind #

Iterator: Rewind


[View source]
def selfloop_edges #

Return edges with self loops


[View source]
def selfloop_edges_with_data #

Return self-looping edges with data


[View source]
def size #

Return number of edges


[View source]