Class LongHashMap<V>

java.lang.Object
com.polytechnik.utils.LongHashMap<V>
Direct Known Subclasses:
LongTreeValueMapTest

public class LongHashMap<V> extends Object
This is a copy of java.util.HashMap which uses longs as keys instead of Objects. It turns out that using this in the PageCache implementation speeds up heap traversals by a factor of three.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final boolean
     
    (package private) final float
    The load factor for the hash table.
    (package private) int
    The number of times this HashMap has been structurally modified Structural modifications are those that change the number of mappings in the HashMap or otherwise modify its internal structure (e.g., rehash).
    (package private) int
    The total number of mappings in the hash table.
    private static final char[]
     
    (package private) LongHashMap.Entry<V>[]
    The hash table data.
    (package private) int
    The table is rehashed when its size exceeds this threshold.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty map with a default capacity and load factor, which is 0.75.
    LongHashMap(int initialCapacity)
    Constructs a new, empty map with the specified initial capacity and default load factor, which is 0.75.
    LongHashMap(int initialCapacity, float loadFactor)
    Constructs a new, empty map with the specified initial capacity and the specified load factor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all mappings from this map.
    private static int
     
    final boolean
    containsKey(long key)
    Returns true if this map contains a mapping for the specified key.
    int
    copyKeys(long[] keylist)
     
    int
    copyKeysAndValues(long[] keylist, V[] valuesarr)
     
    int
    copyValues(V[] valuesarr)
     
    boolean
    Executes procedure for each key/value entry in the map.
    boolean
    forEachEntry(Predicate<V> procedure)
     
    final V
    get(long key)
    Returns the value to which this map maps the specified key.
    (package private) final LongHashMap.Entry<V>
    getEntry(long key)
    Returns the entry associated with the specified key in the HashMap.
    final boolean
    Returns true if this map contains no key-value mappings.
    static void
    main(String[] args)
     
    put(long key, V value)
    Associates the specified value with the specified key in this map.
    private static byte[]
    randombytes(int n)
     
    private static Long
    randomLongk(int i)
     
    private static String
    randomstring(int n)
     
    private static String
     
    (package private) void
    Rehashes the contents of this map into a new HashMap instance with a larger capacity.
    remove(long key)
    Removes the mapping for this key from this map if present.
    (package private) final LongHashMap.Entry<V>
    Removes and returns the entry associated with the specified key in the HashMap.
    final int
    Returns the number of key-value mappings in this map.
    private static int
     

    Methods inherited from class java.lang.Object

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

    • table

      transient LongHashMap.Entry<V>[] table
      The hash table data.
    • size

      transient int size
      The total number of mappings in the hash table.
    • threshold

      int threshold
      The table is rehashed when its size exceeds this threshold. (The value of this field is (int)(capacity * loadFactor).)
    • loadFactor

      final float loadFactor
      The load factor for the hash table.
    • modCount

      transient int modCount
      The number of times this HashMap has been structurally modified Structural modifications are those that change the number of mappings in the HashMap or otherwise modify its internal structure (e.g., rehash). This field is used to make iterators on Collection-views of the HashMap fail-fast. (See ConcurrentModificationException).
    • SYMBOLS64

      private static final char[] SYMBOLS64
    • DEBUG_TEST

      private static final boolean DEBUG_TEST
      See Also:
  • Constructor Details

    • LongHashMap

      public LongHashMap(int initialCapacity, float loadFactor)
      Constructs a new, empty map with the specified initial capacity and the specified load factor.
      Parameters:
      initialCapacity - the initial capacity of the HashMap.
      loadFactor - the load factor of the HashMap
      Throws:
      IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.
    • LongHashMap

      public LongHashMap(int initialCapacity)
      Constructs a new, empty map with the specified initial capacity and default load factor, which is 0.75.
      Parameters:
      initialCapacity - the initial capacity of the HashMap.
      Throws:
      IllegalArgumentException - if the initial capacity is less than zero.
    • LongHashMap

      public LongHashMap()
      Constructs a new, empty map with a default capacity and load factor, which is 0.75.
  • Method Details

    • size

      public final int size()
      Returns the number of key-value mappings in this map.
      Returns:
      the number of key-value mappings in this map.
    • isEmpty

      public final boolean isEmpty()
      Returns true if this map contains no key-value mappings.
      Returns:
      true if this map contains no key-value mappings.
    • get

      public final V get(long key)
      Returns the value to which this map maps the specified key. Returns null if the map contains no mapping for this key. A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.
      Parameters:
      key - key whose associated value is to be returned.
      Returns:
      the value to which this map maps the specified key.
    • containsKey

      public final boolean containsKey(long key)
      Returns true if this map contains a mapping for the specified key.
      Parameters:
      key - key whose presence in this Map is to be tested.
      Returns:
      true if this map contains a mapping for the specified key.
    • getEntry

      final LongHashMap.Entry<V> getEntry(long key)
      Returns the entry associated with the specified key in the HashMap. Returns null if the HashMap contains no mapping for this key.
    • put

      public V put(long key, V value)
      Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.
      Parameters:
      key - key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the HashMap previously associated null with the specified key.
    • remove

      public V remove(long key)
      Removes the mapping for this key from this map if present.
      Parameters:
      key - key whose mapping is to be removed from the map.
      Returns:
      previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.
    • removeEntryForKey

      final LongHashMap.Entry<V> removeEntryForKey(long key)
      Removes and returns the entry associated with the specified key in the HashMap. Returns null if the HashMap contains no mapping for this key.
    • clear

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

      void rehash()
      Rehashes the contents of this map into a new HashMap instance with a larger capacity. This method is called automatically when the number of keys in this map exceeds its capacity and load factor.
    • copyValues

      public int copyValues(V[] valuesarr)
    • copyKeys

      public int copyKeys(long[] keylist)
    • copyKeysAndValues

      public int copyKeysAndValues(long[] keylist, V[] valuesarr)
    • forEachEntry

      public boolean forEachEntry(LongHashMap.TLongObjectProcedure<V> procedure)
      Executes procedure for each key/value entry in the map.
      Parameters:
      procedure - - a LongObjectProcedure value.
      Returns:
      false if the loop over the entries terminated because the procedure returned false for some entry.
    • forEachEntry

      public boolean forEachEntry(Predicate<V> procedure)
    • randombytes

      private static byte[] randombytes(int n)
    • randomstring

      private static String randomstring(int n)
    • randomLongk

      private static Long randomLongk(int i)
    • randomStringk

      private static String randomStringk(int i)
    • comparisontest_hashmap

      private static int comparisontest_hashmap()
    • test_the_same

      private static int test_the_same(String comment, LongHashMap<String> m, HashMap<Long,String> hm)
    • main

      public static void main(String[] args)