@Test public void testPut() { CompactHashMap<String,Integer> map = new CompactHashMap<String,Integer>(TRANSLATOR); assertEquals(null, map.put("a", 9)); assertEquals(null, map.put("b", 8)); assertEquals(null, map.put("c", 7)); assertEquals(null, map.put("d", 6)); map.checkStructure(); assertEquals(null, map.put("e", 5)); assertEquals(null, map.put("f", 4)); assertEquals(null, map.put("g", 3)); assertEquals(null, map.put("h", 2)); map.checkStructure(); assertEquals((Integer)9, map.put("a", 0)); assertEquals((Integer)8, map.put("b", 1)); assertEquals((Integer)7, map.put("c", 2)); map.checkStructure(); assertEquals((Integer)6, map.put("d", 3)); assertEquals((Integer)5, map.put("e", 4)); assertEquals((Integer)4, map.put("f", 5)); map.checkStructure(); assertEquals((Integer)3, map.put("g", 6)); assertEquals((Integer)2, map.put("h", 7)); map.checkStructure(); }
public V put(K key, V value) { Objects.requireNonNull(key); version++; int index = probe(key); boolean isNew = index < 0; V result = isNew ? null : translator.deserializeValue(table[index]); if (isNew) { if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); index = ~index; if (table[index] != TOMBSTONE) { filled++; } } table[index] = translator.serialize(key, value); if (isNew) { incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); } return result; }
CompactHashMap extends AbstractMap<K,V> { public V put(K key, V value) { Objects.requireNonNull(key); version++; int index = probe(key); boolean isNew = index < 0; V result = isNew ? null : translator.deserializeValue(table[index]); if (isNew) { if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); index = ~index; if (table[index] != TOMBSTONE) { filled++; } } table[index] = translator.serialize(key, value); if (isNew) { incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); } return result; } }
CompactHashMap extends AbstractMap<K,V> { public V put(K key, V value) { Objects.requireNonNull(key); version++; int index = probe(key); boolean isNew = index < 0; V result = isNew ? null : translator.deserializeValue(table[index]); if (isNew) { if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); index = ~index; if (table[index] != TOMBSTONE) { filled++; } } table[index] = translator.serialize(key, value); if (isNew) { incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); } return result; } CompactHashMap(CompactMapTranslator<K,V> trans); }
CompactHashMap extends AbstractMap<K,V> { public V put(K key, V value) { Objects.requireNonNull(key); version++; int index = probe(key); boolean isNew = index < 0; V result = isNew ? null : translator.deserializeValue(table[index]); if (isNew) { if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); index = ~index; if (table[index] != TOMBSTONE) { filled++; } } table[index] = translator.serialize(key, value); if (isNew) { incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); } return result; } CompactHashMap(CompactMapTranslator<K,V> trans); void clear(); int size(); @SuppressWarnings("unchecked") boolean containsKey(Object key); V get(Object key); V put(K key, V value); V remove(Object key); Set<Map.Entry<K,V>> entrySet(); }
CompactHashMap extends AbstractMap<K,V> { public V put(K key, V value) { Objects.requireNonNull(key); version++; int index = probe(key); boolean isNew = index < 0; V result = isNew ? null : translator.deserializeValue(table[index]); if (isNew) { if (size == MAX_TABLE_LEN - 1) throw new IllegalStateException("Maximum size reached"); index = ~index; if (table[index] != TOMBSTONE) { filled++; } } table[index] = translator.serialize(key, value); if (isNew) { incrementSize(); if (filled == MAX_TABLE_LEN) resize(table.length); } return result; } CompactHashMap(CompactMapTranslator<K,V> trans); void clear(); int size(); @SuppressWarnings("unchecked") boolean containsKey(Object key); V get(Object key); V put(K key, V value); V remove(Object key); Set<Map.Entry<K,V>> entrySet();  }