|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.AbstractCollection | +--java.util.AbstractSet | +--HashSetLinear
This class implements a hash set with linear probing. It extends
AbstractSet
, with a implementations of
add()
, remove()
, size()
and iterator()
. The iterator supports
hasNext()
, next()
, and remove()
.
The element null
cannot be stored in a
HashSetLinear
.
The iterators returned by this version of HashSetLinear
are "failsafe": this is implemented by maintaining a modification
counter. The Math 176 homework solutions do not need to support this
feature.
One novel feature of this implementation is that it supports active deletion (which is not generally used with linear probing).
The objects in the set must support equals() and hashCode(). Two objects which test as being equal should have the same hash code. Otherwise, unpredictable results may occur.
Constructor Summary | |
HashSetLinear()
This constuctor creates a new, empty HashSetLinear
with an initial capacity
of 101 and a load factor of 0.50. |
|
HashSetLinear(int initialCapacity)
This constuctor creates a new, empty HashSetLinear
with a specified initial capacity
and the default load factor of 0.50. |
|
HashSetLinear(int initialCapacity,
float loadFactor)
This constuctor creates a new, empty HashSetLinear
with a specified initial capacity
and a specified load factor. |
Method Summary | |
boolean |
add(java.lang.Object o)
Add an object to the set stored in the HashTableLinear. |
void |
clear()
Removes all the elements from the set (not necessary for Math 176 homework). |
boolean |
contains(java.lang.Object o)
Check whether an object is present in the hash table |
java.lang.Object |
getRandomElement(java.lang.Object avoidObject)
Returns a more-or-less randomly chosen element in the hash table. |
java.util.Iterator |
iterator()
Create an iterator for the HashTableLinear set |
boolean |
remove(java.lang.Object o)
Remove an object from the set stored in the HashTableLinear. |
int |
size()
Return the number of elements in the hash table |
Methods inherited from class java.util.AbstractSet |
equals,
hashCode |
Methods inherited from class java.util.AbstractCollection |
addAll,
containsAll,
isEmpty,
removeAll,
retainAll,
toArray,
toArray,
toString |
Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
Constructor Detail |
public HashSetLinear()
HashSetLinear
with an initial capacity
of 101 and a load factor of 0.50.public HashSetLinear(int initialCapacity)
HashSetLinear
with a specified initial capacity
and the default load factor of 0.50.initialCapacity
- inital size of the hash tablepublic HashSetLinear(int initialCapacity, float loadFactor)
HashSetLinear
with a specified initial capacity
and a specified load factor. The hash set will be resized whenever
the number of elements exceeds the size of the hashtable times the load factor.
The present implementation never resizes downwards.initialCapacity
- inital size of the hash tableloadFactor
- the load factor: not recommended to be higher than 0.75.Method Detail |
public java.util.Iterator iterator()
public int size()
public boolean contains(java.lang.Object o)
o
- The Object whose presence is being checked.public boolean add(java.lang.Object o)
o
- the Object to be added.public boolean remove(java.lang.Object o)
o
- the Object to be removedpublic void clear()
public java.lang.Object getRandomElement(java.lang.Object avoidObject)
avoidObject
- if non-null, this object is never returned.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |