/** {@inheritDoc} */ public boolean containsAll( int[] array ) { for ( int element : array ) { if ( ! TIntByteHashMap.this.contains( element ) ) { return false; } } return true; }
/** {@inheritDoc} */ public int[] toArray() { return TIntByteHashMap.this.keys(); }
/** {@inheritDoc} */ public void putAll( Map<? extends Integer, ? extends Byte> map ) { ensureCapacity( map.size() ); // could optimize this for cases when map instanceof THashMap for ( Map.Entry<? extends Integer, ? extends Byte> entry : map.entrySet() ) { this.put( entry.getKey().intValue(), entry.getValue().byteValue() ); } }
/** {@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(); byte val = in.readByte(); put(key, val); } } } // TIntByteHashMap
/** {@inheritDoc} */ public byte[] toArray( byte[] dest ) { return TIntByteHashMap.this.values( dest ); }
/** {@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 containsAll( byte[] array ) { for ( byte element : array ) { if ( ! TIntByteHashMap.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 ( ! TIntByteHashMap.this.containsKey( ele ) ) { return false; } } else { return false; } } return true; }
/** {@inheritDoc} */ public void clear() { TIntByteHashMap.this.clear(); }
@Override public SparseByteArray reverse() { //TODO: this could be more efficient and avoid the copy TIntByteHashMap tmp = new TIntByteHashMap(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 TIntByteMap ) ) { return false; } TIntByteMap that = ( TIntByteMap ) other; if ( that.size() != this.size() ) { return false; } byte[] values = _values; byte[] states = _states; byte this_no_entry_value = getNoEntryValue(); byte that_no_entry_value = that.getNoEntryValue(); for ( int i = values.length; i-- > 0; ) { if ( states[i] == FULL ) { int key = _set[i]; byte that_value = that.get( key ); byte 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, ( byte ) 1 ); }
/** {@inheritDoc} */ public byte put( int key, byte value ) { int index = insertionIndex( key ); return doPut( key, value, index ); }
/** * Creates a new <code>TIntByteHashMap</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>byte</tt> array containing the values. */ public TIntByteHashMap( int[] keys, byte[] 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 byte[] toArray() { return TIntByteHashMap.this.values(); }
/** {@inheritDoc} */ public byte[] values() { byte[] vals = new byte[size()]; byte[] 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 contains( byte entry ) { return TIntByteHashMap.this.containsValue( entry ); }
/** {@inheritDoc} */ public boolean containsAll( TIntCollection collection ) { TIntIterator iter = collection.iterator(); while ( iter.hasNext() ) { if ( ! TIntByteHashMap.this.containsKey( iter.next() ) ) { return false; } } return true; }