class Graphsrb::AdjacencyList
Attributes
adj_list[R]
Public Class Methods
create_node(vertex_id, args={})
click to toggle source
Creates and returns the created node
# File lib/graphsrb/adjacency_list.rb, line 72 def self.create_node(vertex_id, args={}) Graphsrb::Node.new(vertex_id, args) end
new()
click to toggle source
# File lib/graphsrb/adjacency_list.rb, line 5 def initialize @adj_list = [] end
Public Instance Methods
<<(node)
click to toggle source
Adds a node to the adjacency list
# File lib/graphsrb/adjacency_list.rb, line 15 def <<(node) add(node) end
add(node)
click to toggle source
Adds a node to the adjacency list
# File lib/graphsrb/adjacency_list.rb, line 10 def add(node) adj_list << node.clone end
clear()
click to toggle source
Remove all nodes from the list
# File lib/graphsrb/adjacency_list.rb, line 67 def clear adj_list.clear end
delete(node)
click to toggle source
Removes a node from the adjacency list
# File lib/graphsrb/adjacency_list.rb, line 41 def delete(node) adj_list.delete(node) end
each(&block)
click to toggle source
# File lib/graphsrb/adjacency_list.rb, line 31 def each(&block) @adj_list.each(&block) end
find(node)
click to toggle source
Searches for a node in the adjacency list Returns nil if not found
# File lib/graphsrb/adjacency_list.rb, line 47 def find(node) index = adj_list.index node if index.nil? return nil else adj_list[index] end end
has_node?(node)
click to toggle source
Returns true if the adjacency list contains the node, false otherwise
# File lib/graphsrb/adjacency_list.rb, line 62 def has_node?(node) not find(node).nil? end
increase_weight(node, dw)
click to toggle source
Increses weight by dw
# File lib/graphsrb/adjacency_list.rb, line 26 def increase_weight(node, dw) node = find(node) node.update_weight(node.weight + dw) unless node.nil? end
nodes()
click to toggle source
Returns all nodes
# File lib/graphsrb/adjacency_list.rb, line 57 def nodes adj_list.clone end
size()
click to toggle source
Returns the number of nodes in the adjacency list
# File lib/graphsrb/adjacency_list.rb, line 36 def size adj_list.size end
update_weight(node, w)
click to toggle source
Updates weight
# File lib/graphsrb/adjacency_list.rb, line 20 def update_weight(node, w) node = find(node) node.update_weight(w) unless node.nil? end