Class: HardReservoir
Instance Attribute Summary
Attributes inherited from Reservoir
Instance Method Summary collapse
- #<<(obj) ⇒ Object
-
#initialize(sample_size) ⇒ HardReservoir
constructor
assumes examples are pre-randomized, but ensures that all elements are unique.
- #uniq(*args, &block) ⇒ Object
Methods inherited from Reservoir
Methods included from Enumerable
#average, #count_by, #geometric_mean, #histogram, #length_of_longest, #length_of_shortest, #longest, #median, #median_by, #percentile, #percentile_by, #rfind, #shortest, #to_percent, #to_ratio, #triangle, #with_previous
Constructor Details
#initialize(sample_size) ⇒ HardReservoir
assumes examples are pre-randomized, but ensures that all elements are unique
43 44 45 46 47 |
# File 'lib/muflax/reservoir.rb', line 43 def initialize sample_size @sample_size = sample_size @total = 0 @reservoir = Set.new end |
Instance Method Details
#<<(obj) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/muflax/reservoir.rb', line 49 def <<(obj) # *only* fill empty slot in the reservoir @reservoir << obj if @reservoir.size < @sample_size @total += 1 end |
#uniq(*args, &block) ⇒ Object
56 |
# File 'lib/muflax/reservoir.rb', line 56 def uniq *args, &block ; @reservoir.to_a.uniq(*args, &block) ; end |