@Test public void stressTest() { List<String> stringSet = randomNumberStrings(100_000); UIntValueMap<String> a = new UIntValueMap<>(); UIntValueMap<String> b = new UIntValueMap<>(); for (int i = 0; i < 20; i++) { for (String s : stringSet) { char c = s.charAt(s.length() - 1); if (a.contains(s)) { a.incrementByAmount(s, 1); continue; } if (b.contains(s)) { b.incrementByAmount(s, 1); continue; } if (c % 2 == 0) { a.incrementByAmount(s, 1); } else { b.incrementByAmount(s, 1); } } } Log.info("[a] key count = %d ", a.size()); Log.info("[b] key count = %d ", b.size()); for (String k : a) { Assert.assertFalse(b.contains(k)); } }
public int incrementByAmount(T key, int amount) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int l = locate(key); if (l < 0) { l = -l - 1; values[l] = amount; keys[l] = key; keyCount++; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } else { values[l] += amount; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } }
UIntValueMap extends HashBase<T> implements Iterable<T> { public int incrementByAmount(T key, int amount) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int l = locate(key); if (l < 0) { l = -l - 1; values[l] = amount; keys[l] = key; keyCount++; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } else { values[l] += amount; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } } }
UIntValueMap extends HashBase<T> implements Iterable<T> { public int incrementByAmount(T key, int amount) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int l = locate(key); if (l < 0) { l = -l - 1; values[l] = amount; keys[l] = key; keyCount++; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } else { values[l] += amount; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } } UIntValueMap();  UIntValueMap(int size); }
UIntValueMap extends HashBase<T> implements Iterable<T> { public int incrementByAmount(T key, int amount) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int l = locate(key); if (l < 0) { l = -l - 1; values[l] = amount; keys[l] = key; keyCount++; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } else { values[l] += amount; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } } UIntValueMap();  UIntValueMap(int size); int get(T key); void put(T key, int value); int increment(T key); void incrementAll(Iterable<T> keys); int decrement(T key); int incrementByAmount(T key, int amount); List<IntValueMap.Entry<T>> getAsEntryList(); Iterator<IntValueMap.Entry<T>> entryIterator(); Iterable<IntValueMap.Entry<T>> iterableEntries(); int sizeLarger(int amount); int sizeSmaller(int amount); int maxValue(); int minValue(); long sumOfValues(int minValue, int maxValue); int[] valueArray(); long sumOfValues(); }
UIntValueMap extends HashBase<T> implements Iterable<T> { public int incrementByAmount(T key, int amount) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int l = locate(key); if (l < 0) { l = -l - 1; values[l] = amount; keys[l] = key; keyCount++; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } else { values[l] += amount; if (values[l] < 0) { throw new IllegalStateException("Value reached to negative."); } return values[l]; } } UIntValueMap();  UIntValueMap(int size); int get(T key); void put(T key, int value); int increment(T key); void incrementAll(Iterable<T> keys); int decrement(T key); int incrementByAmount(T key, int amount); List<IntValueMap.Entry<T>> getAsEntryList(); Iterator<IntValueMap.Entry<T>> entryIterator(); Iterable<IntValueMap.Entry<T>> iterableEntries(); int sizeLarger(int amount); int sizeSmaller(int amount); int maxValue(); int minValue(); long sumOfValues(int minValue, int maxValue); int[] valueArray(); long sumOfValues();  }