public class CounterMap<K,V>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static interface |
CounterMap.CountFunction<V> |
Constructor and Description |
---|
CounterMap() |
CounterMap(boolean identityHashMap) |
CounterMap(CounterMap<K,V> cm) |
CounterMap(MapFactory<K,Counter<V>> outerMF,
MapFactory<V,java.lang.Double> innerMF) |
Modifier and Type | Method and Description |
---|---|
Pair<K,V> |
argMax()
Finds the key with maximum count.
|
protected Counter<V> |
buildCounter(MapFactory<V,java.lang.Double> mf) |
boolean |
containsKey(K key) |
protected Counter<V> |
ensureCounter(K key) |
double |
getCount(K key)
Gets the total count of the given key, or zero if that key is
not present.
|
double |
getCount(K key,
V value)
Gets the count of the given (key, value) entry, or zero if that entry is
not present.
|
Counter<V> |
getCounter(K key)
Gets the sub-counter for the given key.
|
java.util.Collection<Counter<V>> |
getCounters() |
java.util.Set<java.util.Map.Entry<K,Counter<V>>> |
getEntrySet() |
java.util.Iterator<Pair<K,V>> |
getPairIterator() |
void |
incrementAll(CounterMap<K,V> cMap) |
void |
incrementAll(java.util.Map<K,V> map,
double count) |
void |
incrementCount(K key,
V value,
double count)
Increments the count for a particular (key, value) pair.
|
CounterMap<V,K> |
invert()
Constructs reverse CounterMap where the count of a pair (k,v)
is the count of (v,k) in the current CounterMap
|
boolean |
isEmpty()
True if there are no entries in the CounterMap (false does not mean
totalCount > 0)
|
boolean |
isEqualTo(CounterMap<K,V> map) |
java.util.Set<K> |
keySet()
Returns the keys that have been inserted into this CounterMap.
|
static void |
main(java.lang.String[] args) |
void |
normalize() |
void |
normalizeWithDiscount(double discount) |
static <K,V> CounterMap<K,V> |
parallelCounterMap()
Returns a thread safe counter map
|
void |
removeKey(K oldIndex) |
static <V> CounterMap<V,V> |
runPairWise(java.util.List<V> items,
CounterMap.CountFunction<V> countFunction)
Build a counter map by iterating pairwise over the list.
|
void |
scale(double scaleFactor)
Scale all entries in
CounterMap
by scaleFactor |
void |
setCount(K key,
V value,
double count)
Sets the count for a particular (key, value) pair.
|
void |
setCounter(K newIndex,
Counter<V> counter) |
void |
setDefault(double defltVal) |
int |
size()
The number of keys in this CounterMap (not the number of key-value entries
-- use totalSize() for that)
|
java.lang.String |
toString() |
java.lang.String |
toString(java.util.Collection<java.lang.String> keyFilter) |
java.lang.String |
toString(int maxValsPerKey) |
double |
totalCount()
Returns the total of all counts in sub-counters.
|
int |
totalSize()
Returns the total number of (key, value) entries in the CounterMap (not
their total counts).
|
public CounterMap(CounterMap<K,V> cm)
public CounterMap()
public CounterMap(MapFactory<K,Counter<V>> outerMF, MapFactory<V,java.lang.Double> innerMF)
public CounterMap(boolean identityHashMap)
public static <V> CounterMap<V,V> runPairWise(java.util.List<V> items, CounterMap.CountFunction<V> countFunction)
V
- the type to countitems
- the items to iterate overcountFunction
- the function to countpublic static <K,V> CounterMap<K,V> parallelCounterMap()
protected Counter<V> buildCounter(MapFactory<V,java.lang.Double> mf)
public java.util.Set<K> keySet()
public void setCount(K key, V value, double count)
public void incrementCount(K key, V value, double count)
public double getCount(K key, V value)
public Counter<V> getCounter(K key)
public void incrementAll(CounterMap<K,V> cMap)
public double getCount(K key)
public double totalCount()
public int totalSize()
public int size()
public boolean isEmpty()
public Pair<K,V> argMax()
public java.lang.String toString(int maxValsPerKey)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.util.Collection<java.lang.String> keyFilter)
public boolean isEqualTo(CounterMap<K,V> map)
public static void main(java.lang.String[] args)
public void normalize()
public void normalizeWithDiscount(double discount)
public CounterMap<V,K> invert()
public void scale(double scaleFactor)
CounterMap
by scaleFactor
scaleFactor
- public boolean containsKey(K key)
public void removeKey(K oldIndex)
public void setDefault(double defltVal)