|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdata_structures.HashTable<K,V>
data_structures.DHashTable<K,V>
K
- the type of object that will act as keys for the hash tableV
- the type of object that is being stored in the hash tablepublic class DHashTable<K,V>
A simple dynamic HashTable
.
In general, the time for each operation is as follows:
Field Summary |
---|
Fields inherited from class data_structures.HashTable |
---|
DEFAULT_EXPANSION_FACTOR, DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR_THRESHOLD, size, table |
Constructor Summary | |
---|---|
|
DHashTable()
Construct an empty dynamic hash table. |
protected |
DHashTable(int size,
data_structures.HashTable.Node<K,V>[] table)
Construct a dynamic hash table with a given number of mappings and given set of buckets. |
|
DHashTable(K[] keys,
V[] values)
Construct a dynamic hash table which initially contains mappings for a given set of keys and values. |
Method Summary | |
---|---|
DHashTable<K,V> |
add(K[] keys,
V[] values)
Add multiple key/value mappings to the dynamic hash table. |
DHashTable<K,V> |
add(K key,
V value)
Add a key/value mapping to the dynamic hash table. |
DHashTable<K,V> |
addEquals(K[] keys,
V[] values)
Add multiple key/value mappings to the dynamic hash table. |
DHashTable<K,V> |
addEquals(K key,
V value)
Add a key/value mapping to the dynamic hash table. |
DHashTable<K,V> |
clone()
Return a deep copy of the dynamic hash table. |
boolean |
equals(java.lang.Object other)
Check if this hash table is the same as another. |
V |
get(K key)
Return the value mapped to a given key. |
V |
getEquals(K key)
Return the value mapped to a given key. |
protected float |
getLoadFactor()
Return the load factor of the dynamic hash table. |
java.util.Iterator<K> |
keys()
Return an Iterator that will yield all the keys in the dynamic hash table. |
DHashTable<K,V> |
remove(K key)
Remove a key/value mapping from the dynamic hash table. |
DHashTable<K,V> |
remove(K[] keys)
Remove multiple key/value mappings from the dynamic hash table. |
DHashTable<K,V> |
removeEquals(K key)
Remove a key/value mapping from the dynamic hash table. |
DHashTable<K,V> |
removeEquals(K[] keys)
Remove multiple key/value mappings from the dynamic hash table. |
int |
size()
Return the number of mappings in the dynamic hash table. |
java.lang.String |
toString()
Return a string representation of this hash table and all its elements. |
java.util.Iterator<V> |
values()
Return an Iterator that will yield all the values in the dynamic hash table. |
Methods inherited from class data_structures.HashTable |
---|
cloneTable, getBucket, rehash, rehash |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected DHashTable(int size, data_structures.HashTable.Node<K,V>[] table)
Construct a dynamic hash table with a given number of mappings and given set of buckets.
size
- the number of mappings in the hash tabletable
- the bucketspublic DHashTable()
Construct an empty dynamic hash table.
public DHashTable(K[] keys, V[] values)
Construct a dynamic hash table which initially contains mappings for a given set of keys and values.
Mappings are added as if using add(K, V)
.
keys
- the objects which can be used to retrieve the valuesvalues
- the objects to be retrieved using the keys
java.lang.ArrayIndexOutOfBoundsException
- if the array of keys is not the same length as the array of valuesMethod Detail |
---|
protected final float getLoadFactor()
Return the load factor of the dynamic hash table.
The load factor is defined as the number of mapping divided by the number of buckets.
getLoadFactor
in class HashTable<K,V>
public int size()
Return the number of mappings in the dynamic hash table.
size
in class HashTable<K,V>
public DHashTable<K,V> add(K key, V value)
Add a key/value mapping to the dynamic hash table. If a mapping exists whose key is ==
to this key, it is replaced.
add
in class HashTable<K,V>
key
- the object which can be used to retrieve the valuevalue
- the object to be retrieved using the key
public DHashTable<K,V> add(K[] keys, V[] values)
Add multiple key/value mappings to the dynamic hash table. If mappings exist whose keys are ==
to the given keys, they are replaced.
add
in class HashTable<K,V>
keys
- the objects which can be used to retrieve the valuesvalues
- the objects to be retrieved using the keys
java.lang.ArrayIndexOutOfBoundsException
- if the array of keys is not the same length as the array of valuespublic DHashTable<K,V> addEquals(K key, V value)
Add a key/value mapping to the dynamic hash table. If a mapping exists whose key Object.equals(java.lang.Object)
this key, it is replaced.
addEquals
in class HashTable<K,V>
key
- the object which can be used to retrieve the valuevalue
- the object to be retrieved using the key
public DHashTable<K,V> addEquals(K[] keys, V[] values)
Add multiple key/value mappings to the dynamic hash table. If mappings exist whose keys are Object.equals(java.lang.Object)
to the given keys, they are replaced.
addEquals
in class HashTable<K,V>
keys
- the objects which can be used to retrieve the valuesvalues
- the objects to be retrieved using the keys
java.lang.ArrayIndexOutOfBoundsException
- if the array of keys is not the same length as the array of valuespublic V get(K key)
Return the value mapped to a given key. Keys are searched using ==
.
get
in class HashTable<K,V>
key
- the object that was mapped to the desired value
public V getEquals(K key)
Return the value mapped to a given key. Keys are searched using Object.equals(java.lang.Object)
.
getEquals
in class HashTable<K,V>
key
- the object that was mapped to the desired value
public DHashTable<K,V> remove(K key)
Remove a key/value mapping from the dynamic hash table. Keys are searched using ==
.
remove
in class HashTable<K,V>
key
- the key of the key/value mapping to be removed
public DHashTable<K,V> remove(K[] keys)
Remove multiple key/value mappings from the dynamic hash table. Keys are searched using ==
.
remove
in class HashTable<K,V>
keys
- the keys of the key/value mappings to be removed
public DHashTable<K,V> removeEquals(K key)
Remove a key/value mapping from the dynamic hash table. Keys are searched using Object.equals(java.lang.Object)
.
removeEquals
in class HashTable<K,V>
key
- the key of the key/value mapping to be removed
public DHashTable<K,V> removeEquals(K[] keys)
Remove multiple key/value mappings from the dynamic hash table. Keys are searched using Object.equals(java.lang.Object)
.
removeEquals
in class HashTable<K,V>
keys
- the keys of the key/value mappings to be removed
public java.util.Iterator<K> keys()
Return an Iterator
that will yield all the keys in the dynamic hash table.
keys
in class HashTable<K,V>
public java.util.Iterator<V> values()
Return an Iterator
that will yield all the values in the dynamic hash table.
values
in class HashTable<K,V>
public boolean equals(java.lang.Object other)
Check if this hash table is the same as another.
Two hash tables are considered the same if they contain the same key/value mappings. Keys and values are compared using Object.equals(java.lang.Object)
.
The class of the hash table is not taken into account. In other words, a DHashTable
can be equal to an SHashTable
if they contain the same key/value mappings.
equals
in class HashTable<K,V>
other
- another hash table
public DHashTable<K,V> clone()
Return a deep copy of the dynamic hash table.
The clone hash table can be modified without affecting the original.
clone
in class HashTable<K,V>
public java.lang.String toString()
Return a string representation of this hash table and all its elements.
toString
in class HashTable<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |