Class OpenHashMap<K,V>

java.lang.Object
org.apache.felix.resolver.util.OpenHashMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, SequencedMap<K,V>, SortedMap<K,V>
Direct Known Subclasses:
OpenHashMapList, OpenHashMapSet

public class OpenHashMap<K,V> extends Object implements Serializable, Cloneable, SortedMap<K,V>
Based on fastutil Object2ObjectLinkedOpenHashMap
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • key

      protected transient Object[] key
    • value

      protected transient Object[] value
    • mask

      protected transient int mask
    • containsNullKey

      protected transient boolean containsNullKey
    • first

      protected transient int first
    • last

      protected transient int last
    • n

      protected transient int n
    • maxFill

      protected transient int maxFill
    • size

      protected int size
    • f

      protected final float f
    • defRetValue

      protected V defRetValue
    • fast

      protected transient Iterable<Map.Entry<K,V>> fast
    • entries

      protected transient SortedSet<Map.Entry<K,V>> entries
    • keys

      protected transient SortedSet<K> keys
    • values

      protected transient Collection<V> values
  • Constructor Details

    • OpenHashMap

      public OpenHashMap(int expected, float f)
    • OpenHashMap

      public OpenHashMap(int expected)
    • OpenHashMap

      public OpenHashMap()
    • OpenHashMap

      public OpenHashMap(Map<? extends K,? extends V> m, float f)
    • OpenHashMap

      public OpenHashMap(Map<? extends K,? extends V> m)
    • OpenHashMap

      public OpenHashMap(K[] k, V[] v, float f)
    • OpenHashMap

      public OpenHashMap(K[] k, V[] v)
  • Method Details

    • defaultReturnValue

      public void defaultReturnValue(V rv)
    • defaultReturnValue

      public V defaultReturnValue()
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class Object
    • toString

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

      private int realSize()
    • ensureCapacity

      private void ensureCapacity(int capacity)
    • tryCapacity

      private void tryCapacity(long capacity)
    • removeEntry

      private V removeEntry(int pos)
    • removeNullEntry

      private V removeNullEntry()
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Specified by:
      putAll in interface Map<K,V>
    • insert

      private int insert(K k, V v)
    • put

      public V put(K k, V v)
      Specified by:
      put in interface Map<K,V>
    • getOrCompute

      public V getOrCompute(K k)
    • compute

      protected V compute(K k)
    • shiftKeys

      protected final void shiftKeys(int pos)
    • remove

      public V remove(Object k)
      Specified by:
      remove in interface Map<K,V>
    • setValue

      private V setValue(int pos, V v)
    • removeFirst

      public V removeFirst()
    • removeLast

      public V removeLast()
    • moveIndexToFirst

      private void moveIndexToFirst(int i)
    • moveIndexToLast

      private void moveIndexToLast(int i)
    • getAndMoveToFirst

      public V getAndMoveToFirst(K k)
    • getAndMoveToLast

      public V getAndMoveToLast(K k)
    • putAndMoveToFirst

      public V putAndMoveToFirst(K k, V v)
    • putAndMoveToLast

      public V putAndMoveToLast(K k, V v)
    • get

      public V get(Object k)
      Specified by:
      get in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object k)
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object v)
      Specified by:
      containsValue in interface Map<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
    • fixPointers

      protected void fixPointers(int i)
    • fixPointers

      protected void fixPointers(int s, int d)
    • firstKey

      public K firstKey()
      Specified by:
      firstKey in interface SortedMap<K,V>
    • lastKey

      public K lastKey()
      Specified by:
      lastKey in interface SortedMap<K,V>
    • comparator

      public Comparator<? super K> comparator()
      Specified by:
      comparator in interface SortedMap<K,V>
    • tailMap

      public SortedMap<K,V> tailMap(K from)
      Specified by:
      tailMap in interface SortedMap<K,V>
    • headMap

      public SortedMap<K,V> headMap(K to)
      Specified by:
      headMap in interface SortedMap<K,V>
    • subMap

      public SortedMap<K,V> subMap(K from, K to)
      Specified by:
      subMap in interface SortedMap<K,V>
    • fast

      public Iterable<Map.Entry<K,V>> fast()
    • entrySet

      public SortedSet<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
      Specified by:
      entrySet in interface SortedMap<K,V>
    • keySet

      public SortedSet<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
      Specified by:
      keySet in interface SortedMap<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
      Specified by:
      values in interface SortedMap<K,V>
    • trim

      public boolean trim()
      Rehashes the map, making the table as small as possible.

      This method rehashes the table to the smallest size satisfying the load factor. It can be used when the set will not be changed anymore, so to optimize access speed and size.

      If the table size is already the minimum possible, this method does nothing.

      Returns:
      true if there was enough memory to trim the map.
      See Also:
    • trim

      public boolean trim(int n)
      Rehashes this map if the table is too large.

      Let N be the smallest table size that can hold max(n,size()) entries, still satisfying the load factor. If the current table size is smaller than or equal to N, this method does nothing. Otherwise, it rehashes this map in a table of size N.

      This method is useful when reusing maps. Clearing a map leaves the table size untouched. If you are reusing a map many times, you can call this method with a typical size to avoid keeping around a very large table just because of a few large transient maps.

      Parameters:
      n - the threshold for the trimming.
      Returns:
      true if there was enough memory to trim the map.
      See Also:
    • rehash

      protected void rehash(int newN)
      Rehashes the map.

      This method implements the basic rehashing strategy, and may be overriden by subclasses implementing different rehashing strategies (e.g., disk-based rehashing). However, you should not override this method unless you understand the internal workings of this class.

      Parameters:
      newN - the new size
    • clone

      public OpenHashMap<K,V> clone()
      Overrides:
      clone in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class Object
    • writeObject

      private void writeObject(ObjectOutputStream s) throws IOException
      Throws:
      IOException
    • readObject

      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • checkTable

      private void checkTable()
    • arraySize

      private static int arraySize(int expected, float f)
    • maxFill

      private static int maxFill(int n, float f)
    • nextPowerOfTwo

      private static int nextPowerOfTwo(int x)
    • nextPowerOfTwo

      private static long nextPowerOfTwo(long x)
    • mix

      private static int mix(int x)
    • unwrap

      private static <K> int unwrap(Iterator<? extends K> i, K[] array, int offset, int max)
    • unwrap

      private static <K> int unwrap(Iterator<? extends K> i, K[] array)