Class BucketizedHashtable

java.lang.Object
com.sun.jdo.spi.persistence.utility.BucketizedHashtable
All Implemented Interfaces:
Serializable, Cloneable, Map

public class BucketizedHashtable extends Object implements Cloneable, Map, Serializable
This class implements bucketize hashtable, which subdivide the key collection stored into several hashtables (buckets) of smaller size. This will reduce the contention of hashtable.
Author:
Shing Wai Chan
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface java.util.Map

    Map.Entry<K,V>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty BucketizedHashtable with the default bucket size 11, default initial capacity (11 * bucketSize) and default load factor 0.75.
    BucketizedHashtable(int bucketSize)
    Constructs a new, empty BucketizedHashtable with the specified bucket size, default initial capacity (11 * bucketSize) and default load factor 0.75.
    BucketizedHashtable(int bucketSize, int initialCapacity)
    Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and default load factor 0.75.
    BucketizedHashtable(int bucketSize, int initialCapacity, float loadFactor)
    Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and load factor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears this BucketizedHashtable so that it contains no key.
    Creates and returns a shallow copy of this object.
    boolean
     
    boolean
     
    The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
    boolean
    Compares the specified object with this map for equality.
    get(Object key)
     
    int
     
    boolean
     
    The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
    put(Object key, Object value)
    Maps the specified key to the specified value in this hashtable.
    void
     
    Remove the key and its corresponding value.
    int
     
     
    The return collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BucketizedHashtable

      public BucketizedHashtable(int bucketSize, int initialCapacity, float loadFactor)
      Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and load factor.
      Parameters:
      bucketSize - the number of buckets used for hashing
      initialCapacity - the initial capacity of BucketizedHashtable
      loadFactor - the load factor of hashtable
    • BucketizedHashtable

      public BucketizedHashtable(int bucketSize, int initialCapacity)
      Constructs a new, empty BucketizedHashtable with the specified bucket size, initial capacity and default load factor 0.75.
      Parameters:
      bucketSize - the number of buckets used for hashing
      initialCapacity - the initial capacity of hashtable
    • BucketizedHashtable

      public BucketizedHashtable(int bucketSize)
      Constructs a new, empty BucketizedHashtable with the specified bucket size, default initial capacity (11 * bucketSize) and default load factor 0.75.
      Parameters:
      bucketSize - the number of buckets used for hashing
    • BucketizedHashtable

      public BucketizedHashtable()
      Constructs a new, empty BucketizedHashtable with the default bucket size 11, default initial capacity (11 * bucketSize) and default load factor 0.75.
  • Method Details

    • get

      public Object get(Object key)
      Specified by:
      get in interface Map
      Parameters:
      key - a key in the hashtable
      Returns:
      the value to which the specified key is mapped.
    • remove

      public Object remove(Object key)
      Remove the key and its corresponding value.
      Specified by:
      remove in interface Map
      Parameters:
      key - the key that needs to be removed
      Returns:
      the value to which the key had been mapped, or null if the key did not have a mapping.
    • put

      public Object put(Object key, Object value)
      Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null.

      Specified by:
      put in interface Map
      Parameters:
      key - the hashtable key
      value - the value
      Returns:
      the previous value of the specified key in hashtables, or null if it did not have one.
    • putAll

      public void putAll(Map t)
      Specified by:
      putAll in interface Map
      Parameters:
      t - BucketizedHashtable or a Map with a supported operation entrySet
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map
      Parameters:
      key - possible key
      Returns:
      true if and only if the specified object is a key in one of of the hashtables
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map
      Parameters:
      value - possible value
      Returns:
      true if and only if the specified object is a value in one of of the hashtables
    • size

      public int size()
      Specified by:
      size in interface Map
      Returns:
      the total number of key-value mappings of all buckets
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Map
      Overrides:
      hashCode in class Object
      Returns:
      the hash code value for this map
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map
      Returns:
      true if this map contains no key-value mappings
    • clear

      public void clear()
      Clears this BucketizedHashtable so that it contains no key.
      Specified by:
      clear in interface Map
    • entrySet

      public Set entrySet()
      The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
      Specified by:
      entrySet in interface Map
      Returns:
      a set of Map.Entry when bucketSet equal 1
      Throws:
      UnsupportedOperationException - when bucketSize is greater one
    • keySet

      public Set keySet()
      The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.
      Specified by:
      keySet in interface Map
      Returns:
      a set of keys when bucketSet equal 1
      Throws:
      UnsupportedOperationException - when bucketSize is greater one
    • values

      public Collection values()
      The return collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa.
      Specified by:
      values in interface Map
      Returns:
      a collection of values when bucketSet equal 1
      Throws:
      UnsupportedOperationException - when bucketSize is greater one
    • equals

      public boolean equals(Object o)
      Compares the specified object with this map for equality.
      Specified by:
      equals in interface Map
      Overrides:
      equals in class Object
      Returns:
      true if the specified object is a BucketizedHashtable with hashtables represent the same set of mappings.
    • clone

      public Object clone()
      Creates and returns a shallow copy of this object. The keys and values are not cloned.
      Overrides:
      clone in class Object
      Returns:
      a clone of BucketizedHashtable
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representation of this BucketizedHashtable