Author: schor Date: Fri Dec 15 16:04:31 2017 New Revision: 1818297 URL: http://svn.apache.org/viewvc?rev=1818297&view=rev Log: no jira - swap up found item if had to go thru 1 or more removed things, for contains and get
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Obj2IntIdentityHashMap.java Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java?rev=1818297&r1=1818296&r2=1818297&view=diff ============================================================================== --- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java (original) +++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Int2ObjHashMap.java Fri Dec 15 16:04:31 2017 @@ -301,9 +301,19 @@ public class Int2ObjHashMap<T> extends C // } public T get(int key) { - return (key == 0) ? null : values[findPosition(key)]; + if (key == 0) return null; + + int pos = findPosition(key); + if (found_removed != -1) { + keys[found_removed] = key; + keys[pos] = REMOVED_KEY; + T r = values[found_removed] = values[pos]; + values[pos] = null; + return r; + } + return values[pos]; } - + public T remove(int key) { int pos = findPosition(key); T v = values[pos]; @@ -390,6 +400,14 @@ public class Int2ObjHashMap<T> extends C public boolean containsKey(int key) { int probeAddr = findPosition(key); + if (found_removed != -1) { + keys[found_removed] = key; + keys[probeAddr] = REMOVED_KEY; + values[found_removed] = values[probeAddr]; + values[probeAddr] = null; + return true; + } + return keys[probeAddr] != 0 ; } Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Obj2IntIdentityHashMap.java URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Obj2IntIdentityHashMap.java?rev=1818297&r1=1818296&r2=1818297&view=diff ============================================================================== --- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Obj2IntIdentityHashMap.java (original) +++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/Obj2IntIdentityHashMap.java Fri Dec 15 16:04:31 2017 @@ -219,7 +219,18 @@ public class Obj2IntIdentityHashMap<T> e // } public boolean contains(Object obj) { // arg must be Object to fit Collection API - return (componentType.isAssignableFrom(obj.getClass())) ? (find((T) obj) != -1) : false; + if (obj == null || !componentType.isAssignableFrom(obj.getClass())) return false; + T tobj = (T) obj; + int pos = findPosition(tobj); + if (found_removed != -1) { + keys[found_removed] = tobj; + keys[pos] = removedMarker; + int r = values[found_removed] = values[pos]; + values[pos] = 0; + return true; + } + + return keys[pos] == obj; } /** @@ -240,7 +251,14 @@ public class Obj2IntIdentityHashMap<T> e return 0; } int pos = findPosition(obj); - return (keys[pos] != null) ? values[pos] : 0; + if (found_removed != -1) { + keys[found_removed] = obj; + keys[pos] = removedMarker; + int r = values[found_removed] = values[pos]; + values[pos] = 0; + return r; + } + return values[pos]; } /**