/** {@inheritDoc} */ public boolean containsAll( int[] array ) { for ( int element : array ) { if ( ! TIntShortHashMap.this.contains( element ) ) { return false; } } return true; }
/** {@inheritDoc} */ public int[] toArray( int[] dest ) { return TIntShortHashMap.this.keys( dest ); }
/** {@inheritDoc} */ public void putAll( Map<? extends Integer, ? extends Short> map ) { ensureCapacity( map.size() ); // could optimize this for cases when map instanceof THashMap for ( Map.Entry<? extends Integer, ? extends Short> entry : map.entrySet() ) { this.put( entry.getKey().intValue(), entry.getValue().shortValue() ); } }
/** {@inheritDoc} */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SUPER super.readExternal( in ); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { int key = in.readInt(); short val = in.readShort(); put(key, val); } } } // TIntShortHashMap
/** {@inheritDoc} */ public short[] toArray( short[] dest ) { return TIntShortHashMap.this.values( dest ); }
/** {@inheritDoc} */ public short[] values() { short[] vals = new short[size()]; short[] v = _values; byte[] states = _states; for ( int i = v.length, j = 0; i-- > 0; ) { if ( states[i] == FULL ) { vals[j++] = v[i]; } } return vals; }
/** {@inheritDoc} */ public boolean containsAll( short[] array ) { for ( short element : array ) { if ( ! TIntShortHashMap.this.containsValue( element ) ) { return false; } } return true; }
/** {@inheritDoc} */ public boolean containsAll( Collection<?> collection ) { for ( Object element : collection ) { if ( element instanceof Integer ) { int ele = ( ( Integer ) element ).intValue(); if ( ! TIntShortHashMap.this.containsKey( ele ) ) { return false; } } else { return false; } } return true; }
/** {@inheritDoc} */ public void clear() { TIntShortHashMap.this.clear(); }
@Override public SparseShortArray reverse() { //TODO: this could be more efficient and avoid the copy TIntShortHashMap tmp = new TIntShortHashMap(data.size()); for (Entry e : entries()) tmp.put(length - e.index, e.value); this.data = tmp; return this; } }
/** {@inheritDoc} */ @Override public boolean equals( Object other ) { if ( ! ( other instanceof TIntShortMap ) ) { return false; } TIntShortMap that = ( TIntShortMap ) other; if ( that.size() != this.size() ) { return false; } short[] values = _values; byte[] states = _states; short this_no_entry_value = getNoEntryValue(); short that_no_entry_value = that.getNoEntryValue(); for ( int i = values.length; i-- > 0; ) { if ( states[i] == FULL ) { int key = _set[i]; short that_value = that.get( key ); short this_value = values[i]; if ( ( this_value != that_value ) && ( this_value != this_no_entry_value ) && ( that_value != that_no_entry_value ) ) { return false; } } } return true; }
/** {@inheritDoc} */ public boolean increment( int key ) { return adjustValue( key, ( short ) 1 ); }
/** {@inheritDoc} */ public short put( int key, short value ) { int index = insertionIndex( key ); return doPut( key, value, index ); }
/** * Creates a new <code>TIntShortHashMap</code> instance containing * all of the entries in the map passed in. * * @param keys a <tt>int</tt> array containing the keys for the matching values. * @param values a <tt>short</tt> array containing the values. */ public TIntShortHashMap( int[] keys, short[] values ) { super( Math.max( keys.length, values.length ) ); int size = Math.min( keys.length, values.length ); for ( int i = 0; i < size; i++ ) { this.put( keys[i], values[i] ); } }
/** {@inheritDoc} */ public short[] toArray() { return TIntShortHashMap.this.values(); }
/** {@inheritDoc} */ public int[] keys() { int[] keys = new int[size()]; int[] k = _set; byte[] states = _states; for ( int i = k.length, j = 0; i-- > 0; ) { if ( states[i] == FULL ) { keys[j++] = k[i]; } } return keys; }
/** {@inheritDoc} */ public boolean contains( short entry ) { return TIntShortHashMap.this.containsValue( entry ); }
/** {@inheritDoc} */ public boolean containsAll( TIntCollection collection ) { TIntIterator iter = collection.iterator(); while ( iter.hasNext() ) { if ( ! TIntShortHashMap.this.containsKey( iter.next() ) ) { return false; } } return true; }