chord.util
Class ArraySet<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by chord.util.ArraySet<T>
Type Parameters:
T - The type of objects in the set.
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess, java.util.Set<T>

public class ArraySet<T>
extends java.util.ArrayList<T>
implements java.util.Set<T>

Array-based implementation of a set.

Provides O(n) membership testing as opposed to O(1) provided by a hash set.

This implementation must be used for small sets for which its O(n) membership testing penalty is less than the overhead of creating and maintaining a hash set.

Author:
Mayur Naik (mhn@cs.stanford.edu)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArraySet()
           
ArraySet(java.util.Collection<T> s)
           
ArraySet(int initialCapacity)
           
 
Method Summary
 boolean add(T e)
           
 boolean addAll(java.util.Collection<? extends T> c)
           
 void addForcibly(T e)
          Adds a given value to the set without checking if it already exists in the set.
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
 
Methods inherited from class java.util.ArrayList
add, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface java.util.List
containsAll, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

ArraySet

public ArraySet(java.util.Collection<T> s)

ArraySet

public ArraySet()

ArraySet

public ArraySet(int initialCapacity)
Method Detail

add

public boolean add(T e)
Specified by:
add in interface java.util.Collection<T>
Specified by:
add in interface java.util.List<T>
Specified by:
add in interface java.util.Set<T>
Overrides:
add in class java.util.ArrayList<T>

addForcibly

public void addForcibly(T e)
Adds a given value to the set without checking if it already exists in the set.

Parameters:
e - A value to be added to the set.

addAll

public boolean addAll(java.util.Collection<? extends T> c)
Specified by:
addAll in interface java.util.Collection<T>
Specified by:
addAll in interface java.util.List<T>
Specified by:
addAll in interface java.util.Set<T>
Overrides:
addAll in class java.util.ArrayList<T>

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection<T>
Specified by:
equals in interface java.util.List<T>
Specified by:
equals in interface java.util.Set<T>
Overrides:
equals in class java.util.AbstractList<T>

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<T>
Specified by:
hashCode in interface java.util.List<T>
Specified by:
hashCode in interface java.util.Set<T>
Overrides:
hashCode in class java.util.AbstractList<T>