@Override
    public void add(long item, long count) {
        if (count < 0) {
            // Negative values are not implemented in the regular version, and do not
            // play nicely with this algorithm anyway
            throw new IllegalArgumentException("Negative increments not implemented");
        }
        int[] buckets = new int[depth];
        for (int i = 0; i < depth; ++i) {
            buckets[i] = hash(item, i);
        }
        long min = table[0][buckets[0]];
        for (int i = 1; i < depth; ++i) {
            min = Math.min(min, table[i][buckets[i]]);
        }
        for (int i = 0; i < depth; ++i) {
            long newVal = Math.max(table[i][buckets[i]], min + count);
            table[i][buckets[i]] = newVal;
        }
        size += count;
    }
@Test
    public void testAccuracy() {
        int seed = 7364181;
        Random r = new Random(seed);
        int numItems = 10000000;
        int maxScale = 15000;
        double epsOfTotalCount = 0.00075;
        double errorRange = epsOfTotalCount;
        double confidence = 0.99;

        int[] actualFreq = new int[maxScale];
        IFrequency sketch = new ConservativeAddSketch(epsOfTotalCount, confidence, seed);
        IFrequency baseSketch = new CountMinSketch(epsOfTotalCount, confidence, seed);

        for (int i = 0; i < numItems; i++) {
            int x = r.nextInt(maxScale);
            sketch.add(x, 1);
            baseSketch.add(x, 1);
            actualFreq[x]++;
        }

        int numErrors = 0;
        int usedNumbers = 0;
        int betterNumbers = 0;
        long totalDelta = 0;
        int okayError = (int) (numItems * errorRange) + 1;
        long totalError = 0;
        for (int i = 0; i < actualFreq.length; i++) {
            if (actualFreq[i] > 0) {
                usedNumbers++;
            } else {
                continue;
            }
            long error = sketch.estimateCount(i) - actualFreq[i];
            totalError += error;
            if (error > okayError) {
                numErrors++;
            }
            long delta = baseSketch.estimateCount(i) - sketch.estimateCount(i);
            if (delta > 0) {
                totalDelta += delta;
                betterNumbers++;
            }
        }
        double pCorrect = 1 - 1.0 * numErrors / usedNumbers;
        System.out.println("Confidence : " + pCorrect + "   Errors : " + numErrors + "  Error margin : " + okayError);
        System.out.println("Total error : " + totalError + "  Average error : " + totalError / usedNumbers);
        System.out.println("Beat base for : " + 100 * betterNumbers / usedNumbers + " percent of values" +
                           " with a total delta of " + totalDelta);
        assertTrue("Confidence not reached: required " + confidence + ", reached " + pCorrect, pCorrect > confidence);
    }