Class: TraceVisualization::Data::Repetition
- Inherits:
-
RepetitionBase
- Object
- RepetitionBase
- TraceVisualization::Data::Repetition
- Defined in:
- lib/trace_visualization/data/repetition.rb
Constant Summary collapse
- @@sequence =
0
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#left_positions ⇒ Object
readonly
Returns the value of attribute left_positions.
-
#pcount ⇒ Object
Returns the value of attribute pcount.
-
#right_positions ⇒ Object
readonly
Returns the value of attribute right_positions.
-
#score ⇒ Object
Returns the value of attribute score.
-
#strict_ids ⇒ Object
Returns the value of attribute strict_ids.
Attributes inherited from RepetitionBase
#k, #left, #length, #lines, #right
Instance Method Summary collapse
- #==(other_repetition) ⇒ Object
-
#build_positions ⇒ Object
Build positions for hl print: [ [[pos, len], [], … ], [[pos, len], [], … ], … ].
-
#build_positions_for_repeat(pos) ⇒ Object
————————————————————————- [[pos, len], [], … ].
- #equal_positions?(r) ⇒ Boolean
- #get_left_pos(idx) ⇒ Object
- #get_right_pos(idx) ⇒ Object
-
#initialize(length, left_positions, right_positions = nil) ⇒ Repetition
constructor
A new instance of Repetition.
- #positions_size ⇒ Object
- #set_left_pos(idx, val) ⇒ Object
- #to_s ⇒ Object
Methods inherited from RepetitionBase
#left_length, #right_length, #strict_length
Methods included from IRepetition
#get_id, #left_length, #right_length, #strict_length
Constructor Details
#initialize(length, left_positions, right_positions = nil) ⇒ Repetition
Returns a new instance of Repetition.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trace_visualization/data/repetition.rb', line 29 def initialize(length, left_positions, right_positions = nil) super() @k = 0 @pcount = 1 @length = length @left_positions = left_positions @right_positions = right_positions @id = (@@sequence += 1) @strict_ids = [ @id ] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/trace_visualization/data/repetition.rb', line 9 def id @id end |
#left_positions ⇒ Object (readonly)
Returns the value of attribute left_positions.
10 11 12 |
# File 'lib/trace_visualization/data/repetition.rb', line 10 def left_positions @left_positions end |
#pcount ⇒ Object
Returns the value of attribute pcount.
13 14 15 |
# File 'lib/trace_visualization/data/repetition.rb', line 13 def pcount @pcount end |
#right_positions ⇒ Object (readonly)
Returns the value of attribute right_positions.
10 11 12 |
# File 'lib/trace_visualization/data/repetition.rb', line 10 def right_positions @right_positions end |
#score ⇒ Object
Returns the value of attribute score.
12 13 14 |
# File 'lib/trace_visualization/data/repetition.rb', line 12 def score @score end |
#strict_ids ⇒ Object
Returns the value of attribute strict_ids.
15 16 17 |
# File 'lib/trace_visualization/data/repetition.rb', line 15 def strict_ids @strict_ids end |
Instance Method Details
#==(other_repetition) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/trace_visualization/data/repetition.rb', line 43 def ==(other_repetition) other_repetition != nil && @length == other_repetition.length && @left_positions == other_repetition.left_positions && @right_positions == other_repetition.right_positions end |
#build_positions ⇒ Object
Build positions for hl print:
[
[[pos, len], [], ... ],
[[pos, len], [], ... ],
...
]
77 78 79 80 81 82 83 84 85 |
# File 'lib/trace_visualization/data/repetition.rb', line 77 def build_positions result = [] @left_positions.each do |lpos| result << build_positions_for_repeat(lpos) end result end |
#build_positions_for_repeat(pos) ⇒ Object
[[pos, len], [], ... ]
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/trace_visualization/data/repetition.rb', line 89 def build_positions_for_repeat(pos) result = [] for i in 0 ... positions_size lpos, rpos = get_left_pos(i), get_right_pos(i) if lpos == pos if @k == 0 result += [[lpos, left_length()]] else result += left.build_positions_for_repeat(lpos) result += right.build_positions_for_repeat(rpos) end end end result end |
#equal_positions?(r) ⇒ Boolean
66 67 68 69 |
# File 'lib/trace_visualization/data/repetition.rb', line 66 def equal_positions?(r) @left_positions == r.left_positions && @right_positions == r.right_positions end |
#get_left_pos(idx) ⇒ Object
54 55 56 |
# File 'lib/trace_visualization/data/repetition.rb', line 54 def get_left_pos(idx) @left_positions[idx] end |
#get_right_pos(idx) ⇒ Object
62 63 64 |
# File 'lib/trace_visualization/data/repetition.rb', line 62 def get_right_pos(idx) @right_positions != nil ? @right_positions[idx] : -1 end |
#positions_size ⇒ Object
50 51 52 |
# File 'lib/trace_visualization/data/repetition.rb', line 50 def positions_size @left_positions.size end |
#set_left_pos(idx, val) ⇒ Object
58 59 60 |
# File 'lib/trace_visualization/data/repetition.rb', line 58 def set_left_pos(idx, val) @left_positions[idx] = val end |
#to_s ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/trace_visualization/data/repetition.rb', line 17 def to_s "Repetition ##{self.id}: score = #{@score}, k = #{@k}, " + "length = #{@length}, " + "positions.size = #{@left_positions.size}, " + "left_positions = #{@left_positions}, " + "right_positions = #{@right_positions}, " + "strict_ids = #{@strict_ids}, " + "lines = #{lines}, " + "left = #{@left != nil ? @left.id : 'nil'}, " + "right = #{@right != nil ? @right.id : 'nil'}" end |