Constructors Summary |
---|
public BucketizedHashtable(int bucketSize, int initialCapacity, float loadFactor)Constructs a new, empty BucketizedHashtable with the specified
bucket size, initial capacity and load factor.
if (bucketSize <= 0 || initialCapacity < 0) {
throw new IllegalArgumentException();
}
this.bucketSize = bucketSize;
hashtables = new Hashtable[bucketSize];
// always round up to the nearest integer so that it has at
// least the initialCapacity
int initialHashtableSize =
(int)Math.ceil((double)initialCapacity / bucketSize);
for (int i = 0; i < bucketSize; i++) {
hashtables[i] = new Hashtable(initialHashtableSize, loadFactor);
}
|
public BucketizedHashtable(int bucketSize, int initialCapacity)Constructs a new, empty BucketizedHashtable with the specified
bucket size, initial capacity and default load factor 0.75.
this(bucketSize, initialCapacity, 0.75f);
|
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.
this(bucketSize, 11 * bucketSize, 0.75f);
|
public BucketizedHashtable()Constructs a new, empty BucketizedHashtable with the default bucket
size 11, default initial capacity (11 * bucketSize)
and default load factor 0.75.
this(11, 11 * 11, 0.75f);
|
Methods Summary |
---|
public void | clear()Clears this BucketizedHashtable so that it contains no key.
for (int i = 0; i < bucketSize; i++) {
hashtables[i].clear();
}
|
public java.lang.Object | clone()Creates and returns a shallow copy of this object.
The keys and values are not cloned.
try {
BucketizedHashtable bt = (BucketizedHashtable)super.clone();
bt.bucketSize = bucketSize;
bt.hashtables = new Hashtable[bucketSize];
for (int i = 0; i < bucketSize; i++) {
bt.hashtables[i] = (Hashtable)hashtables[i].clone();
}
return bt;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
|
public boolean | containsKey(java.lang.Object key)
return hashtables[getBucketIndex(key)].containsKey(key);
|
public boolean | containsValue(java.lang.Object value)
for (int i = 0; i < bucketSize; i++) {
if (hashtables[i].containsValue(value)) {
return true;
}
}
return false;
|
public java.util.Set | entrySet()The return set is backed by the map, so changes to the map are
reflected in the set, and vice-versa.
if (bucketSize == 1) {
return hashtables[0].entrySet();
} else {
throw new UnsupportedOperationException();
}
|
public boolean | equals(java.lang.Object o)Compares the specified object with this map for equality.
if (o == this) {
return true;
}
if (!(o instanceof BucketizedHashtable)) {
return false;
}
BucketizedHashtable bt = (BucketizedHashtable)o;
if (bt.bucketSize != bucketSize || bt.size() != size()) {
return false;
}
for (int i = 0; i < bucketSize; i++) {
if (!hashtables[i].equals(bt.hashtables[i])) {
return false;
}
}
return true;
|
public java.lang.Object | get(java.lang.Object key)
return hashtables[getBucketIndex(key)].get(key);
|
private int | getBucketIndex(java.lang.Object key)
int index = key.hashCode() % bucketSize;
return (index >= 0) ? index : index + bucketSize;
|
public int | hashCode()
int h = 0;
for (int i = 0; i < bucketSize; i++) {
h += hashtables[i].hashCode();
}
return h;
|
public boolean | isEmpty()
for (int i = 0; i < bucketSize; i++) {
if (!hashtables[i].isEmpty()) {
return false;
}
}
return true;
|
public java.util.Set | keySet()The return set is backed by the map, so changes to the map are
reflected in the set, and vice-versa.
if (bucketSize == 1) {
return hashtables[0].keySet();
} else {
throw new UnsupportedOperationException();
}
|
public java.lang.Object | put(java.lang.Object key, java.lang.Object value)Maps the specified key to the specified
value in this hashtable. Neither the key nor the
value can be null .
return hashtables[getBucketIndex(key)].put(key, value);
|
public void | putAll(java.util.Map t)
if (t instanceof BucketizedHashtable) {
BucketizedHashtable bt = (BucketizedHashtable)t;
for (int i = 0; i < bt.bucketSize; i++) {
putAllFromMapWithEntrySet(bt.hashtables[i]);
}
} else {
putAllFromMapWithEntrySet(t);
}
|
private void | putAllFromMapWithEntrySet(java.util.Map t)
Iterator iter = t.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry e = (Map.Entry)iter.next();
put(e.getKey(), e.getValue());
}
|
public java.lang.Object | remove(java.lang.Object key)Remove the key and its corresponding value.
return hashtables[getBucketIndex(key)].remove(key);
|
public int | size()
int totalSize = 0;
for (int i = 0; i < bucketSize; i++) {
totalSize += hashtables[i].size();
}
return totalSize;
|
public java.lang.String | toString()
StringBuffer buf = new StringBuffer("["); // NOI18N
//bucketSize always >= 1
buf.append(hashtables[0].toString());
for (int i = 1; i < bucketSize; i++) {
buf.append(", "); // NOI18N
buf.append(hashtables[i].toString());
}
buf.append("]"); // NOI18N
return buf.toString();
|
public java.util.Collection | values()The return collection is backed by the map, so changes to the map
are reflected in the collection, and vice-versa.
if (bucketSize == 1) {
return hashtables[0].values();
} else {
throw new UnsupportedOperationException();
}
|