Class TIntMap<T extends java.lang.Comparable>

  • 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
    • Constructor Detail

      • TIntMap

        public TIntMap()
      • TIntMap

        public TIntMap​(int expectedSize)
      • 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)
      • restrict

        public TIntMap<T> restrict​(java.util.Set<T> set)
      • 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 java.lang.Iterable<T extends java.lang.Comparable>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object