Package 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<T>.Entry>
public class TIntMap<T extends Comparable>
extends AbstractTMap<T>
implements Iterable<TIntMap<T>.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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
class
class
class
class
Nested classes/interfaces inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
AbstractTMap.Functionality<T extends Comparable>, AbstractTMap.MapType
-
Field Summary
FieldsFields inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
defaultExpectedSize, growFactor, keyFunc, keys, loadFactor, locked, mapType, num, numCollisions
-
Constructor Summary
ConstructorsConstructorDescriptionTIntMap()
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
Modifier and TypeMethodDescriptionargmax()
int
capacity()
boolean
containsKey
(T key) copy()
entrySet()
int
int
void
gut()
void
void
incrAll
(int dValue) void
incrIfKeyExists
(T key, int dValue) void
iterator()
keySet()
void
lock()
double
max()
void
multAll
(int dValue) void
void
void
putAll
(int value) void
int
size()
double
sum()
void
void
toString()
values()
Methods inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
defaultFunctionality
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
serialVersionUID
protected static final long serialVersionUID- See Also:
-
-
Constructor Details
-
TIntMap
public TIntMap() -
TIntMap
-
TIntMap
public TIntMap(int expectedSize) -
TIntMap
-
TIntMap
expectedSize: expected number of entries we're going to have in the map.
-
-
Method Details
-
containsKey
-
get
-
getSure
-
put
-
put
-
incr
-
incrIfKeyExists
-
scale
-
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
-
max
public double max() -
incrMap
-
copy
-
restrict
-
entryValueComparator
-
lock
public void lock() -
switchToSortedList
public void switchToSortedList() -
switchToHashTable
public void switchToHashTable() -
iterator
- Specified by:
iterator
in interfaceIterable<T extends Comparable>
-
entrySet
-
keySet
-
values
-
toString
-