Package cern.colt.map

Class AbstractMap

java.lang.Object
cern.colt.PersistentObject
cern.colt.map.AbstractMap
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AbstractDoubleIntMap, AbstractIntDoubleMap, AbstractIntIntMap, AbstractIntObjectMap, AbstractLongObjectMap

public abstract class AbstractMap extends PersistentObject
Abstract base class for hash maps holding objects or primitive data types such as int, float, etc. as keys and/or values. First see the package summary and javadoc tree view to get the broad picture.

Note that implementations are not synchronized.

Version:
1.0, 09/24/99
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final int
     
    protected static final double
     
    protected static final double
     
    protected int
    The number of distinct associations in the map; its "size()".
    protected int
     
    protected int
    The table capacity c=table.length always satisfies the invariant c * minLoadFactor invalid input: '<'= s invalid input: '<'= c * maxLoadFactor, where s=size() is the number of associations currently contained.
    protected double
    The maximum load factor for the hashtable.
    protected double
    The minimum load factor for the hashtable.

    Fields inherited from class cern.colt.PersistentObject

    serialVersionUID
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Makes this class non instantiable, but still let's others inherit from it.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected int
    chooseGrowCapacity(int size, double minLoad, double maxLoad)
    Chooses a new prime table capacity optimized for growing that (approximately) satisfies the invariant c * minLoadFactor invalid input: '<'= size invalid input: '<'= c * maxLoadFactor and has at least one FREE slot for the given size.
    protected int
    chooseHighWaterMark(int capacity, double maxLoad)
    Returns new high water mark threshold based on current capacity and maxLoadFactor.
    protected int
    chooseLowWaterMark(int capacity, double minLoad)
    Returns new low water mark threshold based on current capacity and minLoadFactor.
    protected int
    chooseMeanCapacity(int size, double minLoad, double maxLoad)
    Chooses a new prime table capacity neither favoring shrinking nor growing, that (approximately) satisfies the invariant c * minLoadFactor invalid input: '<'= size invalid input: '<'= c * maxLoadFactor and has at least one FREE slot for the given size.
    protected int
    chooseShrinkCapacity(int size, double minLoad, double maxLoad)
    Chooses a new prime table capacity optimized for shrinking that (approximately) satisfies the invariant c * minLoadFactor invalid input: '<'= size invalid input: '<'= c * maxLoadFactor and has at least one FREE slot for the given size.
    abstract void
    Removes all (key,value) associations from the receiver.
    void
    ensureCapacity(int minCapacity)
    Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
    boolean
    Returns true if the receiver contains no (key,value) associations.
    protected int
    nextPrime(int desiredCapacity)
    Returns a prime number which is >= desiredCapacity and very close to desiredCapacity (within 11% if desiredCapacity >= 1000).
    protected void
    setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor)
    Initializes the receiver.
    int
    Returns the number of (key,value) associations currently contained.
    void
    Trims the capacity of the receiver to be the receiver's current size.

    Methods inherited from class cern.colt.PersistentObject

    clone

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • distinct

      protected int distinct
      The number of distinct associations in the map; its "size()".
    • lowWaterMark

      protected int lowWaterMark
      The table capacity c=table.length always satisfies the invariant c * minLoadFactor invalid input: '<'= s invalid input: '<'= c * maxLoadFactor, where s=size() is the number of associations currently contained. The term "c * minLoadFactor" is called the "lowWaterMark", "c * maxLoadFactor" is called the "highWaterMark". In other words, the table capacity (and proportionally the memory used by this class) oscillates within these constraints. The terms are precomputed and cached to avoid recalculating them each time put(..) or removeKey(...) is called.
    • highWaterMark

      protected int highWaterMark
    • minLoadFactor

      protected double minLoadFactor
      The minimum load factor for the hashtable.
    • maxLoadFactor

      protected double maxLoadFactor
      The maximum load factor for the hashtable.
    • defaultCapacity

      protected static final int defaultCapacity
      See Also:
    • defaultMinLoadFactor

      protected static final double defaultMinLoadFactor
      See Also:
    • defaultMaxLoadFactor

      protected static final double defaultMaxLoadFactor
      See Also:
  • Constructor Details

    • AbstractMap

      protected AbstractMap()
      Makes this class non instantiable, but still let's others inherit from it.
  • Method Details

    • chooseGrowCapacity

      protected int chooseGrowCapacity(int size, double minLoad, double maxLoad)
      Chooses a new prime table capacity optimized for growing that (approximately) satisfies the invariant c * minLoadFactor invalid input: '<'= size invalid input: '<'= c * maxLoadFactor and has at least one FREE slot for the given size.
    • chooseHighWaterMark

      protected int chooseHighWaterMark(int capacity, double maxLoad)
      Returns new high water mark threshold based on current capacity and maxLoadFactor.
      Returns:
      int the new threshold.
    • chooseLowWaterMark

      protected int chooseLowWaterMark(int capacity, double minLoad)
      Returns new low water mark threshold based on current capacity and minLoadFactor.
      Returns:
      int the new threshold.
    • chooseMeanCapacity

      protected int chooseMeanCapacity(int size, double minLoad, double maxLoad)
      Chooses a new prime table capacity neither favoring shrinking nor growing, that (approximately) satisfies the invariant c * minLoadFactor invalid input: '<'= size invalid input: '<'= c * maxLoadFactor and has at least one FREE slot for the given size.
    • chooseShrinkCapacity

      protected int chooseShrinkCapacity(int size, double minLoad, double maxLoad)
      Chooses a new prime table capacity optimized for shrinking that (approximately) satisfies the invariant c * minLoadFactor invalid input: '<'= size invalid input: '<'= c * maxLoadFactor and has at least one FREE slot for the given size.
    • clear

      public abstract void clear()
      Removes all (key,value) associations from the receiver.
    • ensureCapacity

      public void ensureCapacity(int minCapacity)
      Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory. If necessary, allocates new internal memory and increases the capacity of the receiver.

      This method never need be called; it is for performance tuning only. Calling this method before put()ing a large number of associations boosts performance, because the receiver will grow only once instead of potentially many times.

      This default implementation does nothing. Override this method if necessary.

      Parameters:
      minCapacity - the desired minimum capacity.
    • isEmpty

      public boolean isEmpty()
      Returns true if the receiver contains no (key,value) associations.
      Returns:
      true if the receiver contains no (key,value) associations.
    • nextPrime

      protected int nextPrime(int desiredCapacity)
      Returns a prime number which is >= desiredCapacity and very close to desiredCapacity (within 11% if desiredCapacity >= 1000).
      Parameters:
      desiredCapacity - the capacity desired by the user.
      Returns:
      the capacity which should be used for a hashtable.
    • setUp

      protected void setUp(int initialCapacity, double minLoadFactor, double maxLoadFactor)
      Initializes the receiver. You will almost certainly need to override this method in subclasses to initialize the hash table.
      Parameters:
      initialCapacity - the initial capacity of the receiver.
      minLoadFactor - the minLoadFactor of the receiver.
      maxLoadFactor - the maxLoadFactor of the receiver.
      Throws:
      IllegalArgumentException - if initialCapacity invalid input: '<' 0 || (minLoadFactor invalid input: '<' 0.0 || minLoadFactor >= 1.0) || (maxLoadFactor invalid input: '<'= 0.0 || maxLoadFactor >= 1.0) || (minLoadFactor >= maxLoadFactor).
    • size

      public int size()
      Returns the number of (key,value) associations currently contained.
      Returns:
      the number of (key,value) associations currently contained.
    • trimToSize

      public void trimToSize()
      Trims the capacity of the receiver to be the receiver's current size. Releases any superfluous internal memory. An application can use this operation to minimize the storage of the receiver.

      This default implementation does nothing. Override this method if necessary.