Class BytesRefHash

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Releasable

    public final class BytesRefHash
    extends Object
    Specialized hash table implementation similar to Lucene's BytesRefHash that maps BytesRef values to ids. Collisions are resolved with open addressing and linear probing, growth is smooth thanks to BigArrays, hashes are cached for faster re-hashing and capacity is always a multiple of 2 for faster identification of buckets. This class is not thread-safe.
    • Constructor Detail

      • BytesRefHash

        public BytesRefHash​(long capacity,
                            BigArrays bigArrays)
      • BytesRefHash

        public BytesRefHash​(long capacity,
                            float maxLoadFactor,
                            BigArrays bigArrays)
    • Method Detail

      • get

        public BytesRef get​(long id,
                            BytesRef dest)
        Return the key at 0 <= index <= capacity(). The result is undefined if the slot is unused.

        Beware that the content of the BytesRef may become invalid as soon as close() is called

      • find

        public long find​(BytesRef key,
                         int code)
        Get the id associated with key
      • add

        public long add​(BytesRef key,
                        int code)
        Try to add key. Return its newly allocated id if it wasn't in the hash table yet, or -1-id if it was already present in the hash table.
      • removeAndAdd

        protected void removeAndAdd​(long index)
        Remove the entry at the given index and add it back
      • id

        public long id​(long index)
        Get the id associated with key at 0 <= index <= capacity() or -1 if this slot is unused.
      • id

        protected final long id​(long index,
                                long id)
      • resize

        protected void resize​(long capacity)
        Resize to the given capacity.
      • used

        protected boolean used​(long bucket)
      • capacity

        public long capacity()
        Return the number of allocated slots to store this hash table.
      • size

        public long size()
        Return the number of longs in this hash table.
      • grow

        protected final void grow()