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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BucketizedHashtable()
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears this BucketizedHashtable so that it contains no key.Object
clone()
Creates and returns a shallow copy of this object.boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set
entrySet()
The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.boolean
equals(Object o)
Compares the specified object with this map for equality.Object
get(Object key)
int
hashCode()
boolean
isEmpty()
Set
keySet()
The return set is backed by the map, so changes to the map are reflected in the set, and vice-versa.Object
put(Object key, Object value)
Maps the specifiedkey
to the specifiedvalue
in this hashtable.void
putAll(Map t)
Object
remove(Object key)
Remove the key and its corresponding value.int
size()
String
toString()
Collection
values()
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
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
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 hashinginitialCapacity
- the initial capacity of BucketizedHashtableloadFactor
- 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 hashinginitialCapacity
- 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 Detail
-
put
public Object put(Object key, Object value)
Maps the specifiedkey
to the specifiedvalue
in this hashtable. Neither the key nor the value can benull
.
-
putAll
public void putAll(Map t)
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap
- 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 interfaceMap
- 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()
-
hashCode
public int hashCode()
-
isEmpty
public boolean isEmpty()
-
clear
public void clear()
Clears this BucketizedHashtable so that it contains no key.
-
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 interfaceMap
- 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 interfaceMap
- 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 interfaceMap
- 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.
-
clone
public Object clone()
Creates and returns a shallow copy of this object. The keys and values are not cloned.
-
-