/** Removes all of the mappings from this map. */ public void clear() { // Smack a new empty table down CHM newchm = new CHM(this,new ConcurrentAutoTable(),MIN_SIZE_LOG); while( !CAS(_chm_offset,_chm,newchm) ) // Spin until the clear works ; CAS(_val_1_offset,_val_1,TOMBSTONE); }
/** Empty the bitvector. */ public void clear ( ) { NBSI cleared = new NBSI(63, new ConcurrentAutoTable(), this); // An empty initial NBSI while( !CAS_nbsi( _nbsi, cleared ) ) // Spin until clear works ; }
private int nextInstanceCounter(String algoName, NonBlockingHashMap<String, Integer> instanceCounters) { synchronized (instanceCounters) { int instanceNum = 1; if (instanceCounters.containsKey(algoName)) instanceNum = instanceCounters.get(algoName) + 1; instanceCounters.put(algoName, instanceNum); return instanceNum; } }
/** Create a new empty bit-vector */ public NonBlockingSetInt( ) { _nbsi = new NBSI(63, new ConcurrentAutoTable(), this); // The initial 1-word set }
private static final void print2_impl(final int i, final long K, final Object V) { if( V != null && Prime.unbox(V) != TOMBSTONE ) print_impl(i,K,V); }
/** Get and clear the current count of reprobes. Reprobes happen on key * collisions, and a high reprobe rate may indicate a poor hash function or * weaknesses in the table resizing function. * @return the count of reprobes since the last call to {@link #reprobes} * or since the table was created. */ public long reprobes() { long r = _reprobes.get(); _reprobes = new ConcurrentAutoTable(); return r; }
/** * 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. */
/** * Current count of elements in the set. Due to concurrent racing updates, * the size is only ever approximate. Updates due to the calling thread are * immediately visible to calling thread. * @return count of elements. */ public int size ( ) { return _nbsi.size( ); } /** Approx largest element in set; at least as big (but max might be smaller). */
/** Create a new NonBlockingHashMap with initial room for the given number of * elements, thus avoiding internal resizing operations to reach an * appropriate size. Large numbers here when used with a small count of * elements will sacrifice space for a small amount of time gained. The * initial size will be rounded up internally to the next larger power of 2. */ public NonBlockingHashMap( final int initial_sz ) { initialize(initial_sz); } private final void initialize( int initial_sz ) {
/** 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 key or value is null */ public boolean replace ( TypeK key, TypeV oldValue, TypeV newValue ) { return putIfMatch( key, newValue, oldValue ) == oldValue; }
/** Returns the Key to which the specified key is mapped, or {@code null} * if this map contains no mapping for the key. * @throws NullPointerException if the specified key is null */ // Never returns a Prime nor a Tombstone. public TypeK getk( TypeK key ) { return (TypeK)getk_impl(this,_kvs,key); }
/** Tests if the key in the table using the <tt>equals</tt> method. * @return <tt>true</tt> if the key is in the table using the <tt>equals</tt> method * @throws NullPointerException if the specified key is null */ @Override public boolean containsKey( Object key ) { return get(key) != null; }
/** Legacy method testing if some key maps into the specified value in this * table. This method is identical in functionality to {@link * #containsValue}, and exists solely to ensure full compatibility with * class {@link java.util.Hashtable}, which supported this method prior to * introduction of the Java Collections framework. * @param val a value to search for * @return <tt>true</tt> if this map maps one or more keys to the specified value * @throws NullPointerException if the specified value is null */ public boolean contains ( Object val ) { return containsValue(val); }
/** Create a new NonBlockingHashMapLong, setting both the initial size and * the space-for-speed tradeoff. {@code true} optimizes for space and is * the default. {@code false} optimizes for speed and doubles space costs * for roughly a 10% speed improvement. */ public NonBlockingHashMapLong( final int initial_sz, final boolean opt_for_space ) { _opt_for_space = opt_for_space; initialize(initial_sz); } private final void initialize( final int initial_sz ) {
/** Legacy method testing if some key maps into the specified value in this * table. This method is identical in functionality to {@link * #containsValue}, and exists solely to ensure full compatibility with * class {@link java.util.Hashtable}, which supported this method prior to * introduction of the Java Collections framework. * @param val a value to search for * @return <tt>true</tt> if this map maps one or more keys to the specified value * @throws NullPointerException if the specified value is null */ public boolean contains ( Object val ) { return containsValue(val); }
/** * A cheaper {@link #get}. Updated only once/millisecond, but as fast as a * simple load instruction when not updating. */ public long estimate_get( ) { return _cat.estimate_sum(0); }
public long sum( long mask ) { long sum = _next == null ? 0 : _next.sum(mask); // Recursively get cached sum final long[] t = _t; for( int i=0; i<t.length; i++ ) sum += t[i]&(~mask); return sum; }