|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsdds.HashTable<K,V>
sdds.SHashTable<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 SHashTable<K,V>
A simple static HashTable
.
In general, the time for each operation is as follows:
Field Summary |
---|
Fields inherited from class sdds.HashTable |
---|
DEFAULT_EXPANSION_FACTOR, DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR_THRESHOLD, size, table |
Constructor Summary | |
---|---|
|
SHashTable()
Construct an empty static hash table. |
protected |
SHashTable(int size,
sdds.HashTable.Node<K,V>[] table)
Construct a static hash table with a given number of mappings and given set of buckets. |
|
SHashTable(K[] keys,
V[] values)
Construct a static hash table which initially contains mappings for a given set of keys and values. |
Method Summary | |
---|---|
SHashTable<K,V> |
add(K[] keys,
V[] values)
Add multiple key/value mappings to the static hash table. |
SHashTable<K,V> |
add(K key,
V value)
Add a key/value mapping to the static hash table. |
SHashTable<K,V> |
addEquals(K[] keys,
V[] values)
Add multiple key/value mappings to the static hash table. |
SHashTable<K,V> |
addEquals(K key,
V value)
Add a key/value mapping to the static hash table. |
SHashTable<K,V> |
clone()
Return a deep copy of the static hash table. |
protected SHashTable<K,V> |
makeHashTable(int size,
sdds.HashTable.Node<K,V>[] table)
This protected method is used instead of a constructor to create new hash tables when this hash table is modified. |
SHashTable<K,V> |
remove(K key)
Remove a key/value mapping from the static hash table. |
SHashTable<K,V> |
remove(K[] keys)
Remove multiple key/value mappings from the static hash table. |
SHashTable<K,V> |
removeEquals(K key)
Remove a key/value mapping from the static hash table. |
SHashTable<K,V> |
removeEquals(K[] keys)
Remove multiple key/value mappings from the static hash table. |
Methods inherited from class sdds.HashTable |
---|
cloneTable, equals, get, getBucket, getEquals, getLoadFactor, keys, rehash, rehash, size, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected SHashTable(int size, sdds.HashTable.Node<K,V>[] table)
Construct a static hash table with a given number of mappings and given set of buckets.
size
- the number of mappings in the hash tabletable
- the bucketspublic SHashTable()
Construct an empty static hash table.
public SHashTable(K[] keys, V[] values)
Construct a static hash table which initially contains mappings for a given set of keys and values.
Mappings are added as if using add(K, V)
.
This constructor is more efficient in both time and space than creating an empty static hash table and then adding the key/value mappings.
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 SHashTable<K,V> makeHashTable(int size, sdds.HashTable.Node<K,V>[] table)
This protected method is used instead of a constructor to create new hash tables when this hash table is modified.
All subclasses of SHashTable should use this method instead of a constructor.
This method can be overridden in a subclass and made to return objects of the subclass's type.
This avoids the new to re-write the modifying methods such as add(K, V)
and remove(K)
in every subclass.
size
- the number of mappings in the hash tabletable
- the bucketspublic SHashTable<K,V> add(K key, V value)
Add a key/value mapping to the static 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 SHashTable<K,V> add(K[] keys, V[] values)
Add multiple key/value mappings to the static hash table. If mappings exist whose keys are ==
to the given keys, they are replaced.
This method is more efficient in both time and space than making multiple calls to add(K, V)
.
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 SHashTable<K,V> addEquals(K key, V value)
Add a key/value mapping to the static 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 SHashTable<K,V> addEquals(K[] keys, V[] values)
Add multiple key/value mappings to the static hash table. If mappings exist whose keys are Object.equals(java.lang.Object)
to the given keys, they are replaced.
This method is more efficient in both time and space than multiple calls to addEquals(K, V)
.
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 SHashTable<K,V> remove(K key)
Remove a key/value mapping from the static hash table. Keys are searched using ==
.
remove
in class HashTable<K,V>
key
- the key of the key/value mapping to be removed
public SHashTable<K,V> remove(K[] keys)
Remove multiple key/value mappings from the static hash table. Keys are searched using ==
.
This method is more efficient in both time and space than multiple calls to remove(K)
.
remove
in class HashTable<K,V>
keys
- the keys of the key/value mappings to be removed
public SHashTable<K,V> removeEquals(K key)
Remove a key/value mapping from the static 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 SHashTable<K,V> removeEquals(K[] keys)
Remove multiple key/value mappings from the static hash table. Keys are searched using Object.equals(java.lang.Object)
.
This method is more efficient in both time and space than multiple calls to removeEquals(K)
.
removeEquals
in class HashTable<K,V>
keys
- the keys of the key/value mappings to be removed
public SHashTable<K,V> clone()
Return a deep copy of the static hash table.
The clone hash table can be modified without affecting the original.
clone
in class HashTable<K,V>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |