Package org.apache.uima.internal.util
Class PositiveIntSet_impl
java.lang.Object
org.apache.uima.internal.util.PositiveIntSet_impl
- All Implemented Interfaces:
PositiveIntSet
An set of non-zero integers, ability to iterate over them (possibly in a sorted way),
with O(1) operations for adding, removing, and testing for contains.
Optimized for adding mostly increasing integers (with some space for less-than-first-one-added).
- major uses: indexes of Feature Structures.
Optimize for small sets
Graceful degradation for completely random integer operations on large sets;
keep O(1) operations, at the expense of extra space (< 3 x size).
Uses several different representations depending on the range of ints stored and the total number of ints stored.
Sizes: Tiny, medium, large
Ranges: semi-knowable, unknowable;
if semi-knowable, dense, small-range (< 65K), large-range
For all sizes,
if dense, use IntBitSet (with offset)
else
For large, (implies large-range, too) use IntHashSet
For medium,
if small-range < 65K, use IntHashSet with offset
else use IntHashSet
Arrange switching between representations
to occur infrequently, especially as cost of switching (size) grows
Arrange checking for switching to occur infrequently, taking into account how underlying data structures grow
(which is often by doubling)
Switch when adding new member(s) if alternative representation is sufficiently smaller
-
Field Summary
Fields inherited from interface org.apache.uima.internal.util.PositiveIntSet
IS_TRACE_MODE_SWITCH -
Constructor Summary
ConstructorsConstructorDescriptionPositiveIntSet_impl(int initialSize, int estMin, int estMax) Set up a Positive Bit Set -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int key) voidadd all elements in this set to the IntVector v as a bulk operationvoidclear()remove all members of the setbooleancontains(int key) intfind(int element) intget(int position) For FSBagIndex low level iterator use DOESN"T WORK WITH INCREMENTING position VALUESbooleanisValid(int position) For FSBagIndex low level iterator useiterator()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) intsize()int[]int[]toString()int[]Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.uima.internal.util.PositiveIntSet
forAllInts
-
Constructor Details
-
PositiveIntSet_impl
public PositiveIntSet_impl() -
PositiveIntSet_impl
public PositiveIntSet_impl(int initialSize, int estMin, int estMax) Set up a Positive Bit Set- Parameters:
initialSize- - if 0, don't allocate yet, wait for first add. If isBitSetDense, then this number is interpreted as the first int to be added, typically with an offset. The next two params are used only if initialSize is not 0.estMin- - the estimated minimum int value to be addedestMax- - the estimated max int value to be added
-
-
Method Details
-
iterator
- Specified by:
iteratorin interfacePositiveIntSet- Returns:
- an iterator (may be ordered or unordered) over the members of the set
-
getUnorderedIterator
-
getOrderedIterator
-
clear
public void clear()Description copied from interface:PositiveIntSetremove all members of the set- Specified by:
clearin interfacePositiveIntSet
-
contains
public boolean contains(int key) - Specified by:
containsin interfacePositiveIntSet- Parameters:
key- -- Returns:
- true if key is in the set
-
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.
-
add
public boolean add(int key) - Specified by:
addin interfacePositiveIntSet- Parameters:
key- -- Returns:
- true if this set did not already contain the specified element
-
remove
public boolean remove(int key) - Specified by:
removein interfacePositiveIntSet- Parameters:
key- -- Returns:
- true if the set had this element before the remove
-
size
public int size()- Specified by:
sizein interfacePositiveIntSet- Returns:
- number of elements in the set
-
toUnorderedIntArray
public int[] toUnorderedIntArray() -
toOrderedIntArray
public int[] toOrderedIntArray() -
get
public int get(int position) Description copied from interface:PositiveIntSetFor FSBagIndex low level iterator use DOESN"T WORK WITH INCREMENTING position VALUES- Specified by:
getin interfacePositiveIntSet- Parameters:
position- - get the element at this position. This is for iterator use only, and is not related to any key- Returns:
- the element
-
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
-