Package org.apache.uima.internal.util
Class ObjHashSet<T>
java.lang.Object
org.apache.uima.internal.util.Common_hash_support
org.apache.uima.internal.util.ObjHashSet<T>
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Set<T>
A set of Objects of type T
This impl is for use in a single thread case only, when table is being updated. Multiple reader
threads are OK if there's no writing.
Supports shrinking (reallocating the big table)
Removed objects replaced with special marker object in the table so find operations continue to
work (they can't stop upon finding this object).
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.uima.internal.util.Common_hash_support
Common_hash_support.CommonCopyOld2New, Common_hash_support.CommonKeyIterator
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate T[]
private final T
the object of type T indicating key is removedFields inherited from class org.apache.uima.internal.util.Common_hash_support
found_removed, histogram, initialCapacity, loadFactor, maxProbe, MIN_CAPACITY, MIN_CAPACITY_SHRINK, MIN_SIZE, removed, secondTimeShrinkable, sizeWhichTriggersExpansion, TUNE
-
Constructor Summary
ConstructorsConstructorDescriptionObjHashSet
(int initialCapacity, Class<T> clazz, T removedMarker) ObjHashSet
(Class<T> clazz, T removedMarker) ObjHashSet
(ObjHashSet<T> ohs) Copy constructorObjHashSet
(ObjHashSet<T> ohs, boolean readOnly) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> c) private void
used for increasing table sizeprotected void
boolean
boolean
containsAll
(Collection<?> c) protected void
copy_to_new_table
(int new_capacity, int old_capacity, Common_hash_support.CommonCopyOld2New commonCopy) int
private int
findPosition
(T key) returns a position in the key/value table if the key is not found, then the position will be to the place where the key would be put upon adding (without reusing REMOVED, and the current internal value of keys[position] would be 0.get
(int index) For iterator useprotected boolean
is_valid_key
(int pos) boolean
isEmpty()
iterator()
protected int
int
if the fs is in the set, the iterator should return it.private int
protected void
newKeysAndValues
(int capacity) boolean
Can't replace the item with a null because other keys that were stored in the table which previously collided with the removed item won't be found.boolean
removeAll
(Collection<?> c) private void
removeAtPosition
(int pos) boolean
retainAll
(Collection<?> c) T[]
toArray()
<T2> T2[]
toArray
(T2[] a) toString()
Methods inherited from class org.apache.uima.internal.util.Common_hash_support
clear, commonPutOrAddNotFound, commonRemove, debugValidate, findPosition, getCapacity, incrementSize, moveToNextFilled, moveToPreviousFilled, newTable, resetHistogram, showHistogram, size, tableSpace
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
-
Field Details
-
removedMarker
the object of type T indicating key is removed -
clazz
-
keys
-
-
Constructor Details
-
ObjHashSet
-
ObjHashSet
- Parameters:
initialCapacity
- - you can add this many before expansionclazz
- - a superclass of the stored itemsremovedMarker
- - a unique value never stored in the table, used to mark removed items
-
ObjHashSet
Copy constructor- Parameters:
ohs
- -
-
ObjHashSet
-
-
Method Details
-
findPosition
returns a position in the key/value table if the key is not found, then the position will be to the place where the key would be put upon adding (without reusing REMOVED, and the current internal value of keys[position] would be 0. if the key is found, then keys[position] == key- Parameters:
obj
- the object to find- Returns:
- the probeAddr in keys array - might reference a slot holding null, or the key value if found
-
contains
-
find
- Parameters:
obj
- the object to find in the table (if it is there)- Returns:
- the position of obj in the table, or -1 if not in the table
-
add
-
addInner
used for increasing table size- Parameters:
rawKey
-
-
remove
Can't replace the item with a null because other keys that were stored in the table which previously collided with the removed item won't be found. UIMA-4204 -
removeAtPosition
private void removeAtPosition(int pos) -
get
For iterator use- Parameters:
index
- - a magic number returned by the internal find- Returns:
- the T at that spot, or null if nothing there
-
iterator
-
moveToFirst
private int moveToFirst() -
moveTo
if the fs is in the set, the iterator should return it. if not, return -1 (makes iterator invalid)- Parameters:
fs
- position to this fs- Returns:
- the index if present, otherwise -1;
-
toArray
public <T2> T2[] toArray(T2[] a) -
toArray
-
toString
-
isEmpty
public boolean isEmpty() -
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
- Specified by:
containsAll
in interfaceSet<T>
-
addAll
-
removeAll
-
retainAll
-
is_valid_key
protected boolean is_valid_key(int pos) - Specified by:
is_valid_key
in classCommon_hash_support
-
keys_length
protected int keys_length()- Specified by:
keys_length
in classCommon_hash_support
-
newKeysAndValues
protected void newKeysAndValues(int capacity) - Specified by:
newKeysAndValues
in classCommon_hash_support
-
clearKeysAndValues
protected void clearKeysAndValues()- Specified by:
clearKeysAndValues
in classCommon_hash_support
-
copy_to_new_table
protected void copy_to_new_table(int new_capacity, int old_capacity, Common_hash_support.CommonCopyOld2New commonCopy) - Specified by:
copy_to_new_table
in classCommon_hash_support
-