Class IntObjectMap<V>

java.lang.Object
org.btrplace.util.IntObjectMap<V>

public class IntObjectMap<V>
extends Object
A map to associate an Object to an element. The map does not compact the key space so it is very efficient in terms of memory when there is no or a very few holes. For the best performances, it is also wise to set the capacity as early as possible to bypass the incremental expansion.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  IntObjectMap.Entry<V>
    Interface used to iterate over the entries.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int DEFAULT_SIZE
    Default size for the map.
  • Constructor Summary

    Constructors 
    Constructor Description
    IntObjectMap()
    Empty may with null to indicate no value.
    IntObjectMap​(V noValue)
    New map.
    IntObjectMap​(V noValue, int size)
    New map.
  • Method Summary

    Modifier and Type Method Description
    void clear()
    Clear the map.
    V clear​(int key)
    Clear the given key.
    IntObjectMap<V> copy()
    Returns a copy of the map.
    boolean equals​(Object o)  
    void expand​(int newSize)
    Expand the map to a new size.
    void forEach​(IntObjectMap.Entry<V> e)
    Iterate over the map entries.
    V get​(int key)
    Get the value for the key.
    boolean has​(int key)
    Check if a key is in the map.
    int hashCode()  
    V noEntryValue()
    Get the value indicating the key is not in the map.
    V put​(int key, V value)
    Put an entry in the map.
    V quickGet​(int key)
    Unsafe version of get(int).
    int size()
    Get the number of entries in the map.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • IntObjectMap

      public IntObjectMap()
      Empty may with null to indicate no value.
    • IntObjectMap

      public IntObjectMap​(V noValue)
      New map.
      Parameters:
      noValue - the value to use to report a missing key.
    • IntObjectMap

      public IntObjectMap​(V noValue, int size)
      New map.
      Parameters:
      noValue - the value to use to report a missing key.
      size - the backend size.
  • Method Details

    • expand

      public void expand​(int newSize)
      Expand the map to a new size.
      Parameters:
      newSize - the new size for the backend.
    • get

      public V get​(int key)
      Get the value for the key. If the key is not in, noEntryValue() is returned.
      Parameters:
      key - the key.
      Returns:
      the value associated to the key. noEntryValue() otherwise.
    • quickGet

      public V quickGet​(int key)
      Unsafe version of get(int).
      Parameters:
      key - the key.
      Returns:
      the value.
    • has

      public boolean has​(int key)
      Check if a key is in the map.
      Parameters:
      key - the key.
      Returns:
      true if the key is in the map. This means that the value differs from noEntryValue().
    • noEntryValue

      public V noEntryValue()
      Get the value indicating the key is not in the map.
      Returns:
      the value.
    • put

      public V put​(int key, V value)
      Put an entry in the map. The map is expanded if needed.
      Parameters:
      key - the entry key.
      value - the value.
    • copy

      public IntObjectMap<V> copy()
      Returns a copy of the map. The values associated to the keys are not copied.
      Returns:
      a copy.
    • clear

      public V clear​(int key)
      Clear the given key. The value will be set to noEntryValue().
      Parameters:
      key - the key.
    • clear

      public void clear()
      Clear the map.
    • forEach

      public void forEach​(IntObjectMap.Entry<V> e)
      Iterate over the map entries. This should not be used for any performance critical computation as the performance will depend on the key density.
      Parameters:
      e - the iterator to use.
    • equals

      public boolean equals​(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • size

      public int size()
      Get the number of entries in the map.
      Returns:
      a positive number.