Package gnu.kawa.util

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

  • All Implemented Interfaces:
    java.util.Map<K,​V>
    Direct Known Subclasses:
    AbstractWeakHashTable, GeneralHashTable, Namespace, WeakIdentityHashMap

    public abstract class AbstractHashTable<Entry extends java.util.Map.Entry<K,​V>,​K,​V>
    extends java.util.AbstractMap<K,​V>
    An abstract hash map from K to V. The entries are represented by an Entry type parameter.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract Entry[] allocEntries​(int n)
      Allocate Entry[n].
      void clear()  
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      V get​(java.lang.Object key)
      Find value for given key.
      V get​(java.lang.Object key, V defaultValue)
      Find value for given key.
      protected abstract int getEntryHashCode​(Entry entry)
      Extract hash-code from Entry.
      protected abstract Entry getEntryNext​(Entry entry)
      Extract next Entry in same hash-bucket.
      Entry getNode​(java.lang.Object key)
      Find Entry for given key.
      V getOrDefault​(java.lang.Object key, V defaultValue)  
      int hash​(java.lang.Object key)
      Calculate hash code of a key.
      protected int hashToIndex​(int hash)
      Map hash-code to bucket index in table.
      protected abstract Entry makeEntry​(K key, int hash, V value)
      Allocate a new node in the hash table.
      protected boolean matches​(java.lang.Object key, int hash, Entry node)
      True if an Entry matches a key.
      protected boolean matches​(K key1, java.lang.Object key2)
      Compare two keys for equivalence.
      V put​(K key, int hash, V value)  
      V put​(K key, V value)  
      protected void rehash()  
      V remove​(java.lang.Object key)  
      protected abstract void setEntryNext​(Entry entry, Entry next)
      Set next Entry in same hash-bucket.
      int size()  
      • Methods inherited from class java.util.AbstractMap

        clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • table

        protected Entry extends java.util.Map.Entry<K,​V>[] table
      • 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​(java.lang.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​(java.lang.Object key,
                                  int hash,
                                  Entry node)
        True if an Entry matches a key.
      • matches

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

        public V get​(java.lang.Object key)
        Find value for given key. Return null if not found.
        Specified by:
        get in interface java.util.Map<Entry extends java.util.Map.Entry<K,​V>,​K>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • getNode

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

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

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

        protected void rehash()
      • put

        public V put​(K key,
                     V value)
        Specified by:
        put in interface java.util.Map<Entry extends java.util.Map.Entry<K,​V>,​K>
        Overrides:
        put in class java.util.AbstractMap<K,​V>
      • put

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

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<Entry extends java.util.Map.Entry<K,​V>,​K>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<Entry extends java.util.Map.Entry<K,​V>,​K>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<Entry extends java.util.Map.Entry<K,​V>,​K>
        Overrides:
        size in class java.util.AbstractMap<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<Entry extends java.util.Map.Entry<K,​V>,​K>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>