class HardReservoir
Public Class Methods
new(sample_size)
click to toggle source
assumes examples are pre-randomized, but ensures that all elements are unique
# File lib/muflax/reservoir.rb, line 43 def initialize sample_size @sample_size = sample_size @total = 0 @reservoir = Set.new end
Public Instance Methods
<<(obj)
click to toggle source
# 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 ;)
click to toggle source
# File lib/muflax/reservoir.rb, line 56 def uniq *args, &block ; @reservoir.to_a.uniq(*args, &block) ; end