Class: Merge::CommonAncestors

Inherits:
Object
  • Object
show all
Defined in:
lib/merge/common_ancestors.rb

Constant Summary collapse

BOTH_PARENTS =
Set.new([:parent1, :parent2])

Instance Method Summary collapse

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

#countsObject



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

#findObject



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

Returns:

  • (Boolean)


28
29
30
# File 'lib/merge/common_ancestors.rb', line 28

def marked?(oid, flag)
  @flags[oid].include?(flag)
end