Package gnu.kawa.util

Class AbstractHashTable<Entry extends Map.Entry<K,​V>,​K,​V>

    • Field Detail

      • mask

        protected int mask
      • num_bindings

        protected int num_bindings
    • Constructor Detail

      • AbstractHashTable

        public AbstractHashTable()
      • AbstractHashTable

        public AbstractHashTable​(int capacity)
    • Method Detail

      • getEntryHashCode

        protected abstract int getEntryHashCode​(Entry entry)
        Extract hash-code from Entry.
      • getEntryNext

        protected abstract Entry getEntryNext​(Entry entry)
        Extract next Entry in same hash-bucket.
      • setEntryNext

        protected abstract void setEntryNext​(Entry entry,
                                             Entry next)
        Set next Entry in same hash-bucket.
      • allocEntries

        protected abstract Entry[] allocEntries​(int n)
        Allocate Entry[n].
      • makeEntry

        protected abstract Entry makeEntry​(K key,
                                           int hash,
                                           V value)
        Allocate a new node in the hash table.
      • hash

        public int hash​(Object key)
        Calculate hash code of a key.
      • hashToIndex

        protected int hashToIndex​(int hash)
        Map hash-code to bucket index in table.
      • matches

        protected boolean matches​(Object key,
                                  int hash,
                                  Entry node)
        True if an Entry matches a key.
      • matches

        protected boolean matches​(K key1,
                                  Object key2)
        Compare two keys for equivalence. Override this and the hash(Object) method if you want a different equivalence relation.
      • getNode

        public Entry getNode​(Object key)
        Find Entry for given key. Return null if not found.
      • get

        public V get​(Object key,
                     V defaultValue)
        Find value for given key. Return defaultValue if not found.
      • getOrDefault

        public V getOrDefault​(Object key,
                              V defaultValue)
      • rehash

        protected void rehash()
      • put

        public V put​(K key,
                     int hash,
                     V value)