Class LongObjectHashMap<V>

java.lang.Object
smile.util.LongObjectHashMap<V>
Type Parameters:
V - the type of values.
All Implemented Interfaces:
Serializable

public class LongObjectHashMap<V> extends Object implements Serializable
An open-addressing hash map from primitive long keys to object values. Avoids autoboxing of keys entirely.

Long.MIN_VALUE (0x8000000000000000L) is reserved as the free-slot sentinel and must not be used as a key.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty map with default capacity 16 and load factor 0.75.
    LongObjectHashMap(int initialCapacity, float loadFactor)
    Constructs an empty map.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(long key)
    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    boolean
    Returns true if this map contains no entries.
    put(long key, V value)
    Associates the specified value with the specified key.
    putIfAbsent(long key, V value)
    If the specified key is not already associated with a value, associates it with the given value and returns null; otherwise returns the current value.
    int
    Returns the number of key-value mappings.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LongObjectHashMap

      public LongObjectHashMap()
      Constructs an empty map with default capacity 16 and load factor 0.75.
    • LongObjectHashMap

      public LongObjectHashMap(int initialCapacity, float loadFactor)
      Constructs an empty map.
      Parameters:
      initialCapacity - the initial capacity (will be rounded up to a power of two).
      loadFactor - the load factor, must be in (0, 1).
  • Method Details

    • size

      public int size()
      Returns the number of key-value mappings.
      Returns:
      the number of entries.
    • isEmpty

      public boolean isEmpty()
      Returns true if this map contains no entries.
      Returns:
      true if empty.
    • get

      public V get(long key)
      Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
      Parameters:
      key - the key (must not be Long.MIN_VALUE).
      Returns:
      the value, or null if absent.
    • put

      public V put(long key, V value)
      Associates the specified value with the specified key.
      Parameters:
      key - the key (must not be Long.MIN_VALUE).
      value - the value.
      Returns:
      the previous value, or null if there was no mapping.
    • putIfAbsent

      public V putIfAbsent(long key, V value)
      If the specified key is not already associated with a value, associates it with the given value and returns null; otherwise returns the current value.
      Parameters:
      key - the key.
      value - the value to insert if absent.
      Returns:
      the existing value if present, else null.