public void print() { long[] t = _t; System.out.print("["+t[0]); for( int i=1; i<t.length; i++ ) System.out.print(","+t[i]); System.out.print("]"); if( _next != null ) _next.print(); } }
private static boolean CAS( long[] A, int idx, long old, long nnn ) { return UNSAFE.compareAndSwapLong( A, rawIndex(A,idx), old, nnn ); }
public String toString( ) { return Long.toString(sum()); }
private long add_if( long x ) { return _cat.add_if(x,hash(),this); }
public String toString( ) { return Long.toString(sum()); }
private static boolean CAS( long[] A, int idx, long old, long nnn ) { return UNSAFE.compareAndSwapLong( A, rawIndex(A,idx), old, nnn ); }
/** Same as {@link #get}, included for completeness. */ public long longValue() { return _cat.sum(); }
/** Same as {@link #get}, included for completeness. */ public int intValue() { return (int)_cat.sum(); } /** Same as {@link #get}, included for completeness. */
/** * Return the counter's {@code long} value converted to a string. */ public String toString() { return _cat.toString(); }
public long estimate_sum( ) { // For short tables, just do the work if( _t.length <= 64 ) return sum(); // For bigger tables, periodically freshen a cached value long millis = System.currentTimeMillis(); if( _fuzzy_time != millis ) { // Time marches on? _fuzzy_sum_cache = sum(); // Get sum the hard way _fuzzy_time = millis; // Indicate freshness of cached value } return _fuzzy_sum_cache; // Return cached sum }
/** * 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(); }
/** * A more verbose print than {@link #toString}, showing internal structure. * Useful for debugging. */ public void print() { _cat.print(); }
/** 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*/} }
public long sum( ) { long sum = _next == null ? 0 : _next.sum(); // Recursively get cached sum final long[] t = _t; for( long cnt : t ) sum += cnt; return sum; }
/** * 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(); } /** Same as {@link #get}, included for completeness. */
public void print() { long[] t = _t; System.out.print("["+t[0]); for( int i=1; i<t.length; i++ ) System.out.print(","+t[i]); System.out.print("]"); if( _next != null ) _next.print(); } }
private long add_if( long x ) { return _cat.add_if(x,hash(),this); }
/** Same as {@link #get}, included for completeness. */ public long longValue() { return _cat.sum(); }