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.
10 11 12 13 |
# File 'lib/kruskal/tree.rb', line 10 def initialize(index, relations = []) @index, @relations = index, relations reindex end |
Instance Method Details
#add(value, source, target) ⇒ Object
31 32 33 34 |
# File 'lib/kruskal/tree.rb', line 31 def add(value, source, target) @relations << [value, source, target] index(target) end |
#eql?(other) ⇒ Boolean Also known as: ==
15 16 17 18 19 20 21 22 23 |
# File 'lib/kruskal/tree.rb', line 15 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
27 28 29 |
# File 'lib/kruskal/tree.rb', line 27 def hash @relations.hash end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/kruskal/tree.rb', line 43 def inspect "Tree#{@relations.inspect}" end |
#merge!(other_tree) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/kruskal/tree.rb', line 36 def merge!(other_tree) other_tree.add_relations_to(@relations) other_tree.each do |(v, s, t)| index(s, t) end end |