/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ public V put( K key, V value ) { int index = insertKey( key ); return doPut( value, index ); }
/** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ public V putIfAbsent( K key, V value ) { int index = insertKey( key ); if ( index < 0 ) { return _values[-index - 1]; } return doPut(value, index ); }
/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ @SuppressWarnings({"unchecked"}) protected void rehash( int newCapacity ) { int oldCapacity = _set.length; int oldSize = size(); Object oldKeys[] = _set; V oldVals[] = _values; _set = new Object[ newCapacity ]; Arrays.fill( _set, FREE ); _values = ( V[] ) new Object[ newCapacity ]; // Process entries from the old array, skipping free and removed slots. Put the // values into the appropriate place in the new array. for ( int i = oldCapacity; i-- > 0; ) { Object o = oldKeys[ i ]; if ( o == FREE || o == REMOVED ) continue; int index = insertKey( ( K ) o ); if ( index < 0 ) { throwObjectContractViolation( _set[ ( -index - 1 ) ], o, size(), oldSize, oldKeys); } _values[ index ] = oldVals[ i ]; } }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ public V put( K key, V value ) { int index = insertKey( key ); return doPut( value, index ); }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ public V put( K key, V value ) { int index = insertKey( key ); return doPut( value, index ); }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ @Override public V put( K key, V value ) { int index = insertKey( key ); return doPut( value, index ); }
/** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ public V putIfAbsent( K key, V value ) { int index = insertKey( key ); if ( index < 0 ) { return _values[-index - 1]; } return doPut(value, index ); }
/** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ @Override public V putIfAbsent( K key, V value ) { int index = insertKey( key ); if ( index < 0 ) { return _values[-index - 1]; } return doPut(value, index ); }
/** * Inserts a key/value pair into the map if the specified key is not already * associated with a value. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or {@code null} if none was found. */ public V putIfAbsent( K key, V value ) { int index = insertKey( key ); if ( index < 0 ) { return _values[-index - 1]; } return doPut(value, index ); }
/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ @SuppressWarnings({"unchecked"}) protected void rehash( int newCapacity ) { int oldCapacity = _set.length; int oldSize = size(); Object oldKeys[] = _set; V oldVals[] = _values; _set = new Object[ newCapacity ]; Arrays.fill( _set, FREE ); _values = ( V[] ) new Object[ newCapacity ]; // Process entries from the old array, skipping free and removed slots. Put the // values into the appropriate place in the new array. for ( int i = oldCapacity; i-- > 0; ) { Object o = oldKeys[ i ]; if ( o == FREE || o == REMOVED ) continue; int index = insertKey( ( K ) o ); if ( index < 0 ) { throwObjectContractViolation( _set[ ( -index - 1 ) ], o, size(), oldSize, oldKeys); } _values[ index ] = oldVals[ i ]; } }
/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ @SuppressWarnings({"unchecked"}) protected void rehash( int newCapacity ) { int oldCapacity = _set.length; int oldSize = size(); Object oldKeys[] = _set; V oldVals[] = _values; _set = new Object[ newCapacity ]; Arrays.fill( _set, FREE ); _values = ( V[] ) new Object[ newCapacity ]; // Process entries from the old array, skipping free and removed slots. Put the // values into the appropriate place in the new array. for ( int i = oldCapacity; i-- > 0; ) { Object o = oldKeys[ i ]; if ( o == FREE || o == REMOVED ) continue; int index = insertKey( ( K ) o ); if ( index < 0 ) { throwObjectContractViolation( _set[ ( -index - 1 ) ], o, size(), oldSize, oldKeys); } _values[ index ] = oldVals[ i ]; } }
/** * rehashes the map to the new capacity. * * @param newCapacity an <code>int</code> value */ @SuppressWarnings({"unchecked"}) @Override protected void rehash( int newCapacity ) { int oldCapacity = _set.length; int oldSize = size(); Object oldKeys[] = _set; V oldVals[] = _values; _set = new Object[ newCapacity ]; Arrays.fill( _set, FREE ); _values = ( V[] ) new Object[ newCapacity ]; // Process entries from the old array, skipping free and removed slots. Put the // values into the appropriate place in the new array. for ( int i = oldCapacity; i-- > 0; ) { Object o = oldKeys[ i ]; if ( o == FREE || o == REMOVED ) continue; int index = insertKey( ( K ) o ); if ( index < 0 ) { throwObjectContractViolation( _set[ ( -index - 1 ) ], o, size(), oldSize, oldKeys); } _values[ index ] = oldVals[ i ]; } }