Module: TraceVisualization::Repetitions::Filter

Defined in:
lib/trace_visualization/repetitions/filter.rb

Class Method Summary collapse

Class Method Details

.delete_duplicates(context) ⇒ Object

Filter repetitions: delete duplicate



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/trace_visualization/repetitions/filter.rb', line 108

def self.delete_duplicates(context)
  i = 0
  while i < context.repetitions.size
    j = i + 1
    while j < context.repetitions.size
      if context.repetitions[i] == context.repetitions[j]
        context.delete_repetition(context.repetitions[j])
        context.repetitions.delete_at(j)
      else
        j += 1
      end        
    end
    i += 1
  end
end

.fix_boundaries(str, rs) ⇒ Object

Filter repetitions: Boundaries

  • Change repetitions with ‘n’ at the beginning or end



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/trace_visualization/repetitions/filter.rb', line 35

def self.fix_boundaries(str, rs)
  rs.each do |r|
    if str[r.get_left_pos(0)].to_str == "\n" && r.length > 1
      for i in 0 ... r.positions_size
        r.set_left_pos(i, r.get_left_pos(i) + 1)
      end
      r.length -= 1
    end

    if str[r.get_left_pos(0) + r.length - 1].to_str == "\n"
      r.length -= 1
    end
  end    
end

.merge(context) ⇒ Object

Merge repetitions with common positions



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/trace_visualization/repetitions/filter.rb', line 125

def self.merge(context)
  i = 0
  while i < context.repetitions.size
    j = 0
    while j < context.repetitions.size
      
      if i != j
        x, y = context.repetitions[i], context.repetitions[j]
        if x.length == y.length && x.k == y.k
          common_positions = x.left_positions & y.left_positions
          if common_positions.size == y.left_positions.size
            context.delete_repetition(y)
            context.repetitions.delete_at(j) 
          elsif common_positions.size > 0
            context.merge_repetitions(x, y)
            context.repetitions.delete_at(j)
          end
        end
      end
      
      j += 1
    end
    i += 1
  end
end

.repetitions_filter(str, context, options = {}) ⇒ Object

Filter repetitions



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/trace_visualization/repetitions/filter.rb', line 18

def self.repetitions_filter(str, context, options = {})
  Utils.set_default_options(options, { :positions_min_size => 3 })
    
  context.repetitions.delete_if do |repetition| 
    flag = repetition.positions_size < options[:positions_min_size] 

    context.delete_repetition(repetition) if flag

    flag
  end
    
  fix_boundaries(str, context.repetitions)
  delete_duplicates(context)
end

.split(str, context) ⇒ Object

Filter repetitions: Split

  • Split repetitions with ‘n’ at the center

  • Delete duplicate after split (one repeat a subset of the other)

NB It has meaning only for the strict repetitions, approximate repetitions doesn’t consist ‘n’



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/trace_visualization/repetitions/filter.rb', line 56

def self.split(str, context)
  splitted = []
  context.repetitions.delete_if do |r|
    pos = nil
    
    for i in r.get_left_pos(0) ... r.get_left_pos(0) + r.length
      if str[i].to_str == "\n"
        pos = i
        break
      end
    end
    
    if pos != nil
      # right part of split
      if r.length - pos - 1 >= 2
        length = r.length - pos - 1
        positions = (0 ... r.positions_size).collect { |i| r.get_left_pos(i) + pos + 1}
    
        nr = r.class.new(length, positions)
    
        splitted << nr
      end
  
      # left part of split
      if pos >= 2
        r.length = pos
        splitted << r
      end
    end

    context.delete_repetition(r) if pos != nil

    (pos != nil)
  end
    
  splitted.delete_if do |r|
    flag = false

    context.repetitions.each do |x|
      flag = ((x.left_positions & r.left_positions).size == r.left_positions.size && x.length >= r.length)
      break if flag
    end

    flag
  end

  Concatenation.process_new_repetitions(splitted, context)
    
  context.repetitions.concat(splitted)
end

.strict_repetitions_filter(str, context, options = {}) ⇒ Object

Filter for strict repetitions



9
10
11
12
13
14
15
# File 'lib/trace_visualization/repetitions/filter.rb', line 9

def self.strict_repetitions_filter(str, context, options = {})
  Utils.set_default_options(options, { :positions_min_size => 3 })
    
  repetitions_filter(str, context, options)
  split(str, context)
  merge(context)
end