Package edu.berkeley.cs.jqf.fuzz.util
Class FastNonCollidingCounter
java.lang.Object
edu.berkeley.cs.jqf.fuzz.util.Counter
edu.berkeley.cs.jqf.fuzz.util.FastNonCollidingCounter
An implementation of
Counter that uses an IntIntHashMap to store values
"Fast" in that it is faster than using something that involves other HashMaps,
and boxing to-and-from primitive values. There is surely a way to make it *faster*
than this too, without avoiding the collisions, but given the performance improvement
compared to the original (and collision-prone) coverage, I made the opinionated decision
to implement it this way to avoid other concerns from high collisions rates on some particular
target applications. Further experimentation with fast (non-colliding) coverage implementations
might help to determine which approach is preferable.- Author:
- Jonathan Bell
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.eclipse.collections.impl.list.mutable.primitive.IntArrayList -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the counter by setting all values to zero.voidcopyFrom(FastNonCollidingCounter counter) intget(int key) Retreives a value for a given key.intgetAtIndex(int idx) org.eclipse.collections.api.list.primitive.IntListReturns a set of indices at which the count is non-zero.org.eclipse.collections.api.list.primitive.IntListReturns a set of keys at which the count is non-zero.intReturns the number of indices with non-zero counts.org.eclipse.collections.api.list.primitive.IntListReturns a set of non-zero count values in this counter.booleanChecks if all indices have zero counts and returns a boolean as result.intincrement(int key) Increments the count at the given key.intincrement(int key, int delta) Increments the count at the given key by a given delta.protected intincrementAtIndex(int index, int delta) voidsetAtIndex(int idx, int value) intsize()Returns the size of this counter.Methods inherited from class edu.berkeley.cs.jqf.fuzz.util.Counter
increment1
-
Field Details
-
nonZeroKeys
protected org.eclipse.collections.impl.list.mutable.primitive.IntArrayList nonZeroKeys
-
-
Constructor Details
-
FastNonCollidingCounter
public FastNonCollidingCounter(int size) Creates a new counter
-
-
Method Details
-
size
public int size()Returns the size of this counter. -
clear
public void clear()Clears the counter by setting all values to zero. -
increment
public int increment(int key) Increments the count at the given key. -
increment
public int increment(int key, int delta) Increments the count at the given key by a given delta. -
incrementAtIndex
protected int incrementAtIndex(int index, int delta) - Overrides:
incrementAtIndexin classCounter
-
setAtIndex
public void setAtIndex(int idx, int value) - Overrides:
setAtIndexin classCounter
-
getAtIndex
public int getAtIndex(int idx) - Overrides:
getAtIndexin classCounter
-
getNonZeroSize
public int getNonZeroSize()Returns the number of indices with non-zero counts.- Overrides:
getNonZeroSizein classCounter- Returns:
- the number of indices with non-zero counts
-
getNonZeroKeys
public org.eclipse.collections.api.list.primitive.IntList getNonZeroKeys()Returns a set of keys at which the count is non-zero.- Returns:
- a set of keys at which the count is non-zero
-
getNonZeroIndices
public org.eclipse.collections.api.list.primitive.IntList getNonZeroIndices()Description copied from class:CounterReturns a set of indices at which the count is non-zero.Note that indices are different from keys, in that multiple keys can map to the same index due to hash collisions.
- Overrides:
getNonZeroIndicesin classCounter- Returns:
- a set of indices at which the count is non-zero
-
getNonZeroValues
public org.eclipse.collections.api.list.primitive.IntList getNonZeroValues()Returns a set of non-zero count values in this counter.- Overrides:
getNonZeroValuesin classCounter- Returns:
- a set of non-zero count values in this counter.
-
get
public int get(int key) Retreives a value for a given key.The key is first hashed to retreive a value from the counter, and hence the result is modulo collisions.
-
copyFrom
-
hasNonZeros
public boolean hasNonZeros()Description copied from class:CounterChecks if all indices have zero counts and returns a boolean as result.- Overrides:
hasNonZerosin classCounter- Returns:
trueif some indices have non-zero counts, otherwisefalse.
-