Class: Merge::CommonAncestors
- Inherits:
-
Object
- Object
- Merge::CommonAncestors
- Defined in:
- lib/merge/common_ancestors.rb
Constant Summary collapse
- BOTH_PARENTS =
Set.new([:parent1, :parent2])
Instance Method Summary collapse
- #counts ⇒ Object
- #find ⇒ Object
-
#initialize(database, one, twos) ⇒ CommonAncestors
constructor
A new instance of CommonAncestors.
- #marked?(oid, flag) ⇒ Boolean
Constructor Details
#initialize(database, one, twos) ⇒ CommonAncestors
Returns a new instance of CommonAncestors.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/merge/common_ancestors.rb', line 8 def initialize(database, one, twos) @database = database @flags = Hash.new { |hash, oid| hash[oid] = Set.new } @queue = [] @results = [] insert_by_date(@queue, @database.load(one)) @flags[one].add(:parent1) twos.each do |two| insert_by_date(@queue, @database.load(two)) @flags[two].add(:parent2) end end |
Instance Method Details
#counts ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/merge/common_ancestors.rb', line 32 def counts ones, twos = 0, 0 @flags.each do |oid, flags| next unless flags.size == 1 ones += 1 if flags.include?(:parent1) twos += 1 if flags.include?(:parent2) end [ones, twos] end |
#find ⇒ Object
23 24 25 26 |
# File 'lib/merge/common_ancestors.rb', line 23 def find process_queue until all_stale? @results.map(&:oid).reject { |oid| marked?(oid, :stale) } end |
#marked?(oid, flag) ⇒ Boolean
28 29 30 |
# File 'lib/merge/common_ancestors.rb', line 28 def marked?(oid, flag) @flags[oid].include?(flag) end |