SpaceSaving { public boolean inc(long key) { int index = 0; FingerPrintAux hash = indices.getHash(key); index = (int) indices.getOrDefault(hash, -1); if (index < argmin) { index = Math.max(0, argmin-1); this.put(hash, index); } assert (indices.get(hash) == index):"error"; int quantity = (int) quantities.get(index); FingerPrintAux quantityHash = lastsOfQuantity.getHash(quantity); int last; if (quantity < n/size) { last = getLastOfQuantity(quantity, quantityHash); assert(last != -1); this.replace(hash, last); assert(indices.get(hash) == getLastOfQuantity(quantity, quantityHash)); } else { last = index; } quantity = incrementQuantity(last, quantityHash); return quantity == n/size; } SpaceSaving(int n, int size, int keySize);   SpaceSaving(int n, int size); boolean containsKey(long e); int bound(long e); int getMin(); int error(long e); boolean inc(long key); String toString();  }
@Test public void testInc() { long key = 611; int n = 1<<10; int size = 1<<5; SpaceSaving ss = new SpaceSaving(n, size, 10); for (int i=0; i < size - 1;++i) { System.out.println(i); assertEquals(ss.bound(key), i); assertFalse(ss.inc(key)); } assertTrue(ss.inc(key)); assertEquals(ss.bound(key), size); }