public class CompactIntSet extends AbstractIntSet implements Serializable
BitSet-backed Set implementation for storing non-negative
int values. This set offers a space-efficient method for storing
small, or densly populated sets of ints.
Because this class only supports storing non-negative values in the set,
any attempt to add a negative value will throw an IllegalArgumentException. The contains and remove methods
will also always return false.
This class provides overloads of the common Set operation with
the primitive int and Integer values. Callers may use the
primitive overloads to avoid auto-boxing the int values.
Furthermore, this class provides overloads for the addAll, removeAll, and retainAll methos which operate on IntSet instances. These
overloaded versions will still operate in O(n) time, but will be
much faster than the Collection-based versions.
This class also provides a wrap(BitSet) method for wrapping an
existing BitSet as a Set, which acts as a bridge between
bit-based and Collections-based operations.
This class is not thread-safe. This class and its iterator implement all of the optional methods.
| Constructor and Description |
|---|
CompactIntSet()
Creates a new, empty set of
int values. |
CompactIntSet(Collection<Integer> ints)
Creates a new set containing all of the specified
int values. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int i) |
boolean |
add(Integer i) |
boolean |
addAll(CompactIntSet ints)
Adds to this set all of the elements that are contained in the specified
CompactIntSet if not already present, using an CompactIntSet-optimized
process. |
boolean |
contains(int i) |
boolean |
contains(Integer i) |
boolean |
isEmpty() |
IntIterator |
iterator() |
boolean |
remove(int i) |
boolean |
remove(Integer i) |
boolean |
removeAll(CompactIntSet ints)
Removes from this set all of the elements that are contained in the
specified
CompactIntSet using an CompactIntSet-optimized process. |
boolean |
retainAll(CompactIntSet ints)
Retains only the elements in this set that are contained in the specified
CompactIntSet using an CompactIntSet-optimized process. |
int |
size() |
static IntSet |
wrap(BitSet b)
Wraps the provided
BitSet as a Set returning the result. |
addAll, containsAll, removeAll, retainAll, toPrimitiveArrayequals, hashCode, removeAlladdAll, clear, contains, containsAll, remove, retainAll, toArray, toArray, toStringpublic CompactIntSet()
int values.public CompactIntSet(Collection<Integer> ints)
int values.public boolean add(Integer i)
add in interface Collection<Integer>add in interface Set<Integer>add in class AbstractCollection<Integer>public boolean add(int i)
add in interface IntCollectionadd in interface IntSetadd in class AbstractIntSetpublic boolean addAll(CompactIntSet ints)
CompactIntSet if not already present, using an CompactIntSet-optimized
process.public boolean contains(Integer i)
public boolean contains(int i)
contains in interface IntCollectioncontains in interface IntSetpublic boolean isEmpty()
isEmpty in interface Collection<Integer>isEmpty in interface Set<Integer>isEmpty in class AbstractCollection<Integer>public IntIterator iterator()
iterator in interface IntCollectioniterator in interface IntSetiterator in interface Iterable<Integer>iterator in interface Collection<Integer>iterator in interface Set<Integer>iterator in class AbstractIntSetpublic boolean remove(Integer i)
public boolean remove(int i)
remove in interface IntCollectionremove in interface IntSetremove in class AbstractIntSetpublic boolean removeAll(CompactIntSet ints)
CompactIntSet using an CompactIntSet-optimized process.public boolean retainAll(CompactIntSet ints)
CompactIntSet using an CompactIntSet-optimized process.public int size()
size in interface Collection<Integer>size in interface Set<Integer>size in class AbstractCollection<Integer>Copyright © 2012. All Rights Reserved.