8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/git_fit/dedup/group_consolidator.rb', line 8
def consolidate(matched_pairs)
parent = {}
all_ids = []
matched_pairs.each do |pair|
a_id = pair[:a][:run_id]
b_id = pair[:b][:run_id]
all_ids << a_id << b_id
end
all_ids.uniq!
return {} if all_ids.empty?
all_ids.each { |id| parent[id] = id }
matched_pairs.each do |pair|
union(parent, pair[:a][:run_id], pair[:b][:run_id])
end
groups = Hash.new { |h, k| h[k] = [] }
all_ids.each do |run_id|
root = find(parent, run_id)
groups[root] << run_id
end
groups.transform_values! { |ids| ids.uniq.sort }
result = {}
groups.each_value do |sorted_ids|
group_id = Digest::SHA256.hexdigest(sorted_ids.join(','))[0, 16]
result[group_id] = sorted_ids
end
result
end
|