Package org.apache.uima.internal.util
Class IntSet
java.lang.Object
org.apache.uima.internal.util.IntSet
- All Implemented Interfaces:
PositiveIntSet
This class implements a set of integers. It does not implement the
Set
interface for
performance reasons, though methods with the same name are equivalent.
This does not implement shorts + offset, like the IntHashSet does because by the time that might
be of interest, we would switch to IntHashSet to get ~O(1) operations including contains.-
Field Summary
Fields inherited from interface org.apache.uima.internal.util.PositiveIntSet
IS_TRACE_MODE_SWITCH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(int element) Adds the specified int to this set.void
add all elements in this set to the IntVector v as a bulk operationvoid
clear()
remove all members of the setboolean
contains
(int element) Tests if this set contains the specified element.boolean
Tests if two sets are equal.int
find
(int element) int
get
(int n) Used for FsBagIndex, and internally to compute most positive/negint
hashCode()
int
indexOf
(int element) boolean
isValid
(int position) For FSBagIndex low level iterator useorg.apache.uima.internal.util.IntSet.IntSetIterator
iterator()
int
For FSBagIndex low level iterator useint
For FSBagIndex low level iterator useint
moveToNext
(int position) For FSBagIndex low level iterator useint
moveToPrevious
(int position) For FSBagIndex low level iterator useboolean
remove
(int key) void
removeElementAt
(int n) Removes then
-th element in this set.int
size()
int[]
toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.uima.internal.util.PositiveIntSet
forAllInts
-
Constructor Details
-
IntSet
public IntSet()Creates a new instance of this set. -
IntSet
public IntSet(int capacity) - Parameters:
capacity
- allocate enough space to hold at least this before expanding
-
-
Method Details
-
add
public boolean add(int element) Adds the specified int to this set.- Specified by:
add
in interfacePositiveIntSet
- Parameters:
element
- the integer to be added.- Returns:
true
if this set did not already contain this element,false
otherwise.
-
contains
public boolean contains(int element) Tests if this set contains the specified element.- Specified by:
contains
in interfacePositiveIntSet
- Parameters:
element
- the element to be tested.- Returns:
true
if the element is contained in this set,false
otherwise.
-
find
public int find(int element) - Specified by:
find
in interfacePositiveIntSet
- Parameters:
element
- an item which may be in the set- Returns:
- -1 if the item is not in the set, or a position value that can be used with iterators to start at that item.
-
size
public int size()- Specified by:
size
in interfacePositiveIntSet
- Returns:
- the size of this set.
-
get
public int get(int n) Used for FsBagIndex, and internally to compute most positive/neg- Specified by:
get
in interfacePositiveIntSet
- Parameters:
n
- the position- Returns:
- the value at that position
-
removeElementAt
public void removeElementAt(int n) Removes then
-th element in this set.- Parameters:
n
- -
-
equals
Tests if two sets are equal. This is the case if the two sets are of the same size, and every element in one set in contained in the other set.
Note that in order to increase performance, before the sets are actually compared the way described above, the sums of the elements in both sets are calculated, ignoring possible int overflows. If the sums are not equal, the two sets cannot be equal. In case the sums are equal, the two sets are compared element by element. -
hashCode
public int hashCode() -
indexOf
public int indexOf(int element) -
clear
public void clear()Description copied from interface:PositiveIntSet
remove all members of the set- Specified by:
clear
in interfacePositiveIntSet
-
remove
public boolean remove(int key) - Specified by:
remove
in interfacePositiveIntSet
- Parameters:
key
- -- Returns:
- true if the set had this element before the remove
-
iterator
public org.apache.uima.internal.util.IntSet.IntSetIterator iterator()- Specified by:
iterator
in interfacePositiveIntSet
- Returns:
- an iterator (may be ordered or unordered) over the members of the set
-
moveToFirst
public int moveToFirst()Description copied from interface:PositiveIntSet
For FSBagIndex low level iterator use- Specified by:
moveToFirst
in interfacePositiveIntSet
- Returns:
- the position of the first element, or -1;
-
moveToLast
public int moveToLast()Description copied from interface:PositiveIntSet
For FSBagIndex low level iterator use- Specified by:
moveToLast
in interfacePositiveIntSet
- Returns:
- the position of the last element, or -1;
-
moveToNext
public int moveToNext(int position) Description copied from interface:PositiveIntSet
For FSBagIndex low level iterator use- Specified by:
moveToNext
in interfacePositiveIntSet
- Parameters:
position
- -- Returns:
- the position of the next element, or -1;
-
moveToPrevious
public int moveToPrevious(int position) Description copied from interface:PositiveIntSet
For FSBagIndex low level iterator use- Specified by:
moveToPrevious
in interfacePositiveIntSet
- Parameters:
position
- -- Returns:
- the position of the next element, or -1;
-
isValid
public boolean isValid(int position) Description copied from interface:PositiveIntSet
For FSBagIndex low level iterator use- Specified by:
isValid
in interfacePositiveIntSet
- Parameters:
position
- -- Returns:
- true if the position is between the first and last element inclusive.
-
bulkAddTo
Description copied from interface:PositiveIntSet
add all elements in this set to the IntVector v as a bulk operation- Specified by:
bulkAddTo
in interfacePositiveIntSet
- Parameters:
v
- - to be added to
-
toIntArray
public int[] toIntArray()- Specified by:
toIntArray
in interfacePositiveIntSet
- Returns:
- the set as an arbitrarily ordered int array
-
toString
-