public String toString() { final StringBuilder buf = new StringBuilder("{"); forEachEntry(new TByteObjectProcedure<V>() { private boolean first = true; public boolean execute(byte key, Object value) { if ( first ) first = false; else buf.append( "," ); buf.append(key); buf.append("="); buf.append(value); return true; } }); buf.append("}"); return buf.toString(); } } // TByteObjectHashMap
/** {@inheritDoc} */ public boolean equals( Object other ) { if ( ! ( other instanceof TByteObjectMap ) ) { return false; } TByteObjectMap that = ( TByteObjectMap ) other; if ( that.size() != this.size() ) { return false; } try { TByteObjectIterator iter = this.iterator(); while ( iter.hasNext() ) { iter.advance(); byte key = iter.key(); Object value = iter.value(); if ( value == null ) { if ( !( that.get( key ) == null && that.containsKey( key ) ) ) { return false; } } else { if ( !value.equals( that.get( key ) ) ) { return false; } } } } catch ( ClassCastException ex ) { // unused. } return true; }
@SuppressWarnings({"unchecked"}) public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION in.readByte(); // SUPER super.readExternal( in ); // NO_ENTRY_KEY no_entry_key = in.readByte(); // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while (size-- > 0) { byte key = in.readByte(); V val = (V) in.readObject(); put(key, val); } }
@SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
public boolean execute( byte key, V value) { put( key, value ); return true; } };
@Override public IndexGeneratorImpl clone() { final TByteObjectHashMap<IntGenerator> newMap = new TByteObjectHashMap<>(generators.size()); generators.forEachEntry( new TByteObjectProcedure<IntGenerator>() { @Override public boolean execute(byte a, IntGenerator b) { newMap.put(a, b.clone()); return true; } } ); /*for (Map.Entry<Byte, IntGenerator> entry : generators.entrySet()) newMap.put(entry.getKey(), entry.getValue().clone()); */ return new IndexGeneratorImpl(newMap); } }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) public Object[] values() { Object[] vals = new Object[size()]; V[] 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 containsKey( byte key ) { return contains( key ); }
/** * Creates a new <code>TByteObjectHashMap</code> that contains the entries * in the map passed to it. * * @param map the <tt>TByteObjectMap</tt> to be copied. */ public TByteObjectHashMap( TByteObjectMap<? extends V> map ) { this( map.size(), 0.5f, map.getNoEntryKey() ); putAll( map ); }
/** {@inheritDoc} */ public V get( byte key ) { int index = index( key ); return index < 0 ? null : _values[index]; }
/** {@inheritDoc} */ public boolean forEachKey( TByteProcedure procedure ) { return forEach( procedure ); }
@SuppressWarnings({"unchecked"}) private V doPut( V value, int index ) { V previous = null; boolean isNewMapping = true; if ( index < 0 ) { index = -index -1; previous = _values[index]; isNewMapping = false; } _values[index] = value; if (isNewMapping) { postInsertHook( consumeFreeSlot ); } return previous; }
Tensor c; DummiesContainer dummies[] = new DummiesContainer[t.size()]; TByteObjectHashMap<MaxType> maxTypeCounts = new TByteObjectHashMap<>(); for (int i = oldData.length - 1; i >= 0; --i) { c = optimizeDummies(oldData[i]); for (MaxType type : maxTypeCounts.valueCollection()) totalDummiesCount += type.count; for (TByteObjectIterator<MaxType> maxTypeIterator = maxTypeCounts.iterator(); maxTypeIterator.hasNext(); ) { maxTypeIterator.advance(); MaxType maxType = maxTypeIterator.value();
/** {@inheritDoc} */ public V put( byte key, V value ) { int index = insertionIndex( key ); return doPut( key, value, index ); }
@Override @SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
/** {@inheritDoc} */ public void putAll( Map<? extends Byte, ? extends V> map ) { Set<? extends Map.Entry<? extends Byte,? extends V>> set = map.entrySet(); for ( Map.Entry<? extends Byte,? extends V> entry : set ) { put( entry.getKey(), entry.getValue() ); } }
/** {@inheritDoc} */ @SuppressWarnings({"unchecked"}) public byte[] keys() { byte[] keys = new byte[size()]; byte[] k = _set; byte[] states = _states; for ( int i = k.length, j = 0; i-- > 0; ) { if ( states[i] == FULL ) { keys[j++] = k[i]; } } return keys; }