package io.sigpipe.sing.stat;

import java.util.Random;

public class ReservoirSampler {

    private int count;
    private double[] reservoir;
    private double[] keys;
    private Random random = new Random();

    public ReservoirSampler(int size) {
        reservoir = new double[size];
        keys = new double[size];
    }
    }
    public int size() {
        return reservoir.length;
    }
    public double[] samples() {
        return this.reservoir;
    }
}

@@ -325,21 +325,527 @@
 ;%0A    %7D%0A
-    %7D
+%0A    public void put(double... items) %7B%0A        for (double item : items) %7B%0A            put(item);%0A        %7D%0A    %7D%0A%0A    public void put(double item) %7B%0A        if (count %3C this.size()) %7B%0A            reservoir%5Bcount%5D = item;%0A        %7D else %7B%0A            double r = random.nextDouble();%0A            if (r %3C ((double) this.size() / (count + 1))) %7B%0A                int i = random.nextInt(this.size());%0A                reservoir%5Bi%5D = item;%0A                keys%5Bi%5D = r;%0A            %7D%0A        %7D%0A%0A        count++;%0A    %7D%0A
 %0A    pub
@@ -896,24 +896,25 @@
 ngth;%0A    %7D%0A
+%0A
     public d
@@ -970,10 +970,74 @@
 ;%0A    %7D%0A
+%0A    private double%5B%5D keys() %7B%0A        return this.keys;%0A    %7D%0A%0A
 %7D%0A

Implement sampling