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:
java.lang.Iterable<T>
,java.util.Collection<T>
,java.util.Set<T>
public class ObjHashSet<T> extends Common_hash_support implements java.util.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 Classes Modifier and Type Class Description private class
ObjHashSet.ObjHashSetIterator
-
Nested classes/interfaces inherited from class org.apache.uima.internal.util.Common_hash_support
Common_hash_support.CommonCopyOld2New, Common_hash_support.CommonKeyIterator
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<T>
clazz
private T[]
keys
private T
removedMarker
the object of type T indicating key is removed-
Fields 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
Constructors Constructor Description ObjHashSet(int initialCapacity, java.lang.Class<T> clazz, T removedMarker)
ObjHashSet(java.lang.Class<T> clazz, T removedMarker)
ObjHashSet(ObjHashSet<T> ohs)
Copy constructorObjHashSet(ObjHashSet<T> ohs, boolean readOnly)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T obj)
boolean
addAll(java.util.Collection<? extends T> c)
private void
addInner(T obj)
used for increasing table sizeprotected void
clearKeysAndValues()
boolean
contains(java.lang.Object obj)
boolean
containsAll(java.util.Collection<?> c)
protected void
copy_to_new_table(int new_capacity, int old_capacity, Common_hash_support.CommonCopyOld2New commonCopy)
int
find(T obj)
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.T
get(int index)
For iterator useprotected boolean
is_valid_key(int pos)
boolean
isEmpty()
java.util.Iterator<T>
iterator()
protected int
keys_length()
int
moveTo(FeatureStructure fs)
if the fs is in the set, the iterator should return it.private int
moveToFirst()
protected void
newKeysAndValues(int capacity)
boolean
remove(java.lang.Object rawKey)
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(java.util.Collection<?> c)
private void
removeAtPosition(int pos)
boolean
retainAll(java.util.Collection<?> c)
T[]
toArray()
<T2> T2[]
toArray(T2[] a)
java.lang.String
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
-
-
-
-
Constructor Detail
-
ObjHashSet
public ObjHashSet(int initialCapacity, java.lang.Class<T> clazz, T removedMarker)
- 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
public ObjHashSet(ObjHashSet<T> ohs)
Copy constructor- Parameters:
ohs
- -
-
ObjHashSet
public ObjHashSet(ObjHashSet<T> ohs, boolean readOnly)
-
-
Method Detail
-
findPosition
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. 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
public boolean contains(java.lang.Object obj)
-
find
public int find(T obj)
- 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
public boolean add(T obj)
-
addInner
private void addInner(T obj)
used for increasing table size- Parameters:
rawKey
-
-
remove
public boolean remove(java.lang.Object rawKey)
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
public T get(int index)
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
public java.util.Iterator<T> iterator()
-
moveToFirst
private int moveToFirst()
-
moveTo
public int moveTo(FeatureStructure fs)
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
public T[] toArray()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isEmpty
public boolean isEmpty()
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
-
addAll
public boolean addAll(java.util.Collection<? extends T> c)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
-
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
-
-