/** {@inheritDoc} */ @SuppressWarnings({"RedundantCast"}) public boolean increment( K key ) { //noinspection RedundantCast return adjustValue( key, (short)1 ); }
/** {@inheritDoc} */ public boolean containsKey( Object key ) { return contains( key ); }
@SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
/** {@inheritDoc} */ public short adjustOrPutValue( final K key, final short adjust_amount, final short put_amount ) { int index = insertKey( key ); final boolean isNewMapping; final short newValue; if ( index < 0 ) { index = -index -1; newValue = ( _values[index] += adjust_amount ); isNewMapping = false; } else { newValue = ( _values[index] = put_amount ); isNewMapping = true; } //noinspection unchecked if ( isNewMapping ) { postInsertHook( consumeFreeSlot ); } return newValue; }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SUPER super.readExternal( in ); // NO_ENTRY_VALUE no_entry_value = in.readShort(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { //noinspection unchecked K key = ( K ) in.readObject(); short val = in.readShort(); put(key, val); } }
/** * Creates a new <code>TObjectShortHashMap</code> that contains the entries * in the map passed to it. * * @param map the <tt>TObjectShortMap</tt> to be copied. */ public TObjectShortHashMap( TObjectShortMap<? extends K> map ) { this( map.size(), 0.5f, map.getNoEntryValue() ); if ( map instanceof TObjectShortHashMap ) { TObjectShortHashMap hashmap = ( TObjectShortHashMap ) map; this._loadFactor = hashmap._loadFactor; this.no_entry_value = hashmap.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( short ) 0 ) { Arrays.fill( _values, this.no_entry_value ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } putAll( map ); }
public boolean execute(K key, short value) { put(key, value); return true; } };
/** {@inheritDoc} */ public boolean adjustValue( K key, short amount ) { int index = index(key); if ( index < 0 ) { return false; } else { _values[index] += amount; return true; } }
/** * Creates a new <code>TObjectShortHashMap</code> that contains the entries * in the map passed to it. * * @param map the <tt>TObjectShortMap</tt> to be copied. */ public TObjectShortHashMap( TObjectShortMap<? extends K> map ) { this( map.size(), 0.5f, map.getNoEntryValue() ); if ( map instanceof TObjectShortHashMap ) { TObjectShortHashMap hashmap = ( TObjectShortHashMap ) map; this._loadFactor = Math.abs( hashmap._loadFactor ); this.no_entry_value = hashmap.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( short ) 0 ) { Arrays.fill( _values, this.no_entry_value ); } setUp( saturatedCast( fastCeil( DEFAULT_CAPACITY / (double) _loadFactor ) ) ); } putAll( map ); }
/** * Executes <tt>procedure</tt> for each key in the map. * * @param procedure a <code>TObjectProcedure</code> value * @return false if the loop over the keys terminated because * the procedure returned false for some key. */ public boolean forEachKey( TObjectProcedure<? super K> procedure ) { return forEach( procedure ); }
private short doPut( short value, int index ) { short previous = no_entry_value; boolean isNewMapping = true; if ( index < 0 ) { index = -index -1; previous = _values[index]; isNewMapping = false; } //noinspection unchecked _values[index] = value; if ( isNewMapping ) { postInsertHook( consumeFreeSlot ); } return previous; }
/** {@inheritDoc} */ public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry( new TObjectShortProcedure<K>() { private boolean first = true; public boolean execute( K key, short value ) { if ( first ) first = false; else buf.append( "," ); buf.append( key ).append( "=" ).append( value ); return true; } }); buf.append( "}" ); return buf.toString(); } } // TObjectShortHashMap
/** {@inheritDoc} */ public short put( K key, short value ) { int index = insertionIndex( key ); return doPut( key, value, index ); }
/** {@inheritDoc} */ public short adjustOrPutValue( final K key, final short adjust_amount, final short put_amount ) { int index = insertionIndex( key ); final boolean isNewMapping; final short newValue; if ( index < 0 ) { index = -index -1; newValue = ( _values[index] += adjust_amount ); isNewMapping = false; } else { newValue = ( _values[index] = put_amount ); isNewMapping = true; } //noinspection unchecked K oldKey = ( K ) _set[index]; _set[index] = key; if ( isNewMapping ) { postInsertHook( oldKey == FREE ); } return newValue; }
@Override @SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SUPER super.readExternal( in ); // NO_ENTRY_VALUE no_entry_value = in.readShort(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { //noinspection unchecked K key = ( K ) in.readObject(); short val = in.readShort(); put(key, val); } }
/** * Creates a new <code>TObjectShortHashMap</code> that contains the entries * in the map passed to it. * * @param map the <tt>TObjectShortMap</tt> to be copied. */ public TObjectShortHashMap( TObjectShortMap<? extends K> map ) { this( map.size(), 0.5f, map.getNoEntryValue() ); if ( map instanceof TObjectShortHashMap ) { TObjectShortHashMap hashmap = ( TObjectShortHashMap ) map; this._loadFactor = hashmap._loadFactor; this.no_entry_value = hashmap.no_entry_value; //noinspection RedundantCast if ( this.no_entry_value != ( short ) 0 ) { Arrays.fill( _values, this.no_entry_value ); } setUp( (int) Math.ceil( DEFAULT_CAPACITY / _loadFactor ) ); } putAll( map ); }