CHM( final NonBlockingHashMapLong nbhml, ConcurrentAutoTable size, final int logsize ) { _nbhml = nbhml; _size = size; _slots= new ConcurrentAutoTable(); _keys = new long [1<<logsize]; _vals = new Object[1<<logsize]; }
@Override public void inc() { counter.add(1); }
/** 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; }
@Override public long get() { return counter.get(); } }
private final boolean tableFull( int reprobe_cnt, int len ) { return // Do the cheap check first: we allow some number of reprobes always reprobe_cnt >= REPROBE_LIMIT && (reprobe_cnt >= reprobe_limit(len) || // More expensive check: see if the table is > 1/2 full. _slots.estimate_get() >= (len>>1)); }
/** * 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( x); } /** {@link #add} with -1 */
/** Atomically set the sum of the striped counters to specified value. * Rather more expensive than a simple store, in order to remain atomic. */ public void set( long x ) { CAT newcat = new CAT(null,4,x); // Spin until CAS works while( !CAS_cat(_cat,newcat) ) {/*empty*/} }
private long add_if( long x ) { return _cat.add_if(x,hash(),this); }
public int internal_size() { return _tab.internal_size(); } }
public void print() { _tab.print(); } public int internal_size() { return _tab.internal_size(); }
public long get(){ return _tab.get(); } public void add( long x ) { _tab.add(x); }
private final boolean tableFull( int reprobe_cnt, int len ) { return // Do the cheap check first: we allow some number of reprobes always reprobe_cnt >= REPROBE_LIMIT && // More expensive check: see if the table is > 1/4 full. _slots.estimate_get() >= reprobe_limit(len); }
/** {@link #add} with -1 */ public void decrement() { add_if(-1L); } /** {@link #add} with +1 */
/** Atomically set the sum of the striped counters to specified value. * Rather more expensive than a simple store, in order to remain atomic. */ public void set( long x ) { CAT newcat = new CAT(null,4,x); // Spin until CAS works while( !CAS_cat(_cat,newcat) ) {/*empty*/} }
private long add_if( long x ) { return _cat.add_if(x,hash(),this); }
CHM( ConcurrentAutoTable size ) { _size = size; _slots= new ConcurrentAutoTable(); }
/** 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; }
public int size () { return (int)_size.get(); }
public void add( long x ) { _tab.add(x); } public void print() { _tab.print(); }
private final boolean tableFull( int reprobe_cnt, int len ) { return // Do the cheap check first: we allow some number of reprobes always reprobe_cnt >= REPROBE_LIMIT && (reprobe_cnt >= reprobe_limit(len) || // More expensive check: see if the table is > 1/2 full. _slots.estimate_get() >= (len>>1)); }