edu.berkeley.nlp.lm.collections
Class TIntMap<T extends Comparable>
java.lang.Object
edu.berkeley.nlp.lm.collections.AbstractTMap<T>
edu.berkeley.nlp.lm.collections.TIntMap<T>
- All Implemented Interfaces:
- Serializable, Iterable<TIntMap.Entry>
public class TIntMap<T extends Comparable>
- extends AbstractTMap<T>
- implements Iterable<TIntMap.Entry>, Serializable
Provides a map from objects to non-negative integers. Motivation: provides a
specialized data structure for mapping objects to doubles which is both fast
and space efficient. Feature 1: You can switch between two representations of
the map: - Sorted list (lookups involve binary search) - Hash table with
linear probing (lookups involve hashing) Feature 2: Sometimes, we want
several maps with the same set of keys. If we lock the map, we can share the
same keys between several maps, which saves space.
Note: in the sorted list, we first sort the keys by hash code, and then for
equal hash code, we sort by the objects values. We hope that hash code
collisions will be rare enough that we won't have to resort to comparing
objects.
Typical usage: - Construct a map using a hash table. - To save space, switch
to a sorted list representation.
Will get runtime exception if try to used sorted list and keys are not
comparable.
- Author:
- Adam Pauls, Percy Liang
- See Also:
- Serialized Form
serialVersionUID
protected static final long serialVersionUID
- See Also:
- Constant Field Values
TIntMap
public TIntMap()
TIntMap
public TIntMap(AbstractTMap.Functionality<T> keyFunc)
TIntMap
public TIntMap(int expectedSize)
TIntMap
public TIntMap(AbstractTMap<T> map)
TIntMap
public TIntMap(AbstractTMap.Functionality<T> keyFunc,
int expectedSize)
- expectedSize: expected number of entries we're going to have in the map.
containsKey
public boolean containsKey(T key)
get
public int get(T key,
int defaultValue)
getSure
public int getSure(T key)
put
public void put(T key,
int value)
put
public void put(T key,
int value,
boolean keepHigher)
incr
public void incr(T key,
int dValue)
incrIfKeyExists
public void incrIfKeyExists(T key,
int dValue)
scale
public void scale(T key,
int dValue)
size
public int size()
capacity
public int capacity()
gut
public void gut()
sum
public double sum()
putAll
public void putAll(int value)
incrAll
public void incrAll(int dValue)
multAll
public void multAll(int dValue)
argmax
public T argmax()
max
public double max()
incrMap
public void incrMap(TIntMap<T> map,
int factor)
copy
public TIntMap<T> copy()
restrict
public TIntMap<T> restrict(Set<T> set)
entryValueComparator
public TIntMap.EntryValueComparator entryValueComparator()
lock
public void lock()
switchToSortedList
public void switchToSortedList()
switchToHashTable
public void switchToHashTable()
iterator
public edu.berkeley.nlp.lm.collections.TIntMap.EntryIterator iterator()
- Specified by:
iterator
in interface Iterable<TIntMap.Entry>
entrySet
public TIntMap.EntrySet entrySet()
keySet
public TIntMap.KeySet keySet()
values
public TIntMap.ValueCollection values()
toString
public String toString()
- Overrides:
toString
in class Object