Package gnu.kawa.util

Class IntHashTable


  • public class IntHashTable
    extends java.lang.Object
    A hash table that maps Object to int. This is a custom hash table optimised for Object-to-int maps. This is done to avoid unnecessary object allocation in the image set.
    See Also:
    OutPort
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int[] ints  
      protected int mask  
      protected int num_bindings  
      protected java.lang.Object[] objs  
    • Constructor Summary

      Constructors 
      Constructor Description
      IntHashTable()
      Construct an Object-to-int hash table.
      IntHashTable​(int capacity)
      Construct an Object-to-int hash table with a specified amount of mappings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all mappings from this map.
      int getFromIndex​(int index)
      Return the value stored at the specified index in the table.
      int hash​(java.lang.Object key)
      Compute the hash code of a given object.
      int lookup​(java.lang.Object key)
      Lookup a given key's value in the hash table.
      int lookup​(java.lang.Object key, int hash)
      Find either the index of a key's value, or the index of an available space.
      int putAtIndex​(java.lang.Object key, int value, int index)
      Associates the specified key with the specified value in this map.
      protected void rehash()
      Expand the hash table when it exceeds the load factor.
      int remove​(java.lang.Object key)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • objs

        protected java.lang.Object[] objs
      • ints

        protected int[] ints
      • mask

        protected int mask
      • num_bindings

        protected int num_bindings
    • Constructor Detail

      • IntHashTable

        public IntHashTable()
        Construct an Object-to-int hash table. The default size of the hash table is 64 mappings.
      • IntHashTable

        public IntHashTable​(int capacity)
        Construct an Object-to-int hash table with a specified amount of mappings.
        Parameters:
        capacity - The number of default mappings in this hash table.
    • Method Detail

      • hash

        public int hash​(java.lang.Object key)
        Compute the hash code of a given object.
        Parameters:
        key - The object whose hash code is to be computed.
        Returns:
        zero if the object is null, otherwise the identityHashCode
      • lookup

        public int lookup​(java.lang.Object key,
                          int hash)
        Find either the index of a key's value, or the index of an available space.
        Parameters:
        key - The key to whose value you want to find.
        hash - The hash code of this key.
        Returns:
        Either the index of the key's value, or an index pointing to unoccupied space.
      • lookup

        public int lookup​(java.lang.Object key)
        Lookup a given key's value in the hash table.
        Parameters:
        key - The key whose value you want to find.
        Returns:
        Either the index of the key's value, or an index pointing to unoccupied space.
      • getFromIndex

        public int getFromIndex​(int index)
        Return the value stored at the specified index in the table.
        Parameters:
        index - The index to inspect, as returned from lookup(java.lang.Object, int)
        Returns:
        A non-negative integer if the index contains a non-null value, or -1 if it does.
      • putAtIndex

        public int putAtIndex​(java.lang.Object key,
                              int value,
                              int index)
        Associates the specified key with the specified value in this map.
        Parameters:
        key - key with which the specified value is to be associated.
        value - value to be associated with the specified key.
        index - the index at which to place this binding, as returned from lookup(java.lang.Object, int).
        Returns:
        previous value associated with specified key, or -1 if there was no mapping for key.
      • remove

        public int remove​(java.lang.Object key)
      • rehash

        protected void rehash()
        Expand the hash table when it exceeds the load factor. Rehash the existing objects.
      • clear

        public void clear()
        Removes all mappings from this map.