Module: RbBCC::DisplayHelper
- Included in:
- RbBCC
- Defined in:
- lib/rbbcc/disp_helper.rb
Overview
They’re directly ported from table.py They might be more looked like Ruby code
Instance Method Summary collapse
- #print_linear_hist(vals, val_type) ⇒ Object
- #print_log2_hist(vals, val_type, strip_leading_zero) ⇒ Object
- #stars(val, val_max, width) ⇒ Object
Instance Method Details
#print_linear_hist(vals, val_type) ⇒ Object
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 |
# File 'lib/rbbcc/disp_helper.rb', line 70 def print_linear_hist(vals, val_type) stars_max = $stars_max log2_dist_max = 64 idx_max = -1 val_max = 0 vals.each_with_index do |v, i| idx_max = i if v > 0 val_max = v if v > val_max end header = " %-13s : count distribution" body = " %-10d : %-8d |%-*s|" stars = stars_max if idx_max >= 0 puts(header % val_type); end (0...(idx_max + 1)).each do |i| val = vals[i] puts(body % [i, val, stars, stars(val, val_max, stars)]) end end |
#print_log2_hist(vals, val_type, strip_leading_zero) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rbbcc/disp_helper.rb', line 24 def print_log2_hist(vals, val_type, strip_leading_zero) stars_max = $stars_max log2_dist_max = 64 idx_max = -1 val_max = 0 vals.each_with_index do |v, i| idx_max = i if v > 0 val_max = v if v > val_max end if idx_max <= 32 header = " %-19s : count distribution" body = "%10d -> %-10d : %-8d |%-*s|" stars = stars_max else header = " %-29s : count distribution" body = "%20d -> %-20d : %-8d |%-*s|" stars = stars_max / 2 end if idx_max > 0 puts(header % val_type) end (1...(idx_max + 1)).each do |i| low = (1 << i) >> 1 high = (1 << i) - 1 if (low == high) low -= 1 end val = vals[i] if strip_leading_zero if val puts(body % [low, high, val, stars, stars(val, val_max, stars)]) strip_leading_zero = false end else puts(body % [low, high, val, stars, stars(val, val_max, stars)]) end end end |
#stars(val, val_max, width) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbbcc/disp_helper.rb', line 10 def stars(val, val_max, width) i = 0 text = "" while true break if (i > (width * val.to_f / val_max) - 1) || (i > width - 1) text += "*" i += 1 end if val > val_max text = text[0...-1] + "+" end return text end |