Class: Redu::WorstOffenderSet

Inherits:
Object
  • Object
show all
Defined in:
lib/redu/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_count) ⇒ WorstOffenderSet

Returns a new instance of WorstOffenderSet.



17
18
19
20
21
22
23
# File 'lib/redu/analyzer.rb', line 17

def initialize(max_count)
  @offenders = {}
  @max_count = max_count
  @least_worst_object = nil

  @offenders = Containers::MinHeap.new
end

Instance Method Details

#add(redis_debug_object) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/redu/analyzer.rb', line 25

def add(redis_debug_object)
  # If it's full and you aren't big enough skip you
  #puts "Least Worst Object: #{@least_worst_object.inspect}"
  if @offenders.size < @max_count
    @offenders.push(redis_debug_object.bytesize,redis_debug_object)
  else
    min = @offenders.min
    if min.bytesize < redis_debug_object.bytesize
      @offenders.pop
      @offenders.push(redis_debug_object.bytesize,redis_debug_object)
    end
  end
end

#max_sortObject



39
40
41
42
43
44
45
46
# File 'lib/redu/analyzer.rb', line 39

def max_sort
  output = []
  loop do 
    output << @offenders.pop
    break if @offenders.size == 0
  end
  output.reverse
end

#sorted_by_offenseObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/redu/analyzer.rb', line 48

def sorted_by_offense
  sorted_offenders = @offenders.sort do |a,b|
    b[1].bytesize <=> a[1].bytesize
  end
  output_offenders = []
  sorted_offenders.each do |pair|
    output_offenders << pair[1]
  end
  return output_offenders
end