class LimitedUniformReservoir implements Reservoir {

    private static final int DEFAULT_SIZE = 4096;

    private static final int BITS_PER_LONG = 63;

    private final AtomicLong count = new AtomicLong();

    private volatile AtomicLongArray values = new AtomicLongArray(DEFAULT_SIZE);

    @Override
    public int size() {
        final long c = count.get();
        if (c > values.length()) {
            return values.length();
        }
        return (int) c;
    }

    @Override
    public void update(long value) {
        final long c = count.incrementAndGet();
        if (c <= values.length()) {
            values.set((int) c - 1, value);
        } else {
            final long r = nextLong(c);
            if (r < values.length()) {
                values.set((int) r, value);
            }
        }
    }

    @Override
    public Snapshot getSnapshot() {<FILL_FUNCTION_BODY>}

    public void reset() {
        count.set(0);
        values = new AtomicLongArray(DEFAULT_SIZE);
    }

    private static long nextLong(long n) {
        long bits;
        long val;
        do {
            bits = ThreadLocalRandom.current().nextLong() & (~(1L << BITS_PER_LONG));
            val = bits % n;
        } while (bits - val + (n - 1) < 0L);
        return val;
    }
}

        final int s = size();
        final List<Long> copy = new ArrayList<>(s);
        for (int i = 0; i < s; i++) {
            copy.add(values.get(i));
        }
        return new UniformSnapshot(copy);
    
<no_super_class>