public interface Counter<E> extends PrettyLoggable
Counters
. The class previously known as Counter has been
renamed to ClassicCounter
. An alternative Counter
implementation, which is more memory efficient but not necessarily faster,
is OpenAddressCounter
.
Implementation note: You shouldn't casually add further methods to
this interface. Rather, they should be added to the Counters
class.
Modifier and Type | Method and Description |
---|---|
void |
addAll(Counter<E> counter)
Adds the counts in the given Counter to the counts in this Counter.
|
void |
clear()
Removes all entries from the counter.
|
boolean |
containsKey(E key)
Returns whether a Counter contains a key.
|
double |
decrementCount(E key)
Decrements the count for this key by 1.0.
|
double |
decrementCount(E key,
double value)
Decrements the count for this key by the given value.
|
double |
defaultReturnValue()
Returns the default return value.
|
Set<Map.Entry<E,Double>> |
entrySet()
Returns a view of the entries in this counter.
|
double |
getCount(Object key)
Returns the count for this key as a double.
|
Factory<Counter<E>> |
getFactory()
Returns a factory that can create new instances of this kind of Counter.
|
double |
incrementCount(E key)
Increments the count for this key by 1.0.
|
double |
incrementCount(E key,
double value)
Increments the count for the given key by the given value.
|
Set<E> |
keySet()
Returns the Set of keys in this counter.
|
double |
logIncrementCount(E key,
double value)
Increments the count stored in log space for this key by the given
log-transformed value.
|
double |
remove(E key)
Removes the given key and its associated value from this Counter.
|
void |
setCount(E key,
double value)
Sets the count for the given key to be the given value.
|
void |
setDefaultReturnValue(double rv)
Sets the default return value.
|
int |
size()
Returns the number of entries stored in this counter.
|
double |
totalCount()
Computes the total of all counts in this counter, and returns it
as a double.
|
Collection<Double> |
values()
Returns a copy of the values currently in this counter.
|
prettyLog
Factory<Counter<E>> getFactory()
void setDefaultReturnValue(double rv)
rv
- The default valuedouble defaultReturnValue()
double getCount(Object key)
key
- The keyvoid setCount(E key, double value)
incrementCount(Object,double)
.key
- The keyvalue
- The countdouble incrementCount(E key, double value)
incrementCount(Object)
.
To set a count to a specific value instead of incrementing it, use
setCount(Object,double)
.key
- The key to incrementvalue
- The amount to increment it bydouble incrementCount(E key)
incrementCount(Object,double)
.
To set a count to a specific value instead of incrementing it, use
setCount(Object,double)
.key
- The key to increment by 1.0double decrementCount(E key, double value)
incrementCount
.
To more conveniently decrement the count by 1.0, use
decrementCount(Object)
.
To set a count to a specific value instead of decrementing it, use
setCount(Object,double)
.key
- The key to decrementvalue
- The amount to decrement it bydouble decrementCount(E key)
decrementCount(Object,double)
.
To set a count to a specific value instead of decrementing it, use
setCount(Object,double)
.key
- The key to decrement by 1.0double logIncrementCount(E key, double value)
setCount(Object,double)
.key
- The key to incrementvalue
- The amount to increment it by, in log spacevoid addAll(Counter<E> counter)
counter
- The Counter whose counts will be added. For each key in
counter, if it is not in this, then it will be added with value
counter.getCount(key)
. Otherwise, it will have value
this.getCount(key) + counter.getCount(key)
.double remove(E key)
key
- The keyboolean containsKey(E key)
key
- The keySet<E> keySet()
Collection<Double> values()
Set<Map.Entry<E,Double>> entrySet()
void clear()
int size()
double totalCount()