Package edu.berkeley.nlp.lm.collections
Class TIntMap<T extends java.lang.Comparable>
- java.lang.Object
-
- edu.berkeley.nlp.lm.collections.AbstractTMap<T>
-
- edu.berkeley.nlp.lm.collections.TIntMap<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<TIntMap.Entry>
public class TIntMap<T extends java.lang.Comparable> extends AbstractTMap<T> implements java.lang.Iterable<TIntMap.Entry>, java.io.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classTIntMap.EntryclassTIntMap.EntrySetclassTIntMap.EntryValueComparatorclassTIntMap.KeySetclassTIntMap.ValueCollection-
Nested classes/interfaces inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
AbstractTMap.Functionality<T extends java.lang.Comparable>, AbstractTMap.MapType
-
-
Field Summary
Fields Modifier and Type Field Description protected static longserialVersionUID-
Fields inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
defaultExpectedSize, growFactor, keyFunc, keys, loadFactor, locked, mapType, num, numCollisions
-
-
Constructor Summary
Constructors Constructor Description TIntMap()TIntMap(int expectedSize)TIntMap(AbstractTMap.Functionality<T> keyFunc)TIntMap(AbstractTMap.Functionality<T> keyFunc, int expectedSize)expectedSize: expected number of entries we're going to have in the map.TIntMap(AbstractTMap<T> map)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Targmax()intcapacity()booleancontainsKey(T key)TIntMap<T>copy()TIntMap.EntrySetentrySet()TIntMap.EntryValueComparatorentryValueComparator()intget(T key, int defaultValue)intgetSure(T key)voidgut()voidincr(T key, int dValue)voidincrAll(int dValue)voidincrIfKeyExists(T key, int dValue)voidincrMap(TIntMap<T> map, int factor)edu.berkeley.nlp.lm.collections.TIntMap.EntryIteratoriterator()TIntMap.KeySetkeySet()voidlock()doublemax()voidmultAll(int dValue)voidput(T key, int value)voidput(T key, int value, boolean keepHigher)voidputAll(int value)TIntMap<T>restrict(java.util.Set<T> set)voidscale(T key, int dValue)intsize()doublesum()voidswitchToHashTable()voidswitchToSortedList()java.lang.StringtoString()TIntMap.ValueCollectionvalues()-
Methods inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
defaultFunctionality
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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.
-
-
Method Detail
-
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()
-
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:
iteratorin interfacejava.lang.Iterable<T extends java.lang.Comparable>
-
entrySet
public TIntMap.EntrySet entrySet()
-
keySet
public TIntMap.KeySet keySet()
-
values
public TIntMap.ValueCollection values()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-