Class: StreamStats::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/stream_stats/counter.rb,
ext/stream_stats/stream_stats_counter.c

Constant Summary collapse

ATTRIBUTE_LIST =
[:count, :sum, :min, :max, :mean, :stddev]

Instance Method Summary collapse

Constructor Details

#initializeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'ext/stream_stats/stream_stats_counter.c', line 8

static VALUE strstat_counter_init(VALUE self) {
  counter *i_counter;
  VALUE data;

  i_counter = (counter *) malloc(sizeof(counter));

  if (init_counter(i_counter) != 0)
    rb_raise(rb_eArgError, "failed to initialize");

  data = Data_Wrap_Struct(counter_class, NULL, free, i_counter);
  rb_ivar_set(self, rb_intern("internal_struct"), data);

  return Qnil;
}

Instance Method Details

#<<(rb_sample) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'ext/stream_stats/stream_stats_counter.c', line 32

static VALUE strstat_counter_add_sample(VALUE self, VALUE rb_sample) {
  double sample;
  counter *i_counter;
  int returned;

  sample = NUM2DBL(rb_sample);

  i_counter = (counter*) strstat_get_struct(self);

  returned = counter_add_sample(i_counter, sample);
  if (returned != 0) {
    rb_raise(rb_eRuntimeError, "add sample returned %d", returned);
  }

  return Qnil;
}

#countObject



49
50
51
52
53
54
55
# File 'ext/stream_stats/stream_stats_counter.c', line 49

static VALUE strstat_counter_count(VALUE self) {
  counter *i_counter;

  i_counter = (counter*) strstat_get_struct(self);

  return LONG2NUM(counter_count(i_counter));
}

#inspectObject



6
7
8
9
10
11
# File 'lib/stream_stats/counter.rb', line 6

def inspect
  attr_list = ATTRIBUTE_LIST.map do |method|
    "#{method.to_s}: #{self.send(method)}"
  end * ', '
  "#{self.to_s} {#{attr_list}}"
end

#maxObject



67
68
69
# File 'ext/stream_stats/stream_stats_counter.c', line 67

static VALUE strstat_counter_max(VALUE self) {
  return strstat_counter_commoncall(self, counter_max);
}

#meanObject



70
71
72
# File 'ext/stream_stats/stream_stats_counter.c', line 70

static VALUE strstat_counter_mean(VALUE self) {
  return strstat_counter_commoncall(self, counter_mean);
}

#minObject



64
65
66
# File 'ext/stream_stats/stream_stats_counter.c', line 64

static VALUE strstat_counter_min(VALUE self) {
  return strstat_counter_commoncall(self, counter_min);
}

#squared_sumObject



79
80
81
# File 'ext/stream_stats/stream_stats_counter.c', line 79

static VALUE strstat_counter_squared_sum(VALUE self) {
  return strstat_counter_commoncall(self, counter_squared_sum);
}

#stddevObject



73
74
75
# File 'ext/stream_stats/stream_stats_counter.c', line 73

static VALUE strstat_counter_stddev(VALUE self) {
  return strstat_counter_commoncall(self, counter_stddev);
}

#sumObject



76
77
78
# File 'ext/stream_stats/stream_stats_counter.c', line 76

static VALUE strstat_counter_sum(VALUE self) {
  return strstat_counter_commoncall(self, counter_sum);
}