public class IntSet extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
IntSet.Bucket |
Modifier and Type | Field and Description |
---|---|
protected int |
bucketInitialCapacity |
protected IntSet.Bucket[] |
buckets |
protected static int |
DEFAULT_BUCKET_CAPACITY |
protected static int |
DEFAULT_NUM_BUCKETS |
protected int |
numBuckets |
protected int |
size |
Constructor and Description |
---|
IntSet()
Creates an empty IntSet with the default number of buckets and initial bucket capacity.
|
IntSet(int numBuckets,
int bucketInitialCapacity)
Creates an empty IntSet with the specified number of buckets and initial bucket capacity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(int value)
Adds the specified value to this set.
|
void |
clear()
Removes all of the values from this set.
|
boolean |
contains(int value)
Indicates whether this set contains the specified value.
|
boolean |
remove(int value)
Removes the specified value from this set.
|
int |
size()
Returns the number of unique integers in this set.
|
int[] |
toArray(int[] array)
Returns the values in this set as a 32-bit integer array.
|
protected int bucketInitialCapacity
protected IntSet.Bucket[] buckets
protected static final int DEFAULT_BUCKET_CAPACITY
protected static final int DEFAULT_NUM_BUCKETS
protected int numBuckets
protected int size
public IntSet()
public IntSet(int numBuckets, int bucketInitialCapacity)
numBuckets
- the number of buckets this IntSet uses tobucketInitialCapacity
- the initial capacity for each bucket.IllegalArgumentException
- if either numBuckets or bucketInitialCapacity is less than 1.public boolean add(int value)
value
- the value to add.public void clear()
public boolean contains(int value)
value
- the value to test.public boolean remove(int value)
value
- the value to remove.public int size()
public int[] toArray(int[] array)
null
or is not large enough, this allocates and returns a new array
with length equal to this set's size.array
- the array into which the values are stored.null
or not large
enough.