/** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ @SuppressWarnings({"unchecked", "SimplifiableIfStatement"}) public boolean equals( Object other ) { if ( !( other instanceof Map ) ) { return false; } Map<K, V> that = (Map<K, V>) other; if ( that.size() != this.size() ) { return false; } return forEachEntry( new EqProcedure<K, V>( that ) ); }
/** * copies the key/value mappings in <tt>map</tt> into this map. * * @param map a <code>Map</code> value */ public void putAll( Map<? extends K, ? extends V> map ) { ensureCapacity( map.size() ); // could optimize this for cases when map instanceof TCustomHashMap for ( Map.Entry<? extends K, ? extends V> e : map.entrySet() ) { put( e.getKey(), e.getValue() ); } }
/** * Creates a new <code>TCustomHashMap</code> instance which contains the * key/value pairs in <tt>map</tt>. * * @param map a <code>Map</code> value */ public TCustomHashMap( HashingStrategy<? super K> strategy, TCustomHashMap<? extends K, ? extends V> map ) { this( strategy, map.size() ); putAll( map ); }
/** * 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 ); }
@SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }
/** * Retains only those entries in the map for which the procedure * returns a true value. * * @param procedure determines which entries to keep * @return true if the map was modified. */ @SuppressWarnings({"unchecked"}) public boolean retainEntries( TObjectObjectProcedure<? super K, ? super V> procedure ) { boolean modified = false; Object[] keys = _set; V[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for ( int i = keys.length; i-- > 0; ) { if ( keys[i] != FREE && keys[i] != REMOVED && !procedure.execute( (K) keys[i], values[i] ) ) { removeAt( i ); modified = true; } } } finally { reenableAutoCompaction( true ); } return modified; }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION byte version = in.readByte(); // NOTE: super was not written in version 0 if ( version != 0 ) { super.readExternal( in ); } // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while ( size-- > 0 ) { //noinspection unchecked K key = (K) in.readObject(); //noinspection unchecked V val = (V) in.readObject(); put( key, val ); } } } // TCustomHashMap
TCustomHashMap<long[], List<ArrayModifiableDBIDs>> newClustersMap = new TCustomHashMap<>(BitsUtil.TROVE_HASH_STRATEGY); Pair<long[], ArrayModifiableDBIDs> noise = new Pair<>(BitsUtil.zero(dimensionality), DBIDUtil.newArray()); for(long[] pv : clustersMap.keySet()) { List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv); for(ArrayModifiableDBIDs c : parallelClusters) { noise.second.addDBIDs(c); List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv); List<ArrayModifiableDBIDs> newParallelClusters = new ArrayList<>(parallelClusters.size()); for(ArrayModifiableDBIDs c : parallelClusters) { newClustersMap.put(pv, newParallelClusters); clustersMap.clear(); clustersMap.putAll(newClustersMap); clustersMap.put(noise.first, noiseList);
public String toString() { Iterator<E> i = iterator(); if ( !i.hasNext() ) return "{}"; StringBuilder sb = new StringBuilder(); sb.append( '{' ); for (; ; ) { E e = i.next(); sb.append( e == this ? "(this Collection)" : e ); if ( !i.hasNext() ) return sb.append( '}' ).toString(); sb.append( ", " ); } } }
/** * checks for the present of <tt>key</tt> in the keys of the map. * * @param key an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean containsKey( Object key ) { return contains( key ); }
/** * Creates a new <code>TCustomHashMap</code> instance which contains the * key/value pairs in <tt>map</tt>. * * @param map a <code>Map</code> value */ public TCustomHashMap( HashingStrategy<? super K> strategy, Map<? extends K, ? extends V> map ) { this( strategy, map.size() ); putAll( map ); }
TCustomHashMap<long[], List<ArrayModifiableDBIDs>> clustersMap = new TCustomHashMap<>(BitsUtil.TROVE_HASH_STRATEGY); List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(preferenceVector); if(parallelClusters == null) { parallelClusters = new ArrayList<>(); clustersMap.put(preferenceVector, parallelClusters); int dim = RelationUtil.dimensionality(relation); StringBuilder msg = new StringBuilder("Step 0"); for(Map.Entry<long[], List<ArrayModifiableDBIDs>> clusterList : clustersMap.entrySet()) { for(ArrayModifiableDBIDs c : clusterList.getValue()) { msg.append('\n').append(BitsUtil.toStringLow(clusterList.getKey(), dim)).append(" ids ").append(c.size()); for(long[] pv : clustersMap.keySet()) { List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv); for(ArrayModifiableDBIDs cluster : parallelClusters) { if(cluster.isEmpty()) {
/** * 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 ); }
/** * retrieves the value for <tt>key</tt> * * @param key an <code>Object</code> value * @return the value of <tt>key</tt> or null if no such mapping exists. */ @SuppressWarnings({"unchecked"}) public V get( Object key ) { int index = index( key ); if ( index < 0 || ! strategy.equals( ( K ) _set[index], ( K ) key ) ) { return null; } return _values[index]; }
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; }
/** * 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 = insertionIndex( key ); return doPut( key, value, index ); }
/** * Retains only those entries in the map for which the procedure * returns a true value. * * @param procedure determines which entries to keep * @return true if the map was modified. */ @SuppressWarnings({"unchecked"}) public boolean retainEntries( TObjectObjectProcedure<? super K, ? super V> procedure ) { boolean modified = false; Object[] keys = _set; V[] values = _values; // Temporarily disable compaction. This is a fix for bug #1738760 tempDisableAutoCompaction(); try { for ( int i = keys.length; i-- > 0; ) { if ( keys[i] != FREE && keys[i] != REMOVED && !procedure.execute( (K) keys[i], values[i] ) ) { removeAt( i ); modified = true; } } } finally { reenableAutoCompaction( true ); } return modified; }
/** * 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 ); }
public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // VERSION byte version = in.readByte(); // NOTE: super was not written in version 0 if ( version != 0 ) { super.readExternal( in ); } // NUMBER OF ENTRIES int size = in.readInt(); setUp( size ); // ENTRIES while ( size-- > 0 ) { //noinspection unchecked K key = (K) in.readObject(); //noinspection unchecked V val = (V) in.readObject(); put( key, val ); } } } // TCustomHashMap
@SuppressWarnings({"unchecked"}) public boolean remove( Object o ) { return removeElement( (E) o ); }