Package gov.nasa.worldwind.util
Class IntSet
- java.lang.Object
-
- gov.nasa.worldwind.util.IntSet
-
public class IntSet extends java.lang.Object
A collection of 32-bit integer primitives that contains no duplicate elements. IntSet provides the minimal operations for working with on a set of integers: add, remove, contains, and clear. Additionally, IntSet provides methods for determining the number of integers in the set, and for retrieving the integers as an array.IntSet
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
IntSet.Bucket
-
Field Summary
Fields Modifier and Type Field 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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
DEFAULT_NUM_BUCKETS
protected static final int DEFAULT_NUM_BUCKETS
- See Also:
- Constant Field Values
-
DEFAULT_BUCKET_CAPACITY
protected static final int DEFAULT_BUCKET_CAPACITY
- See Also:
- Constant Field Values
-
buckets
protected IntSet.Bucket[] buckets
-
numBuckets
protected int numBuckets
-
bucketInitialCapacity
protected int bucketInitialCapacity
-
size
protected int size
-
-
Constructor Detail
-
IntSet
public IntSet()
Creates an empty IntSet with the default number of buckets and initial bucket capacity.
-
IntSet
public IntSet(int numBuckets, int bucketInitialCapacity)
Creates an empty IntSet with the specified number of buckets and initial bucket capacity. Both the number of buckets and the initial bucket capacity must be greater than zero. For optimal performance with more than a few unique values, the number of buckets should be configured to a large value such as 128. The bucket initial capacity does not significantly affect performance, as each bucket eventually grows to fit its entries.- Parameters:
numBuckets
- the number of buckets this IntSet uses tobucketInitialCapacity
- the initial capacity for each bucket.- Throws:
java.lang.IllegalArgumentException
- if either numBuckets or bucketInitialCapacity is less than 1.
-
-
Method Detail
-
size
public int size()
Returns the number of unique integers in this set.- Returns:
- the set's size.
-
add
public boolean add(int value)
Adds the specified value to this set. If this set does not contain the value, it is added to this set and this returns true. Otherwise this does nothing and returns false.- Parameters:
value
- the value to add.- Returns:
- true if the value is added to this set, otherwise false.
-
remove
public boolean remove(int value)
Removes the specified value from this set. If this set does not contain the value, this does nothing and returns false. Otherwise this removes the value and returns true.- Parameters:
value
- the value to remove.- Returns:
- true of the value is removed from this set, otherwise false.
-
contains
public boolean contains(int value)
Indicates whether this set contains the specified value.- Parameters:
value
- the value to test.- Returns:
- true if this set contains the value, otherwise false.
-
clear
public void clear()
Removes all of the values from this set. This set is empty after this call returns.
-
toArray
public int[] toArray(int[] array)
Returns the values in this set as a 32-bit integer array. The values are stored in the specified array if it has enough room. If the array isnull
or is not large enough, this allocates and returns a new array with length equal to this set's size.- Parameters:
array
- the array into which the values are stored.- Returns:
- the array of values in this set, or a new array if the specified array is
null
or not large enough.
-
-