Module: TraceVisualization::Reorder

Defined in:
lib/trace_visualization/reorder.rb

Class Method Summary collapse

Class Method Details

.process(data) ⇒ Object

Assign new int_values (ord field) in order to reduce the distance between min and max int_values. It’s necessary to reduce the size of the alphabet. Return max int_value



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
# File 'lib/trace_visualization/reorder.rb', line 9

def self.process(data)
  sorted = data.sort { |a, b| a.int_value <=> b.int_value }
  
  termination_chars = []
  
  idx, prev = 0, nil
  sorted.each do |item|
    if prev != item.int_value
      prev = item.int_value
      idx += 1
    end

    if item.int_value == TraceVisualization::TERMINATION_CHAR.ord
      termination_chars << item
      idx -= 1
    else
      item.ord = idx
    end
  end

  if termination_chars.size > 0
    # Set maximal value for termination char
    termination_chars.each { |x| x.ord = idx + 1 }
    idx += 1
  end
  
  idx
end