NASA World Wind

gov.nasa.worldwind.util
Class IntSet

java.lang.Object
  extended by gov.nasa.worldwind.util.IntSet

public class IntSet
extends 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
protected static class IntSet.Bucket
           
 
Field Summary
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 Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bucketInitialCapacity

protected int bucketInitialCapacity

buckets

protected IntSet.Bucket[] buckets

DEFAULT_BUCKET_CAPACITY

protected static final int DEFAULT_BUCKET_CAPACITY
See Also:
Constant Field Values

DEFAULT_NUM_BUCKETS

protected static final int DEFAULT_NUM_BUCKETS
See Also:
Constant Field Values

numBuckets

protected int numBuckets

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 to
bucketInitialCapacity - the initial capacity for each bucket.
Throws:
IllegalArgumentException - if either numBuckets or bucketInitialCapacity is less than 1.
Method Detail

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.

clear

public void clear()
Removes all of the values from this set. This set is empty after this call returns.


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.

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.

size

public int size()
Returns the number of unique integers in this set.

Returns:
the set's size.

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 is null 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.

NASA World Wind