/** * Copies all of the mappings from the specified map to this one. * These mappings replace any mappings that this map had for any of the * keys currently in the specified Map. * * @param t Mappings to be stored in this map. */ @Override public void putAll(Map t) { for (Object o : t.entrySet()) { Map.Entry e = (Map.Entry) o; put(e.getKey(), e.getValue()); } }
@Override public void clear() { IntHashMap.this.clear(); } };
@Override public boolean contains(Object o) { return containsKey(o); }
@Test void testIntHashMap() { IntHashMap ihm = new IntHashMap(); assertTrue(ihm.isEmpty()); ihm.put(i, new Integer(i)); assertEquals(10000, ihm.size()); assertFalse(ihm.isEmpty()); assertEquals(i, ((Integer) ihm.get(i)).intValue()); assertTrue(ihm.containsKey(1)); assertTrue(ihm.containsValue(Integer.valueOf(173))); IntHashMap ihm2 = ihm.clone(); assertEquals(10000, ihm2.size()); ihm.remove(1); assertEquals(9999, ihm.size()); assertEquals(10000, ihm2.size()); ihm.clear(); assertTrue(ihm.isEmpty()); ihm.put(Integer.valueOf("123"), "Xxx");
@Override public boolean remove(Object o) { return IntHashMap.this.remove(o) != null; }
@Override public boolean contains(Object o) { return containsValue(o); }
/** * Returns the value to which this map maps the specified key. Returns * <code>null</code> if the map contains no mapping for this key. A return * value of <code>null</code> does not <i>necessarily</i> indicate that the * map contains no mapping for the key; it's also possible that the map * explicitly maps the key to <code>null</code>. The <code>containsKey</code> * operation may be used to distinguish these two cases. * * @param key key whose associated value is to be returned. * @return the value to which this map maps the specified key. */ @Override public Object get(Object key) { if (key instanceof Number) { return get(((Number) key).intValue()); } return null; }
private static Hasher32 checkSeed(List<byte[]> values, int seed) { IntHashMap hashCodes = new IntHashMap(); Hasher32 hasher = new Hasher32(seed); for (byte[] object : values) { int hashCode = hasher.hashUnsafeWords(object); byte[] preObject = (byte[]) hashCodes.put(hashCode, object); if (preObject != null) { return null; } } return hasher; } }
/** * Constructs a new map with the same mappings as the given map. The * map is created with a capacity of twice the number of mappings in * the given map or 11 (whichever is greater), and a default load factor, * which is 0.75. */ public IntHashMap(Map t) { this(Math.max(2 * t.size(), 11), 0.75f); putAll(t); }
if (count >= threshold) { rehash();
@Override public boolean remove(final Object o) { return IntHashMap.this.remove(o) != null; }
@Override public boolean contains(final Object o) { return containsValue(o); }
/** * Returns the value to which this map maps the specified key. Returns * <code>null</code> if the map contains no mapping for this key. A return * value of <code>null</code> does not <i>necessarily</i> indicate that the * map contains no mapping for the key; it's also possible that the map * explicitly maps the key to <code>null</code>. The <code>containsKey</code> * operation may be used to distinguish these two cases. * * @param key key whose associated value is to be returned. * @return the value to which this map maps the specified key. */ @Override public Object get(final Object key) { if (key instanceof Number) { return get(((Number) key).intValue()); } return null; }
/** * Constructs a new map with the same mappings as the given map. The * map is created with a capacity of twice the number of mappings in * the given map or 11 (whichever is greater), and a default load factor, * which is 0.75. */ public IntHashMap(final Map t) { this(Math.max(2 * t.size(), 11), 0.75f); putAll(t); }
if (count >= threshold) { rehash();
@Override public void clear() { IntHashMap.this.clear(); } };
/** * Associates the specified value with the specified key in this map. If the * map previously contained a mapping for this key, the old value is * replaced. * * @param key key with which the specified value is to be associated. * @param value value to be associated with the specified key. * @return previous value associated with specified key, or <code>null</code> if * there was no mapping for key. A <code>null</code> return can also indicate * that the IntHashMap previously associated <code>null</code> with the * specified key. */ @Override public Object put(Object key, Object value) { if (key instanceof Number) { return put(((Number) key).intValue(), value); } throw new UnsupportedOperationException("IntHashMap key must be a Number"); }
@Override public boolean contains(final Object o) { return containsKey(o); }
/** * Removes the mapping for this key from this map if present. * * @param key key whose mapping is to be removed from the map. * @return previous value associated with specified key, or <code>null</code> if * there was no mapping for key. A <code>null</code> return can also indicate * that the map previously associated <code>null</code> with the specified * key. */ @Override public Object remove(Object key) { if (key instanceof Number) { return remove(((Number) key).intValue()); } return null; }
@Override public boolean contains(final Object o) { return containsValue(o); }