edu.berkeley.nlp.lm.collections
Class TIntMap<T extends Comparable>

java.lang.Object
  extended by edu.berkeley.nlp.lm.collections.AbstractTMap<T>
      extended by 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

Nested Class Summary
 class TIntMap.Entry
           
 class TIntMap.EntrySet
           
 class TIntMap.EntryValueComparator
           
 class TIntMap.KeySet
           
 class TIntMap.ValueCollection
           
 
Nested classes/interfaces inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
AbstractTMap.Functionality<T extends Comparable>, AbstractTMap.MapType
 
Field Summary
protected static long serialVersionUID
           
 
Fields inherited from class edu.berkeley.nlp.lm.collections.AbstractTMap
defaultExpectedSize, growFactor, keyFunc, keys, loadFactor, locked, mapType, num, numCollisions
 
Constructor Summary
TIntMap()
           
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)
           
TIntMap(int expectedSize)
           
 
Method Summary
 T argmax()
           
 int capacity()
           
 boolean containsKey(T key)
           
 TIntMap<T> copy()
           
 TIntMap.EntrySet entrySet()
           
 TIntMap.EntryValueComparator entryValueComparator()
           
 int get(T key, int defaultValue)
           
 int getSure(T key)
           
 void gut()
           
 void incr(T key, int dValue)
           
 void incrAll(int dValue)
           
 void incrIfKeyExists(T key, int dValue)
           
 void incrMap(TIntMap<T> map, int factor)
           
 edu.berkeley.nlp.lm.collections.TIntMap.EntryIterator iterator()
           
 TIntMap.KeySet keySet()
           
 void lock()
           
 double max()
           
 void multAll(int dValue)
           
 void put(T key, int value)
           
 void put(T key, int value, boolean keepHigher)
           
 void putAll(int value)
           
 TIntMap<T> restrict(Set<T> set)
           
 void scale(T key, int dValue)
           
 int size()
           
 double sum()
           
 void switchToHashTable()
           
 void switchToSortedList()
           
 String toString()
           
 TIntMap.ValueCollection 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
 

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()

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