|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
kodkod.util.collections.CacheSet<E>
public final class CacheSet<E>
Implements the Set interface, backed by a hash table. It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time. This class does not permit the null element.
This class offers constant time performance for the basic operations (add, remove, contains and size), assuming the hash function disperses the elements properly among the buckets. Iterating over this set requires time proportional to the sum of the HashSet instance's size (the number of elements) plus the "capacity" of the backing map (the number of buckets). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.
This set differs from Java's HashSet in that it provides methods for retrieving elements with a particular hashcode. This makes it easy to set as a cache in which cached objects' hashcodes are their keys.
Note that this implementation is not synchronized. The iterators returned by this class's iterator method are not fail-fast
elts: set T |
Constructor Summary | |
---|---|
CacheSet()
Constructs a new, empty set; the backing map has default initial capacity (16) and load factor (0.75). |
|
CacheSet(java.util.Collection<? extends E> c)
Constructs a new set containing the elements in the specified collection. |
|
CacheSet(int initialCapacity,
float loadFactor)
Constructs a new, empty set; the backing map has the specified initial capacity and the specified load factor. |
Method Summary | |
---|---|
boolean |
add(E elt)
Adds the given element to this set, if not already present. |
void |
clear()
Removes all elements from this set. |
boolean |
contains(java.lang.Object elt)
Returns true if this set contains the given element. |
java.util.Iterator<E> |
get(int hash)
Returns an iterator over the elements whose hashcode() method returns the given hash. |
boolean |
isEmpty()
Returns true if this set is empty. |
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements in this set. |
boolean |
remove(java.lang.Object elt)
Removes the specified object from this set, if present. |
int |
size()
Returns the number of elements in this set. |
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
---|
addAll, containsAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Set |
---|
addAll, containsAll, retainAll, toArray, toArray |
Constructor Detail |
---|
public CacheSet()
no this.elts' |
public CacheSet(int initialCapacity, float loadFactor)
initialCapacity
- the initial capacity of the hash map.loadFactor
- the load factor of the hash map.
java.lang.IllegalArgumentException
- if the initial capacity is less
than zero, or if the load factor is nonpositive.no this.elts' |
public CacheSet(java.util.Collection<? extends E> c)
c
- the collection whose elements are to be placed into this set.
java.lang.NullPointerException
- if the specified collection is null.Method Detail |
---|
public int size()
size
in interface java.util.Collection<E>
size
in interface java.util.Set<E>
size
in class java.util.AbstractCollection<E>
Set.size()
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E>
isEmpty
in interface java.util.Set<E>
isEmpty
in class java.util.AbstractCollection<E>
Set.isEmpty()
public boolean contains(java.lang.Object elt)
contains
in interface java.util.Collection<E>
contains
in interface java.util.Set<E>
contains
in class java.util.AbstractCollection<E>
java.lang.NullPointerException
- - elt = nullSet.contains(java.lang.Object)
public java.util.Iterator<E> iterator()
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.Set<E>
iterator
in class java.util.AbstractCollection<E>
Set.iterator()
public boolean add(E elt)
add
in interface java.util.Collection<E>
add
in interface java.util.Set<E>
add
in class java.util.AbstractCollection<E>
java.lang.NullPointerException
- - elt = nullthis.elts' = this.elts + elt |
public boolean remove(java.lang.Object elt)
remove
in interface java.util.Collection<E>
remove
in interface java.util.Set<E>
remove
in class java.util.AbstractCollection<E>
java.lang.NullPointerException
- - elt = nullSet.remove(java.lang.Object)
this.elts' = this.elts - elt |
public java.util.Iterator<E> get(int hash)
public void clear()
clear
in interface java.util.Collection<E>
clear
in interface java.util.Set<E>
clear
in class java.util.AbstractCollection<E>
Set.clear()
no this.elts' |
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |