@Override public Object clone() { IntHashMap<V> newMap = new IntHashMap<>(table.length, loadFactor); for (int i = 0; i < table.length; i++) { Entry<V> entry = table[i]; while (entry != null) { newMap.put(entry.getKey(), entry.getValue()); entry = entry.next; } } return newMap; }
public void addNativeSignature(int arity, MethodType signature) { if ( arity == -1 ) varSignature = signature; else { if ( signatures == null ) signatures = new IntHashMap<>(2); signatures.put(arity, signature); } }
public static <T> ClassValue<T> newInstance(ClassValueCalculator<T> calculator) { if ( CLASS_VALUE ) return newJava7Instance(calculator); return new MapBasedClassValue<>(calculator); }
private final CHM copy_slot_and_check( int idx, Object should_help ) { // We're only here because the caller saw a Prime, which implies a // table-copy is in progress. assert _newchm != null; if( copy_slot(idx) ) // Copy the desired slot copy_check_and_promote(1); // Record the slot copied // Generically help along any copy (except if called recursively from a helper) if( should_help != null ) _nbhml.help_copy(); return _newchm; }
/** Maps the specified key to the specified value in the table. The value * cannot be null. <p> The value can be retrieved by calling {@link #get} * with a key that is equal to the original key. * @param key key with which the specified value is to be associated * @param val value to be associated with the specified key * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt> * @throws NullPointerException if the specified value is null */ public TypeV put ( long key, TypeV val ) { return putIfMatch( key, val,NO_MATCH_OLD);}
CHM( final NonBlockingHashMapLong nbhml, Counter size, final int logsize ) { _nbhml = nbhml; _size = size; _slots= new Counter(); _keys = new long [1<<logsize]; _vals = new Object[1<<logsize]; }
/** * Add the given value to current counter value. Concurrent updates will * not be lost, but addAndGet or getAndAdd are not implemented because the * total counter value (i.e., {@link #get}) is not atomically updated. * Updates are striped across an array of counters to avoid cache contention * and has been tested with performance scaling linearly up to 768 CPUs. */ public void add( long x ) { add_if_mask( x,0); } /** {@link #add} with -1 */
/** * Current value of the counter. Since other threads are updating furiously * the value is only approximate, but it includes all counts made by the * current thread. Requires a pass over the internally striped counters. */ public long get() { return _cat.sum(0); } /** Same as {@link #get}, included for completeness. */
public void all_set( long val ) { long[] t = _t; for( int i=0; i<t.length; i++ ) t[i] = val; if( _next != null ) _next.all_set(val); if( _sum_cache != Long.MIN_VALUE ) _sum_cache = Long.MIN_VALUE; // Blow out cache }
@Override public Object clone() { IntHashMap<V> newMap = new IntHashMap<>(table.length, loadFactor); for (int i = 0; i < table.length; i++) { Entry<V> entry = table[i]; while (entry != null) { newMap.put(entry.getKey(), entry.getValue()); entry = entry.next; } } return newMap; }
public static <T> ClassValue<T> newInstance(ClassValueCalculator<T> calculator) { if ( CLASS_VALUE ) return newJava7Instance(calculator); return new MapBasedClassValue<>(calculator); }
/** Removes the key (and its corresponding value) from this map. * This method does nothing if the key is not in the map. * @return the previous value associated with <tt>key</tt>, or * <tt>null</tt> if there was no mapping for <tt>key</tt>*/ public TypeV remove ( long key ) { return putIfMatch( key,TOMBSTONE,NO_MATCH_OLD);}
/** Atomically, do a {@link #put} if-and-only-if the key is not mapped. * Useful to ensure that only a single mapping for the key exists, even if * many threads are trying to create the mapping in parallel. * @return the previous value associated with the specified key, * or <tt>null</tt> if there was no mapping for the key * @throws NullPointerException if the specified is value is null */ public TypeV putIfAbsent( long key, TypeV val ) { return putIfMatch( key, val,TOMBSTONE );}
/** Atomically do a <code>put(key,newValue)</code> if-and-only-if the key is * mapped a value which is <code>equals</code> to <code>oldValue</code>. * @throws NullPointerException if the specified value is null */ public boolean replace ( long key, TypeV oldValue, TypeV newValue ) { return putIfMatch( key, newValue, oldValue ) == oldValue; }