@Override public byte adjustOrPutValue(long key, byte newValue, byte incrValue) { int i = indexOfInsertion(key); if (i < 0) { //already contained i = -i - 1; this.values[i] += incrValue; return this.values[i]; } else { put(key, newValue); return newValue; } }
@Test public void testAdjustOrPutValue() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 23); map.put((long) 13, (byte) 24); map.put((long) 14, (byte) 25); map.adjustOrPutValue((long)11, (byte)1, (byte)3); assertEquals(25, map.get((long)11) ); map.adjustOrPutValue((long)15, (byte)1, (byte)3); assertEquals(1, map.get((long)15) ); }
@Test public void testKeysSortedByValue() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 23); map.put((long) 13, (byte) 24); map.put((long) 14, (byte) 25); map.removeKey((long) 13); LongArrayList keys = new LongArrayList(); map.keysSortedByValue(keys); long[] keysArray = keys.toArray(new long[keys.size()]); assertArrayEquals(new long[] {11, 12, 14}, keysArray ); }
@Test public void testForEachKey() { final LongArrayList keys = new LongArrayList(); OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 23); map.put((long) 13, (byte) 24); map.put((long) 14, (byte) 25); map.removeKey((long) 13); map.forEachKey(new LongProcedure() { @Override public boolean apply(long element) { keys.add(element); return true; } }); long[] keysArray = keys.toArray(new long[keys.size()]); Arrays.sort(keysArray); assertArrayEquals(new long[] {11, 12, 14}, keysArray ); }
int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity); return put(key, value);
@Test public void testValues() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 23); map.put((long) 13, (byte) 24); map.put((long) 14, (byte) 25); map.removeKey((long) 13); ByteArrayList values = new ByteArrayList(100); map.values(values); assertEquals(3, values.size()); values.sort(); assertEquals(22, values.get(0) ); assertEquals(23, values.get(1) ); assertEquals(25, values.get(2) ); }
@Test public void testEquals() { // since there are no other subclasses of // Abstractxxx available, we have to just test the // obvious. OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 23); map.put((long) 13, (byte) 24); map.put((long) 14, (byte) 25); map.removeKey((long) 13); OpenLongByteHashMap map2 = (OpenLongByteHashMap) map.copy(); assertEquals(map, map2); assertTrue(map2.equals(map)); assertFalse("Hello Sailor".equals(map)); assertFalse(map.equals("hello sailor")); map2.removeKey((long) 11); assertFalse(map.equals(map2)); assertFalse(map2.equals(map)); }
@Test public void testClone() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); OpenLongByteHashMap map2 = (OpenLongByteHashMap) map.clone(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testContainsKey() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); assertTrue(map.containsKey((long) 11)); assertFalse(map.containsKey((long) 12)); }
@Test public void testCopy() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); OpenLongByteHashMap map2 = (OpenLongByteHashMap) map.copy(); map.clear(); assertEquals(1, map2.size()); }
@Test public void testContainValue() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); assertTrue(map.containsValue((byte) 22)); assertFalse(map.containsValue((byte) 23)); }
@Test public void testKeys() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 22); LongArrayList keys = new LongArrayList(); map.keys(keys); keys.sort(); assertEquals(11, keys.get(0) ); assertEquals(12, keys.get(1) ); LongArrayList k2 = map.keys(); k2.sort(); assertEquals(keys, k2); }
@Test public void testPairsMatching() { LongArrayList keyList = new LongArrayList(); ByteArrayList valueList = new ByteArrayList(); OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); map.put((long) 12, (byte) 23); map.put((long) 13, (byte) 24); map.put((long) 14, (byte) 25); map.removeKey((long) 13); map.pairsMatching(new LongByteProcedure() { @Override public boolean apply(long first, byte second) { return (first % 2) == 0; }}, keyList, valueList); keyList.sort(); valueList.sort(); assertEquals(2, keyList.size()); assertEquals(2, valueList.size()); assertEquals(12, keyList.get(0) ); assertEquals(14, keyList.get(1) ); assertEquals(23, valueList.get(0) ); assertEquals(25, valueList.get(1) ); }
@Test public void testClear() { OpenLongByteHashMap map = new OpenLongByteHashMap(); map.put((long) 11, (byte) 22); assertEquals(1, map.size()); map.clear(); assertEquals(0, map.size()); assertEquals(0, map.get((long) 11), 0.0000001); }
@Override public byte adjustOrPutValue(long key, byte newValue, byte incrValue) { int i = indexOfInsertion(key); if (i < 0) { //already contained i = -i - 1; this.values[i] += incrValue; return this.values[i]; } else { put(key, newValue); return newValue; } }
@Override public byte adjustOrPutValue(long key, byte newValue, byte incrValue) { int i = indexOfInsertion(key); if (i < 0) { //already contained i = -i - 1; this.values[i] += incrValue; return this.values[i]; } else { put(key, newValue); return newValue; } }
int newCapacity = chooseGrowCapacity(this.distinct + 1, this.minLoadFactor, this.maxLoadFactor); rehash(newCapacity); return put(key, value);