Manuel Bustillo
726470267d
All checks were successful
Run unit tests / unit_tests (pull_request) Successful in 2m7s
28 lines
639 B
Ruby
28 lines
639 B
Ruby
class AffinityGroupsHierarchy < Array
|
|
include Singleton
|
|
|
|
def initialize
|
|
super
|
|
@references = {}
|
|
end
|
|
|
|
def find(name)
|
|
@references[name]
|
|
end
|
|
|
|
def <<(name)
|
|
new_node = Tree::TreeNode.new(name)
|
|
super(new_node).tap { @references[name] = new_node }
|
|
end
|
|
|
|
def register_child(parent_name, child_name)
|
|
@references[parent_name] << Tree::TreeNode.new(child_name).tap { |child_node| @references[child_name] = child_node }
|
|
end
|
|
|
|
def distance(name_a, name_b)
|
|
return nil if @references[name_a].nil? || @references[name_b].nil?
|
|
|
|
@references[name_a].distance_to_common_ancestor(@references[name_b])
|
|
end
|
|
end
|