|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectMyHashSet<T>
public class MyHashSet<T>
The MyHashSet API is similar to the Java Set interface. This collection is backed by a hash table.
| Field Summary | |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY
Unless otherwise specified, the table will start as an array of this length. |
static double |
LOAD_FACTOR
When the ratio of size/capacity reaches or exceeds this value, it is time for the table to be expanded |
| Constructor Summary | |
|---|---|
MyHashSet()
Initializes an empty table of length equal to DEFAULT_INITIAL_CAPACITY |
|
MyHashSet(int initialCapacity)
Initializes an empty table of the specified length (capacity). |
|
| Method Summary | |
|---|---|
void |
add(T element)
Adds the specified element to the collection. |
boolean |
contains(T element)
Looks for the specified element in the table. |
int |
getCapacity()
Returns the length of the table (the number of buckets). |
int |
getSize()
Returns the number of elements stored in the table. |
java.util.Iterator<T> |
iterator()
Returns an Iterator that can be used to iterate over all of the elements in the collection. |
void |
remove(T element)
Removes the specified element from the collection. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_INITIAL_CAPACITY
public static final double LOAD_FACTOR
| Constructor Detail |
|---|
public MyHashSet(int initialCapacity)
initialCapacity - initial length (capacity) of tablepublic MyHashSet()
| Method Detail |
|---|
public int getSize()
public int getCapacity()
public boolean contains(T element)
element - to be found
public void add(T element)
element - the element to be added to the collectionpublic void remove(T element)
element - the element to be removedpublic java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||