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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int element) Adds the specified int to this set.voidadd all elements in this set to the IntVector v as a bulk operationvoidclear()remove all members of the setbooleancontains(int element) Tests if this set contains the specified element.booleanTests if two sets are equal.intfind(int element) intget(int n) Used for FsBagIndex, and internally to compute most positive/neginthashCode()intindexOf(int element) booleanisValid(int position) For FSBagIndex low level iterator useorg.apache.uima.internal.util.IntSet.IntSetIteratoriterator()intFor FSBagIndex low level iterator useintFor FSBagIndex low level iterator useintmoveToNext(int position) For FSBagIndex low level iterator useintmoveToPrevious(int position) For FSBagIndex low level iterator usebooleanremove(int key) voidremoveElementAt(int n) Removes then-th element in this set.intsize()int[]toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
addin interfacePositiveIntSet- Parameters:
element- the integer to be added.- Returns:
trueif this set did not already contain this element,falseotherwise.
-
contains
public boolean contains(int element) Tests if this set contains the specified element.- Specified by:
containsin interfacePositiveIntSet- Parameters:
element- the element to be tested.- Returns:
trueif the element is contained in this set,falseotherwise.
-
find
public int find(int element) - Specified by:
findin 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:
sizein 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:
getin 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:PositiveIntSetremove all members of the set- Specified by:
clearin interfacePositiveIntSet
-
remove
public boolean remove(int key) - Specified by:
removein 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:
iteratorin interfacePositiveIntSet- Returns:
- an iterator (may be ordered or unordered) over the members of the set
-
moveToFirst
public int moveToFirst()Description copied from interface:PositiveIntSetFor FSBagIndex low level iterator use- Specified by:
moveToFirstin interfacePositiveIntSet- Returns:
- the position of the first element, or -1;
-
moveToLast
public int moveToLast()Description copied from interface:PositiveIntSetFor FSBagIndex low level iterator use- Specified by:
moveToLastin interfacePositiveIntSet- Returns:
- the position of the last element, or -1;
-
moveToNext
public int moveToNext(int position) Description copied from interface:PositiveIntSetFor FSBagIndex low level iterator use- Specified by:
moveToNextin interfacePositiveIntSet- Parameters:
position- -- Returns:
- the position of the next element, or -1;
-
moveToPrevious
public int moveToPrevious(int position) Description copied from interface:PositiveIntSetFor FSBagIndex low level iterator use- Specified by:
moveToPreviousin interfacePositiveIntSet- Parameters:
position- -- Returns:
- the position of the next element, or -1;
-
isValid
public boolean isValid(int position) Description copied from interface:PositiveIntSetFor FSBagIndex low level iterator use- Specified by:
isValidin interfacePositiveIntSet- Parameters:
position- -- Returns:
- true if the position is between the first and last element inclusive.
-
bulkAddTo
Description copied from interface:PositiveIntSetadd all elements in this set to the IntVector v as a bulk operation- Specified by:
bulkAddToin interfacePositiveIntSet- Parameters:
v- - to be added to
-
toIntArray
public int[] toIntArray()- Specified by:
toIntArrayin interfacePositiveIntSet- Returns:
- the set as an arbitrarily ordered int array
-
toString
-