Class BiInt2ObjectMap<V>

java.lang.Object
org.agrona.collections.BiInt2ObjectMap<V>
Type Parameters:
V - type of the object stored in the map.
Direct Known Subclasses:
BiInt2NullableObjectMap

public class BiInt2ObjectMap<V> extends Object
Map that takes two part int key and associates with an object.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Handler for a map entry.
    static interface 
    Creates a new value based upon keys.
    static interface 
    Creates a new value based upon keys.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long[]
     
    private final float
     
    private static final int
     
    private int
     
    private int
     
    private Object[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct an empty map.
    BiInt2ObjectMap(int initialCapacity, float loadFactor)
    Construct a map that sets it initial capacity and load factor.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get the total capacity for the map to which the load factor with be a fraction of.
    void
    Clear out the map of all entries.
    void
    Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.
    private void
    compactChain(int deleteIndex)
     
    compute(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V,? extends V> remappingFunction)
    Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
    computeIfAbsent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryFunction<? extends V> mappingFunction)
    If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
    computeIfPresent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V,? extends V> remappingFunction)
    If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.
    boolean
    containsKey(int keyPartA, int keyPartB)
    Returns true if this map contains a mapping for the specified key.
    void
    forEach(Consumer<V> consumer)
    Iterate over the contents of the map.
    void
    Iterate over the contents of the map.
    get(int keyPartA, int keyPartB)
    Retrieve a value from the map.
    private V
    getMapping(int keyPartA, int keyPartB)
     
    getOrDefault(int keyPartA, int keyPartB, V defaultValue)
    Retrieve a value from the map or defaultValue if this map contains not mapping for the key.
    private void
     
    boolean
    Is map empty or not.
    float
    Get the load factor beyond which the map will increase size.
    protected Object
    Interceptor for masking null values.
    merge(int keyPartA, int keyPartB, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
    If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.
    put(int keyPartA, int keyPartB, V value)
    Put a value into the map.
    putIfAbsent(int keyPartA, int keyPartB, V value)
    If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.
    private void
    rehash(int newCapacity)
     
    remove(int keyPartA, int keyPartB)
    Remove a value from the map and return the value.
    boolean
    remove(int keyPartA, int keyPartB, V value)
    Removes the entry for the specified key only if it is currently mapped to the specified value.
    replace(int keyPartA, int keyPartB, V value)
    Replaces the entry for the specified key only if currently mapped to the specified value.
    boolean
    replace(int keyPartA, int keyPartB, V oldValue, V newValue)
    Replaces the entry for the specified key only if currently mapped to the specified value.
    int
    Get the actual threshold which when reached the map will resize.
    int
    Return the number of unique entries in the map.
    protected V
    Interceptor for unmasking null values.

    Methods inherited from class java.lang.Object

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

    • MIN_CAPACITY

      private static final int MIN_CAPACITY
      See Also:
    • loadFactor

      private final float loadFactor
    • resizeThreshold

      private int resizeThreshold
    • size

      private int size
    • keys

      private long[] keys
    • values

      private Object[] values
  • Constructor Details

    • BiInt2ObjectMap

      public BiInt2ObjectMap()
      Construct an empty map.
    • BiInt2ObjectMap

      public BiInt2ObjectMap(int initialCapacity, float loadFactor)
      Construct a map that sets it initial capacity and load factor.
      Parameters:
      initialCapacity - for the underlying hash map.
      loadFactor - for the underlying hash map.
  • Method Details

    • capacity

      public int capacity()
      Get the total capacity for the map to which the load factor with be a fraction of.
      Returns:
      the total capacity for the map.
    • loadFactor

      public float loadFactor()
      Get the load factor beyond which the map will increase size.
      Returns:
      load factor for when the map should increase size.
    • resizeThreshold

      public int resizeThreshold()
      Get the actual threshold which when reached the map will resize. This is a function of the current capacity and load factor.
      Returns:
      the threshold when the map will resize.
    • clear

      public void clear()
      Clear out the map of all entries.
      See Also:
    • compact

      public void compact()
      Compact the backing arrays by rehashing with a capacity just larger than current size and giving consideration to the load factor.
    • put

      public V put(int keyPartA, int keyPartB, V value)
      Put a value into the map.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      value - to put into the map.
      Returns:
      the previous value if found otherwise null.
      See Also:
    • mapNullValue

      protected Object mapNullValue(Object value)
      Interceptor for masking null values.
      Parameters:
      value - value to mask.
      Returns:
      masked value.
    • unmapNullValue

      protected V unmapNullValue(Object value)
      Interceptor for unmasking null values.
      Parameters:
      value - value to unmask.
      Returns:
      unmasked value.
    • getMapping

      private V getMapping(int keyPartA, int keyPartB)
    • get

      public V get(int keyPartA, int keyPartB)
      Retrieve a value from the map.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      Returns:
      value matching the key if found or null if not found.
      See Also:
    • getOrDefault

      public V getOrDefault(int keyPartA, int keyPartB, V defaultValue)
      Retrieve a value from the map or defaultValue if this map contains not mapping for the key.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      defaultValue - the default mapping of the key.
      Returns:
      value matching the key if found or defaultValue if not found.
      See Also:
    • containsKey

      public boolean containsKey(int keyPartA, int keyPartB)
      Returns true if this map contains a mapping for the specified key.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      Returns:
      true if this map contains a mapping for the specified key
      See Also:
    • remove

      public V remove(int keyPartA, int keyPartB)
      Remove a value from the map and return the value.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      Returns:
      the previous value if found otherwise null
      See Also:
    • computeIfAbsent

      public V computeIfAbsent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryFunction<? extends V> mappingFunction)
      If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      mappingFunction - creates values based upon keys if the key pair is missing.
      Returns:
      the newly created or stored value.
      See Also:
    • computeIfPresent

      public V computeIfPresent(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V,? extends V> remappingFunction)
      If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.

      If the function returns null, the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.

      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      remappingFunction - the function to compute a value.
      Returns:
      the new value associated with the specified key, or null if none.
      See Also:
    • compute

      public V compute(int keyPartA, int keyPartB, BiInt2ObjectMap.EntryRemap<? super V,? extends V> remappingFunction)
      Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      remappingFunction - the function to compute a value.
      Returns:
      the new value associated with the specified key, or null if none.
      See Also:
    • merge

      public V merge(int keyPartA, int keyPartB, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
      If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      value - the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key.
      remappingFunction - the function to recompute a value if present.
      Returns:
      the new value associated with the specified key, or null if no value is associated with the key.
      See Also:
    • forEach

      public void forEach(Consumer<V> consumer)
      Iterate over the contents of the map.
      Parameters:
      consumer - to apply to each value in the map.
    • forEach

      public void forEach(BiInt2ObjectMap.EntryConsumer<V> consumer)
      Iterate over the contents of the map.
      Parameters:
      consumer - to apply to each value in the map.
    • replace

      public V replace(int keyPartA, int keyPartB, V value)
      Replaces the entry for the specified key only if currently mapped to the specified value.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      value - value to be associated with the specified key.
      Returns:
      the previous value associated with the specified key, or null if there was no mapping for the key. A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.
      See Also:
    • replace

      public boolean replace(int keyPartA, int keyPartB, V oldValue, V newValue)
      Replaces the entry for the specified key only if currently mapped to the specified value.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      oldValue - value expected to be associated with the specified key.
      newValue - to be associated with the specified key.
      Returns:
      true if the value was replaced.
    • putIfAbsent

      public V putIfAbsent(int keyPartA, int keyPartB, V value)
      If the specified key is not already associated with a value (or is mapped to null) associates it with the given value and returns null, else returns the current value.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      value - to put into the map.
      Returns:
      the previous value if found otherwise null.
    • remove

      public boolean remove(int keyPartA, int keyPartB, V value)
      Removes the entry for the specified key only if it is currently mapped to the specified value.
      Parameters:
      keyPartA - for the key.
      keyPartB - for the key.
      value - value expected to be associated with the specified key.
      Returns:
      true if the value was removed.
      See Also:
    • size

      public int size()
      Return the number of unique entries in the map.
      Returns:
      number of unique entries in the map.
    • isEmpty

      public boolean isEmpty()
      Is map empty or not.
      Returns:
      boolean indicating empty map or not.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • rehash

      private void rehash(int newCapacity)
    • compactChain

      private void compactChain(int deleteIndex)
    • increaseCapacity

      private void increaseCapacity()