@Test public void testSimple() { DoubleLinkedCountingSet s = new DoubleLinkedCountingSet(10, 5); assertEquals(0, s.elementsCount); s.increment(3); assertEquals(1, s.elementsCount); assertEquals(1, s.counts[0]); assertEquals(3, s.dense[0]); s.increment(10); assertEquals(2, s.elementsCount); assertEquals(1, s.counts[1]); assertEquals(10, s.dense[1]); s.increment(3); assertEquals(2, s.elementsCount); assertEquals(2, s.counts[0]); }
public void increment(int key) { int index = sparse[key]; if (index < elementsCount && dense[index] == key) { counts[index]++; } else { index = elementsCount++; sparse[key] = index; dense[index] = key; counts[index] = 1; } }
DoubleLinkedCountingSet { public void increment(int key) { int index = sparse[key]; if (index < elementsCount && dense[index] == key) { counts[index]++; } else { index = elementsCount++; sparse[key] = index; dense[index] = key; counts[index] = 1; } } }
DoubleLinkedCountingSet { public void increment(int key) { int index = sparse[key]; if (index < elementsCount && dense[index] == key) { counts[index]++; } else { index = elementsCount++; sparse[key] = index; dense[index] = key; counts[index] = 1; } } DoubleLinkedCountingSet(int maxValue, int maxValues); }
DoubleLinkedCountingSet { public void increment(int key) { int index = sparse[key]; if (index < elementsCount && dense[index] == key) { counts[index]++; } else { index = elementsCount++; sparse[key] = index; dense[index] = key; counts[index] = 1; } } DoubleLinkedCountingSet(int maxValue, int maxValues); void increment(int key); void clear(); }
DoubleLinkedCountingSet { public void increment(int key) { int index = sparse[key]; if (index < elementsCount && dense[index] == key) { counts[index]++; } else { index = elementsCount++; sparse[key] = index; dense[index] = key; counts[index] = 1; } } DoubleLinkedCountingSet(int maxValue, int maxValues); void increment(int key); void clear(); final int[] sparse; final int[] dense; final int[] counts; public int elementsCount; }