Class: TraceVisualization::Repetitions::Context
- Inherits:
-
Object
- Object
- TraceVisualization::Repetitions::Context
- Defined in:
- lib/trace_visualization/repetitions/context.rb
Instance Attribute Summary collapse
-
#hashes ⇒ Object
Returns the value of attribute hashes.
-
#mapping ⇒ Object
Returns the value of attribute mapping.
-
#repetitions ⇒ Object
Returns the value of attribute repetitions.
-
#repetitions_by_line ⇒ Object
Returns the value of attribute repetitions_by_line.
Instance Method Summary collapse
- #delete_repetition(repetition) ⇒ Object
- #init_repetitions_by_line(new_repetitions) ⇒ Object
-
#initialize(mapping) ⇒ Context
constructor
A new instance of Context.
- #lines ⇒ Object
- #merge_repetitions(x, y) ⇒ Object
Constructor Details
#initialize(mapping) ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 |
# File 'lib/trace_visualization/repetitions/context.rb', line 8 def initialize mapping @mapping = mapping @repetitions_by_line = Array.new(@mapping.lines.size) { [] } @hashes = [] end |
Instance Attribute Details
#hashes ⇒ Object
Returns the value of attribute hashes.
6 7 8 |
# File 'lib/trace_visualization/repetitions/context.rb', line 6 def hashes @hashes end |
#mapping ⇒ Object
Returns the value of attribute mapping.
6 7 8 |
# File 'lib/trace_visualization/repetitions/context.rb', line 6 def mapping @mapping end |
#repetitions ⇒ Object
Returns the value of attribute repetitions.
6 7 8 |
# File 'lib/trace_visualization/repetitions/context.rb', line 6 def repetitions @repetitions end |
#repetitions_by_line ⇒ Object
Returns the value of attribute repetitions_by_line.
6 7 8 |
# File 'lib/trace_visualization/repetitions/context.rb', line 6 def repetitions_by_line @repetitions_by_line end |
Instance Method Details
#delete_repetition(repetition) ⇒ Object
46 47 48 49 50 |
# File 'lib/trace_visualization/repetitions/context.rb', line 46 def delete_repetition(repetition) repetition.lines.each do |line| @repetitions_by_line[line].delete_if { |item| item[0].id == repetition.id } end end |
#init_repetitions_by_line(new_repetitions) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trace_visualization/repetitions/context.rb', line 23 def init_repetitions_by_line(new_repetitions) for r in new_repetitions r_pos = r.left_positions r.lines.clear i, j = 0, 0 while (i < @mapping.lines.size && j < r_pos.size) a, b = @mapping.lines[i], (i + 1 < @mapping.lines.size ? @mapping.lines[i + 1] : 2**32) if a <= r_pos[j] && r_pos[j] < b @repetitions_by_line[i] << [r, r_pos[j]] r.lines << i j += 1 else i += 1 end end end @repetitions_by_line.each { |item| item.sort! { |a, b| a[1] <=> b[1] } } end |
#lines ⇒ Object
19 20 21 |
# File 'lib/trace_visualization/repetitions/context.rb', line 19 def lines @mapping.lines end |
#merge_repetitions(x, y) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/trace_visualization/repetitions/context.rb', line 52 def merge_repetitions(x, y) x.left_positions.concat(y.left_positions).uniq!.sort! if x.right_positions x.right_positions.concat(y.right_positions).uniq!.sort! end y.lines.each do |line| for i in 0 ... @repetitions_by_line[line].size if @repetitions_by_line[line][i][0].id == y.id @repetitions_by_line[line][i][0] = x x.lines << line unless x.lines.index line end end end end |