Class: Kruskal::Tree
- Inherits:
-
Object
- Object
- Kruskal::Tree
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/kruskal/tree.rb
Instance Method Summary collapse
- #add(value, source, target) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(index, relations = []) ⇒ Tree
constructor
A new instance of Tree.
- #inspect ⇒ Object
- #merge!(other_tree) ⇒ Object
Constructor Details
#initialize(index, relations = []) ⇒ Tree
Returns a new instance of Tree.
8 9 10 11 |
# File 'lib/kruskal/tree.rb', line 8 def initialize(index, relations = []) @index, @relations = index, relations reindex end |
Instance Method Details
#add(value, source, target) ⇒ Object
29 30 31 32 |
# File 'lib/kruskal/tree.rb', line 29 def add(value, source, target) @relations << [value, source, target] index(target) end |
#eql?(other) ⇒ Boolean Also known as: ==
13 14 15 16 17 18 19 20 21 |
# File 'lib/kruskal/tree.rb', line 13 def eql?(other) if other.is_a?(self.class) other.relations_equal_to(@relations) elsif other.is_a?(Array) @relations == other else false end end |
#hash ⇒ Object
25 26 27 |
# File 'lib/kruskal/tree.rb', line 25 def hash @relations.hash end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/kruskal/tree.rb', line 41 def inspect "Tree#{@relations.inspect}" end |
#merge!(other_tree) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/kruskal/tree.rb', line 34 def merge!(other_tree) other_tree.add_relations_to(@relations) other_tree.each do |(v, s, t)| index(s, t) end end |