net.sf.saxon.sort

Class IntArraySet

public class IntArraySet extends Object implements Serializable, IntSet

Set of int values. This class is modelled on the java.net.Set interface, but it does not implement this interface, because the set members are int's rather than Objects.

This implementation of a set of integers is optimized to use very little storage and to provide fast comparison of two sets. The equals() method determines whether two sets contain the same integers.

This implementation is not efficient at adding new integers to the set. It creates a new array each time you do that.

Not thread safe.

Author: Michael Kay

Field Summary
static int[]EMPTY_INT_ARRAY
Constructor Summary
IntArraySet()
Create an empty set
IntArraySet(IntHashSet input)
Create a set containing integers from the specified IntHashSet
IntArraySet(IntArraySet input)
Create one IntArraySet as a copy of another
Method Summary
booleanadd(int value)
Add an integer to the set
voidclear()
booleancontains(int value)
booleancontainsAll(IntSet other)
Test if this set is a superset of another set
booleanequals(Object other)
Test whether this set has exactly the same members as another set
intgetFirst()
Get the first value in the set.
int[]getValues()
Get the set of integer values as an array
inthashCode()
Construct a hash key that supports the equals() test
booleanisEmpty()
IntIteratoriterator()
Get an iterator over the values
static IntArraySetmake(int[] in, int size)
Factory method to construct a set from an array of integers
booleanremove(int value)
intsize()
StringtoString()
IntArraySetunion(IntArraySet other)
Form a new set that is the union of this set with another set.

Field Detail

EMPTY_INT_ARRAY

public static final int[] EMPTY_INT_ARRAY

Constructor Detail

IntArraySet

public IntArraySet()
Create an empty set

IntArraySet

public IntArraySet(IntHashSet input)
Create a set containing integers from the specified IntHashSet

Parameters: input the set to be copied

IntArraySet

public IntArraySet(IntArraySet input)
Create one IntArraySet as a copy of another

Parameters: input the set to be copied

Method Detail

add

public boolean add(int value)
Add an integer to the set

Parameters: value the integer to be added

Returns: true if the integer was added, false if it was already present

clear

public void clear()

contains

public boolean contains(int value)

containsAll

public boolean containsAll(IntSet other)
Test if this set is a superset of another set

equals

public boolean equals(Object other)
Test whether this set has exactly the same members as another set

getFirst

public int getFirst()
Get the first value in the set.

Returns: the first value in the set, in sorted order

Throws: ArrayIndexOutOfBoundsException if the set is empty

getValues

public int[] getValues()
Get the set of integer values as an array

Returns: a sorted array of integers

hashCode

public int hashCode()
Construct a hash key that supports the equals() test

isEmpty

public boolean isEmpty()

iterator

public IntIterator iterator()
Get an iterator over the values

Returns: an iterator over the values, which will be delivered in sorted order

make

public static IntArraySet make(int[] in, int size)
Factory method to construct a set from an array of integers

Parameters: in the array of integers, which must be in ascending order size the number of elements in the array that are significant

Returns: the constructed set

remove

public boolean remove(int value)

size

public int size()

toString

public String toString()

union

public IntArraySet union(IntArraySet other)
Form a new set that is the union of this set with another set.

Parameters: other the other set

Returns: the union of the two sets