Class FastHashMap<K,V>

java.lang.Object
org.apache.jena.mem.collection.FastHashBase<K>
org.apache.jena.mem.collection.FastHashMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
JenaMap<K,V>, JenaMapIndexed<K,V>, JenaMapSetCommon<K>, Sized
Direct Known Subclasses:
FastHashedBunchMap, NodesToBitmapsMap, NodesToIndices

public abstract class FastHashMap<K,V> extends FastHashBase<K> implements JenaMapIndexed<K,V>
Hash map specialization built on top of FastHashBase. Grows on demand but never shrinks, does not guarantee iteration order, does not allow null keys, and is not thread-safe.

Optimized for fast add / containsKey / stream / iterate operations. Removal is somewhat slower than in HashMap because of the back-shifting performed on the probe table. Iteration speed does not recover after many removals because the dense keys array is not compacted.

  • Method Details

    • clear

      public void clear()
      Description copied from class: FastHashBase
      Removes all the elements from this collection (optional operation). The collection will be empty after this method returns.
      Specified by:
      clear in interface JenaMapSetCommon<K>
      Overrides:
      clear in class FastHashBase<K>
    • tryPut

      public boolean tryPut(K key, V value)
      Description copied from interface: JenaMap
      Try to put a key-value pair into the map. If the key is already present, the value is updated.
      Specified by:
      tryPut in interface JenaMap<K,V>
      Parameters:
      key - the key to put. (null is not allowed)
      value - the value to put. (null is not allowed)
      Returns:
      true if the key-value pair was put into the map, false if the key was already present
    • put

      public void put(K key, V value)
      Description copied from interface: JenaMap
      Put a key-value pair into the map. If the key is already present, the value is updated.
      Specified by:
      put in interface JenaMap<K,V>
      Parameters:
      key - the key to put. (null is not allowed)
      value - the value to put. (null is not allowed)
    • putAndGetIndex

      public int putAndGetIndex(K key, V value)
      Description copied from interface: JenaMapIndexed
      Put a key-value pair and return the index of the affected entry. If the key is already present, its value is updated and the existing index is returned.
      Specified by:
      putAndGetIndex in interface JenaMapIndexed<K,V>
      Parameters:
      key - the key to put. (null is not allowed)
      value - the value to put. (null is not allowed)
      Returns:
      the index of the entry holding key
    • getValueAt

      public V getValueAt(int i)
      Returns the value at the given index. Array bounds are not checked. The caller must ensure the index is valid and corresponds to a non-null key.
      Specified by:
      getValueAt in interface JenaMapIndexed<K,V>
      Parameters:
      i - index
      Returns:
      value
    • get

      public V get(K key)
      Description copied from interface: JenaMap
      Get the value associated with the provided key.
      Specified by:
      get in interface JenaMap<K,V>
      Parameters:
      key - the key to look up
      Returns:
      the value associated with the key, or null if the key is not present
    • getOrDefault

      public V getOrDefault(K key, V defaultValue)
      Description copied from interface: JenaMap
      Get the value associated with the provided key, or a default value if the key is not present.
      Specified by:
      getOrDefault in interface JenaMap<K,V>
      Parameters:
      key - the key to look up
      defaultValue - the default value to return if the key is not present
      Returns:
      the value associated with the key, or the default value if the key is not present
    • computeIfAbsent

      public V computeIfAbsent(K key, Supplier<V> absentValueSupplier)
      Description copied from interface: JenaMap
      Compute a value for a key if the key is not present. The value is automatically put into the map.
      Specified by:
      computeIfAbsent in interface JenaMap<K,V>
      Parameters:
      key - the key whose value is to retrieved or computed
      absentValueSupplier - the function to compute a value for the key, if the key is not present
      Returns:
      the value associated with the key, or the value computed by the function if the key is not present
    • compute

      public void compute(K key, UnaryOperator<V> valueProcessor)
      Description copied from interface: JenaMap
      Compute a value for a key.
      Specified by:
      compute in interface JenaMap<K,V>
      Parameters:
      key - the key to compute a value for
      valueProcessor - the function to compute a value for the key. The function is passed the current value associated with the key, or null if the key is not present. The function should return the new value to associate with the key, or null if the key should be removed from the map.
    • valueIterator

      public ExtendedIterator<V> valueIterator()
      Description copied from interface: JenaMap
      Get an iterator over the values in the map.
      Specified by:
      valueIterator in interface JenaMap<K,V>
      Returns:
      an iterator over the values in the map
    • valueSpliterator

      public Spliterator<V> valueSpliterator()
      Description copied from interface: JenaMap
      Get a spliterator over the values in the map.
      Specified by:
      valueSpliterator in interface JenaMap<K,V>
      Returns:
      a spliterator over the values in the map