Class: TraceVisualization::Data::Repetition

Inherits:
RepetitionBase show all
Defined in:
lib/trace_visualization/data/repetition.rb

Constant Summary collapse

@@sequence =
0

Instance Attribute Summary collapse

Attributes inherited from RepetitionBase

#k, #left, #length, #lines, #right

Instance Method Summary collapse

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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trace_visualization/data/repetition.rb', line 27

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]
  @lines = []
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/trace_visualization/data/repetition.rb', line 12

def id
  @id
end

#left_positionsObject (readonly)

Returns the value of attribute left_positions.



11
12
13
# File 'lib/trace_visualization/data/repetition.rb', line 11

def left_positions
  @left_positions
end

#pcountObject

Returns the value of attribute pcount.



10
11
12
# File 'lib/trace_visualization/data/repetition.rb', line 10

def pcount
  @pcount
end

#right_positionsObject (readonly)

Returns the value of attribute right_positions.



11
12
13
# File 'lib/trace_visualization/data/repetition.rb', line 11

def right_positions
  @right_positions
end

#scoreObject

Returns the value of attribute score.



9
10
11
# File 'lib/trace_visualization/data/repetition.rb', line 9

def score
  @score
end

#strict_idsObject

Returns the value of attribute strict_ids.



13
14
15
# File 'lib/trace_visualization/data/repetition.rb', line 13

def strict_ids
  @strict_ids
end

Instance Method Details

#build_positionsObject

Build positions for hl print:

[
  [[pos, len], [], ... ],
  [[pos, len], [], ... ],
  ...  
]


69
70
71
72
73
74
75
76
77
# File 'lib/trace_visualization/data/repetition.rb', line 69

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], [], ... ]


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/trace_visualization/data/repetition.rb', line 81

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

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/trace_visualization/data/repetition.rb', line 58

def equal_positions?(r)
  @left_positions == r.left_positions && 
  @right_positions == r.right_positions
end

#get_left_pos(idx) ⇒ Object



46
47
48
# File 'lib/trace_visualization/data/repetition.rb', line 46

def get_left_pos(idx)
  @left_positions[idx]
end

#get_right_pos(idx) ⇒ Object



54
55
56
# File 'lib/trace_visualization/data/repetition.rb', line 54

def get_right_pos(idx)
  @right_positions != nil ? @right_positions[idx] : -1
end

#positions_sizeObject



42
43
44
# File 'lib/trace_visualization/data/repetition.rb', line 42

def positions_size
  @left_positions.size
end

#set_left_pos(idx, val) ⇒ Object



50
51
52
# File 'lib/trace_visualization/data/repetition.rb', line 50

def set_left_pos(idx, val)
  @left_positions[idx] = val
end

#to_sObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/trace_visualization/data/repetition.rb', line 15

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