class Algorithmable::UnionFind::Impl
Attributes
quantity[R]
Public Class Methods
new(quantity, find_strategy = SimpleFind.new, union_strategy = SimpleUnion.new)
click to toggle source
# File lib/algorithmable/union_find.rb, line 10 def initialize(quantity, find_strategy = SimpleFind.new, union_strategy = SimpleUnion.new) @index = (0..quantity).to_a @quantity = quantity @find_strategy = find_strategy @union_strategy = union_strategy end
Public Instance Methods
connected?(p1, p2)
click to toggle source
# File lib/algorithmable/union_find.rb, line 26 def connected?(p1, p2) find(p1) == find(p2) end
find(p)
click to toggle source
# File lib/algorithmable/union_find.rb, line 17 def find(p) @find_strategy.find(p, @index) end
union(p1, p2)
click to toggle source
# File lib/algorithmable/union_find.rb, line 21 def union(p1, p2) @union_strategy.union(p1, p2, @index) @quantity -= 1 end