Interface Hash

All Known Implementing Classes:
BooleanOpenHashSet, Byte2BooleanLinkedOpenHashMap, Byte2BooleanOpenCustomHashMap, Byte2BooleanOpenHashMap, Byte2ByteLinkedOpenHashMap, Byte2ByteOpenCustomHashMap, Byte2ByteOpenHashMap, Byte2CharLinkedOpenHashMap, Byte2CharOpenCustomHashMap, Byte2CharOpenHashMap, Byte2DoubleLinkedOpenHashMap, Byte2DoubleOpenCustomHashMap, Byte2DoubleOpenHashMap, Byte2FloatLinkedOpenHashMap, Byte2FloatOpenCustomHashMap, Byte2FloatOpenHashMap, Byte2IntLinkedOpenHashMap, Byte2IntOpenCustomHashMap, Byte2IntOpenHashMap, Byte2LongLinkedOpenHashMap, Byte2LongOpenCustomHashMap, Byte2LongOpenHashMap, Byte2ObjectLinkedOpenHashMap, Byte2ObjectOpenCustomHashMap, Byte2ObjectOpenHashMap, Byte2ReferenceLinkedOpenHashMap, Byte2ReferenceOpenCustomHashMap, Byte2ReferenceOpenHashMap, Byte2ShortLinkedOpenHashMap, Byte2ShortOpenCustomHashMap, Byte2ShortOpenHashMap, ByteLinkedOpenCustomHashSet, ByteLinkedOpenHashSet, ByteOpenCustomHashSet, ByteOpenHashSet, Char2BooleanLinkedOpenHashMap, Char2BooleanOpenCustomHashMap, Char2BooleanOpenHashMap, Char2ByteLinkedOpenHashMap, Char2ByteOpenCustomHashMap, Char2ByteOpenHashMap, Char2CharLinkedOpenHashMap, Char2CharOpenCustomHashMap, Char2CharOpenHashMap, Char2DoubleLinkedOpenHashMap, Char2DoubleOpenCustomHashMap, Char2DoubleOpenHashMap, Char2FloatLinkedOpenHashMap, Char2FloatOpenCustomHashMap, Char2FloatOpenHashMap, Char2IntLinkedOpenHashMap, Char2IntOpenCustomHashMap, Char2IntOpenHashMap, Char2LongLinkedOpenHashMap, Char2LongOpenCustomHashMap, Char2LongOpenHashMap, Char2ObjectLinkedOpenHashMap, Char2ObjectOpenCustomHashMap, Char2ObjectOpenHashMap, Char2ReferenceLinkedOpenHashMap, Char2ReferenceOpenCustomHashMap, Char2ReferenceOpenHashMap, Char2ShortLinkedOpenHashMap, Char2ShortOpenCustomHashMap, Char2ShortOpenHashMap, CharLinkedOpenCustomHashSet, CharLinkedOpenHashSet, CharOpenCustomHashSet, CharOpenHashSet, Double2BooleanLinkedOpenHashMap, Double2BooleanOpenCustomHashMap, Double2BooleanOpenHashMap, Double2ByteLinkedOpenHashMap, Double2ByteOpenCustomHashMap, Double2ByteOpenHashMap, Double2CharLinkedOpenHashMap, Double2CharOpenCustomHashMap, Double2CharOpenHashMap, Double2DoubleLinkedOpenHashMap, Double2DoubleOpenCustomHashMap, Double2DoubleOpenHashMap, Double2FloatLinkedOpenHashMap, Double2FloatOpenCustomHashMap, Double2FloatOpenHashMap, Double2IntLinkedOpenHashMap, Double2IntOpenCustomHashMap, Double2IntOpenHashMap, Double2LongLinkedOpenHashMap, Double2LongOpenCustomHashMap, Double2LongOpenHashMap, Double2ObjectLinkedOpenHashMap, Double2ObjectOpenCustomHashMap, Double2ObjectOpenHashMap, Double2ReferenceLinkedOpenHashMap, Double2ReferenceOpenCustomHashMap, Double2ReferenceOpenHashMap, Double2ShortLinkedOpenHashMap, Double2ShortOpenCustomHashMap, Double2ShortOpenHashMap, DoubleLinkedOpenCustomHashSet, DoubleLinkedOpenHashSet, DoubleOpenCustomHashSet, DoubleOpenHashBigSet, DoubleOpenHashSet, Float2BooleanLinkedOpenHashMap, Float2BooleanOpenCustomHashMap, Float2BooleanOpenHashMap, Float2ByteLinkedOpenHashMap, Float2ByteOpenCustomHashMap, Float2ByteOpenHashMap, Float2CharLinkedOpenHashMap, Float2CharOpenCustomHashMap, Float2CharOpenHashMap, Float2DoubleLinkedOpenHashMap, Float2DoubleOpenCustomHashMap, Float2DoubleOpenHashMap, Float2FloatLinkedOpenHashMap, Float2FloatOpenCustomHashMap, Float2FloatOpenHashMap, Float2IntLinkedOpenHashMap, Float2IntOpenCustomHashMap, Float2IntOpenHashMap, Float2LongLinkedOpenHashMap, Float2LongOpenCustomHashMap, Float2LongOpenHashMap, Float2ObjectLinkedOpenHashMap, Float2ObjectOpenCustomHashMap, Float2ObjectOpenHashMap, Float2ReferenceLinkedOpenHashMap, Float2ReferenceOpenCustomHashMap, Float2ReferenceOpenHashMap, Float2ShortLinkedOpenHashMap, Float2ShortOpenCustomHashMap, Float2ShortOpenHashMap, FloatLinkedOpenCustomHashSet, FloatLinkedOpenHashSet, FloatOpenCustomHashSet, FloatOpenHashBigSet, FloatOpenHashSet, Int2BooleanLinkedOpenHashMap, Int2BooleanOpenCustomHashMap, Int2BooleanOpenHashMap, Int2ByteLinkedOpenHashMap, Int2ByteOpenCustomHashMap, Int2ByteOpenHashMap, Int2CharLinkedOpenHashMap, Int2CharOpenCustomHashMap, Int2CharOpenHashMap, Int2DoubleLinkedOpenHashMap, Int2DoubleOpenCustomHashMap, Int2DoubleOpenHashMap, Int2FloatLinkedOpenHashMap, Int2FloatOpenCustomHashMap, Int2FloatOpenHashMap, Int2IntLinkedOpenHashMap, Int2IntOpenCustomHashMap, Int2IntOpenHashMap, Int2LongLinkedOpenHashMap, Int2LongOpenCustomHashMap, Int2LongOpenHashMap, Int2ObjectLinkedOpenHashMap, Int2ObjectOpenCustomHashMap, Int2ObjectOpenHashMap, Int2ReferenceLinkedOpenHashMap, Int2ReferenceOpenCustomHashMap, Int2ReferenceOpenHashMap, Int2ShortLinkedOpenHashMap, Int2ShortOpenCustomHashMap, Int2ShortOpenHashMap, IntLinkedOpenCustomHashSet, IntLinkedOpenHashSet, IntOpenCustomHashSet, IntOpenHashBigSet, IntOpenHashSet, Long2BooleanLinkedOpenHashMap, Long2BooleanOpenCustomHashMap, Long2BooleanOpenHashMap, Long2ByteLinkedOpenHashMap, Long2ByteOpenCustomHashMap, Long2ByteOpenHashMap, Long2CharLinkedOpenHashMap, Long2CharOpenCustomHashMap, Long2CharOpenHashMap, Long2DoubleLinkedOpenHashMap, Long2DoubleOpenCustomHashMap, Long2DoubleOpenHashMap, Long2FloatLinkedOpenHashMap, Long2FloatOpenCustomHashMap, Long2FloatOpenHashMap, Long2IntLinkedOpenHashMap, Long2IntOpenCustomHashMap, Long2IntOpenHashMap, Long2LongLinkedOpenHashMap, Long2LongOpenCustomHashMap, Long2LongOpenHashMap, Long2ObjectLinkedOpenHashMap, Long2ObjectOpenCustomHashMap, Long2ObjectOpenHashMap, Long2ReferenceLinkedOpenHashMap, Long2ReferenceOpenCustomHashMap, Long2ReferenceOpenHashMap, Long2ShortLinkedOpenHashMap, Long2ShortOpenCustomHashMap, Long2ShortOpenHashMap, LongLinkedOpenCustomHashSet, LongLinkedOpenHashSet, LongOpenCustomHashSet, LongOpenHashBigSet, LongOpenHashSet, Object2BooleanLinkedOpenCustomHashMap, Object2BooleanLinkedOpenHashMap, Object2BooleanOpenCustomHashMap, Object2BooleanOpenHashMap, Object2ByteLinkedOpenCustomHashMap, Object2ByteLinkedOpenHashMap, Object2ByteOpenCustomHashMap, Object2ByteOpenHashMap, Object2CharLinkedOpenCustomHashMap, Object2CharLinkedOpenHashMap, Object2CharOpenCustomHashMap, Object2CharOpenHashMap, Object2DoubleLinkedOpenCustomHashMap, Object2DoubleLinkedOpenHashMap, Object2DoubleOpenCustomHashMap, Object2DoubleOpenHashMap, Object2FloatLinkedOpenCustomHashMap, Object2FloatLinkedOpenHashMap, Object2FloatOpenCustomHashMap, Object2FloatOpenHashMap, Object2IntLinkedOpenCustomHashMap, Object2IntLinkedOpenHashMap, Object2IntOpenCustomHashMap, Object2IntOpenHashMap, Object2LongLinkedOpenCustomHashMap, Object2LongLinkedOpenHashMap, Object2LongOpenCustomHashMap, Object2LongOpenHashMap, Object2ObjectLinkedOpenCustomHashMap, Object2ObjectLinkedOpenHashMap, Object2ObjectOpenCustomHashMap, Object2ObjectOpenHashMap, Object2ReferenceLinkedOpenCustomHashMap, Object2ReferenceLinkedOpenHashMap, Object2ReferenceOpenCustomHashMap, Object2ReferenceOpenHashMap, Object2ShortLinkedOpenCustomHashMap, Object2ShortLinkedOpenHashMap, Object2ShortOpenCustomHashMap, Object2ShortOpenHashMap, ObjectLinkedOpenCustomHashSet, ObjectLinkedOpenHashSet, ObjectOpenCustomHashSet, ObjectOpenHashBigSet, ObjectOpenHashSet, Reference2BooleanLinkedOpenHashMap, Reference2BooleanOpenCustomHashMap, Reference2BooleanOpenHashMap, Reference2ByteLinkedOpenHashMap, Reference2ByteOpenCustomHashMap, Reference2ByteOpenHashMap, Reference2CharLinkedOpenHashMap, Reference2CharOpenCustomHashMap, Reference2CharOpenHashMap, Reference2DoubleLinkedOpenHashMap, Reference2DoubleOpenCustomHashMap, Reference2DoubleOpenHashMap, Reference2FloatLinkedOpenHashMap, Reference2FloatOpenCustomHashMap, Reference2FloatOpenHashMap, Reference2IntLinkedOpenHashMap, Reference2IntOpenCustomHashMap, Reference2IntOpenHashMap, Reference2LongLinkedOpenHashMap, Reference2LongOpenCustomHashMap, Reference2LongOpenHashMap, Reference2ObjectLinkedOpenHashMap, Reference2ObjectOpenCustomHashMap, Reference2ObjectOpenHashMap, Reference2ReferenceLinkedOpenHashMap, Reference2ReferenceOpenCustomHashMap, Reference2ReferenceOpenHashMap, Reference2ShortLinkedOpenHashMap, Reference2ShortOpenCustomHashMap, Reference2ShortOpenHashMap, ReferenceLinkedOpenHashSet, ReferenceOpenHashBigSet, ReferenceOpenHashSet, Short2BooleanLinkedOpenHashMap, Short2BooleanOpenCustomHashMap, Short2BooleanOpenHashMap, Short2ByteLinkedOpenHashMap, Short2ByteOpenCustomHashMap, Short2ByteOpenHashMap, Short2CharLinkedOpenHashMap, Short2CharOpenCustomHashMap, Short2CharOpenHashMap, Short2DoubleLinkedOpenHashMap, Short2DoubleOpenCustomHashMap, Short2DoubleOpenHashMap, Short2FloatLinkedOpenHashMap, Short2FloatOpenCustomHashMap, Short2FloatOpenHashMap, Short2IntLinkedOpenHashMap, Short2IntOpenCustomHashMap, Short2IntOpenHashMap, Short2LongLinkedOpenHashMap, Short2LongOpenCustomHashMap, Short2LongOpenHashMap, Short2ObjectLinkedOpenHashMap, Short2ObjectOpenCustomHashMap, Short2ObjectOpenHashMap, Short2ReferenceLinkedOpenHashMap, Short2ReferenceOpenCustomHashMap, Short2ReferenceOpenHashMap, Short2ShortLinkedOpenHashMap, Short2ShortOpenCustomHashMap, Short2ShortOpenHashMap, ShortLinkedOpenCustomHashSet, ShortLinkedOpenHashSet, ShortOpenCustomHashSet, ShortOpenHashSet

public interface Hash
Basic data for all hash-based classes.

Historical note

Warning: the following comments are here for historical reasons, and apply just to the double hash classes that can be optionally generated. The standard fastutil distribution since 6.1.0 uses linear-probing hash tables, and tables are always sized as powers of two.

The classes in fastutil are built around open-addressing hashing implemented via double hashing. Following Knuth's suggestions in the third volume of The Art of Computer Programming, we use for the table size a prime p such that p-2 is also prime. In this way hashing is implemented with modulo p, and secondary hashing with modulo p-2.

Entries in a table can be in three states: FREE, OCCUPIED or REMOVED. The naive handling of removed entries requires that you search for a free entry as if they were occupied. However, fastutil implements two useful optimizations, based on the following invariant:

Let i0, i1, …, ip-1 be the permutation of the table indices induced by the key k, that is, i0 is the hash of k and the following indices are obtained by adding (modulo p) the secondary hash plus one. If there is a OCCUPIED entry with key k, its index in the sequence above comes before the indices of any REMOVED entries with key k.

When we search for the key k we scan the entries in the sequence i0, i1, …, ip-1 and stop when k is found, when we finished the sequence or when we find a FREE entry. Note that the correctness of this procedure it is not completely trivial. Indeed, when we stop at a REMOVED entry with key k we must rely on the invariant to be sure that no OCCUPIED entry with the same key can appear later. If we insert and remove frequently the same entries, this optimization can be very effective (note, however, that when using objects as keys or values deleted entries are set to a special fixed value to optimize garbage collection).

Moreover, during the probe we keep the index of the first REMOVED entry we meet. If we actually have to insert a new element, we use that entry if we can, thus avoiding to pollute another FREE entry. Since this position comes a fortiori before any REMOVED entries with the same key, we are also keeping the invariant true.

  • Nested Class Summary

    Nested Classes 
    Modifier and Type Interface Description
    static interface  Hash.Strategy<K>
    A generic hash strategy.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int DEFAULT_GROWTH_FACTOR
    Deprecated.
    static int DEFAULT_INITIAL_SIZE
    The initial default size of a hash table.
    static float DEFAULT_LOAD_FACTOR
    The default load factor of a hash table.
    static float FAST_LOAD_FACTOR
    The load factor for a (usually small) table that is meant to be particularly fast.
    static byte FREE
    Deprecated.
    static byte OCCUPIED
    Deprecated.
    static int[] PRIMES
    Deprecated.
    static byte REMOVED
    Deprecated.
    static float VERY_FAST_LOAD_FACTOR
    The load factor for a (usually very small) table that is meant to be extremely fast.