You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2017/07/20 14:44:41 UTC
svn commit: r1802497 - in
/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util:
CopyOnWriteObjHashSet.java CopyOnWriteOrderedFsSet_array.java ObjHashSet.java
Author: schor
Date: Thu Jul 20 14:44:41 2017
New Revision: 1802497
URL: http://svn.apache.org/viewvc?rev=1802497&view=rev
Log:
[UIMA-5504] clean up iterators/indexes, remove modification count maintenance
Modified:
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java
uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java?rev=1802497&r1=1802496&r2=1802497&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteObjHashSet.java Thu Jul 20 14:44:41 2017
@@ -33,9 +33,12 @@ public class CopyOnWriteObjHashSet<T> im
private ObjHashSet<T> ohs;
+ private ObjHashSet<T> original;
+
public CopyOnWriteObjHashSet(ObjHashSet<T> original) {
this.ohs = original;
+ this.original = original;
}
/**
@@ -148,13 +151,13 @@ public class CopyOnWriteObjHashSet<T> im
return ohs.toString();
}
- /**
- * @see ObjHashSet#getModificationCount()
- * @return the modification count
- */
- public int getModificationCount() {
- return ohs.getModificationCount();
- }
+// /**
+// * @see ObjHashSet#getModificationCount()
+// * @return the modification count
+// */
+// public int getModificationCount() {
+// return ohs.getModificationCount();
+// }
/**
* @see ObjHashSet#getCapacity()
@@ -172,4 +175,13 @@ public class CopyOnWriteObjHashSet<T> im
return ohs.size();
}
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.CopyOnWriteIndexPart#isOriginal(java.lang.Object)
+ */
+ @Override
+ public boolean isOriginal() {
+ return ohs == original;
+ }
+
+
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java?rev=1802497&r1=1802496&r2=1802497&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/CopyOnWriteOrderedFsSet_array.java Thu Jul 20 14:44:41 2017
@@ -18,57 +18,56 @@
*/
package org.apache.uima.internal.util;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Comparator;
-import java.util.Iterator;
-import java.util.NavigableSet;
-import java.util.NoSuchElementException;
-import java.util.SortedSet;
-import java.util.Spliterator;
-import java.util.function.Consumer;
-import java.util.function.Predicate;
-import java.util.function.Supplier;
-import java.util.stream.Stream;
import org.apache.uima.cas.impl.CopyOnWriteIndexPart;
-import org.apache.uima.internal.util.OrderedFsSet_array.SubSet;
import org.apache.uima.jcas.cas.TOP;
/**
* implements OrderedFsSet_array partially, for iterator use
*/
-public class CopyOnWriteOrderedFsSet_array implements NavigableSet<TOP>, CopyOnWriteIndexPart {
+public class CopyOnWriteOrderedFsSet_array implements CopyOnWriteIndexPart {
private OrderedFsSet_array set;
final public Comparator<TOP> comparatorWithoutID;
+ final public Comparator<TOP> comparatorWithID;
- final Supplier<OrderedFsSet_array> sosa = () -> set;
+ final public int a_firstUsedslot;
+ final public int a_nextFreeslot;
+ final public OrderedFsSet_array original;
+ public TOP[] a; // derived from "set" above
+
public CopyOnWriteOrderedFsSet_array(OrderedFsSet_array original) {
this.set = original;
+ this.original = original;
this.comparatorWithoutID = original.comparatorWithoutID;
+ this.comparatorWithID = original.comparatorWithID;
+ this.a_firstUsedslot = original.a_firstUsedslot;
+ this.a_nextFreeslot = original.a_nextFreeslot;
+ this.a = original.a;
}
-
+
/**
* Called by index when about to make an update
* This copy captures the state of things before the update happens
*/
@Override
public void makeReadOnlyCopy() {
- set = new OrderedFsSet_array(set, true); // true = make read only copy
+ this.set = new OrderedFsSet_array(set, true); // true = make read only copy
+ this.a = set.a;
}
- /**
- * @see java.lang.Iterable#forEach(java.util.function.Consumer)
+ /* (non-Javadoc)
+ * @see org.apache.uima.cas.impl.CopyOnWriteIndexPart#isOriginal(java.lang.Object)
*/
@Override
- public void forEach(Consumer<? super TOP> action) {
- set.forEach(action);
+ public boolean isOriginal() {
+ return set == original;
}
-
+
/**
* @see java.lang.Object#hashCode()
*/
@@ -86,409 +85,18 @@ public class CopyOnWriteOrderedFsSet_arr
}
/**
- * @see OrderedFsSet_array#comparator()
- */
- @Override
- public Comparator<? super TOP> comparator() {
- return set.comparator();
- }
-
- /**
- * @see OrderedFsSet_array#first()
- */
- @Override
- public TOP first() {
- return set.first();
- }
-
- /**
- * @see OrderedFsSet_array#last()
- */
- @Override
- public TOP last() {
- return set.last();
- }
-
- /**
* @see OrderedFsSet_array#size()
*/
- @Override
public int size() {
return set.size();
}
- /**
- * @see OrderedFsSet_array#isEmpty()
- */
- @Override
- public boolean isEmpty() {
- return set.isEmpty();
- }
-
- /**
- * @see OrderedFsSet_array#contains(java.lang.Object)
- */
- @Override
- public boolean contains(Object o) {
- return set.contains(o);
- }
-
- /**
- * @see OrderedFsSet_array#toArray()
- */
- @Override
- public Object[] toArray() {
- return set.toArray();
- }
-
- /**
- * @see OrderedFsSet_array#toArray(java.lang.Object[])
- */
- @Override
- public <T> T[] toArray(T[] a1) {
- return set.toArray(a1);
- }
-
- /**
- * @see OrderedFsSet_array#add(TOP)
- */
- @Override
- public boolean add(TOP fs) {
- return set.add(fs);
- }
-
- /**
- * @see java.util.SortedSet#spliterator()
- */
- @Override
- public Spliterator<TOP> spliterator() {
- return set.spliterator();
- }
-
- /**
- * @see java.util.Collection#removeIf(java.util.function.Predicate)
- */
- @Override
- public boolean removeIf(Predicate<? super TOP> filter) {
- return set.removeIf(filter);
- }
-
- /**
- * @see java.util.Collection#stream()
- */
- @Override
- public Stream<TOP> stream() {
- return set.stream();
- }
-
- /**
- * @see java.util.Collection#parallelStream()
- */
- @Override
- public Stream<TOP> parallelStream() {
- return set.parallelStream();
- }
-
- /**
- * @see OrderedFsSet_array#remove(java.lang.Object)
- */
- @Override
- public boolean remove(Object o) {
- return set.remove(o);
- }
-
- /**
- * @see OrderedFsSet_array#containsAll(java.util.Collection)
- */
- @Override
- public boolean containsAll(Collection<?> c) {
- return set.containsAll(c);
- }
-
- /**
- * @see OrderedFsSet_array#addAll(java.util.Collection)
- */
- @Override
- public boolean addAll(Collection<? extends TOP> c) {
- return set.addAll(c);
- }
-
- /**
- * @see OrderedFsSet_array#retainAll(java.util.Collection)
- */
- @Override
- public boolean retainAll(Collection<?> c) {
- return set.retainAll(c);
- }
-
- /**
- * @see OrderedFsSet_array#removeAll(java.util.Collection)
- */
- @Override
- public boolean removeAll(Collection<?> c) {
- return set.removeAll(c);
- }
-
- /**
- *
- * @see OrderedFsSet_array#clear()
- */
- @Override
- public void clear() {
- set.clear();
- }
-
- /**
- * @see OrderedFsSet_array#lower(TOP)
- */
- @Override
- public TOP lower(TOP fs) {
- return set.lower(fs);
- }
-
- /**
- * @see OrderedFsSet_array#lowerPos(TOP)
- * @param fs the Feature Structure to use for positioning
- * @return -
- */
- public int lowerPos(TOP fs) {
- return set.lowerPos(fs);
- }
-
- /**
- * @see OrderedFsSet_array#floor(TOP)
- */
- @Override
- public TOP floor(TOP fs) {
- return set.floor(fs);
- }
-
- /**
- * @see OrderedFsSet_array#floorPos(TOP)
- * @param fs the Feature Structure to use for positioning
- * @return -
- */
- public int floorPos(TOP fs) {
- return set.floorPos(fs);
- }
-
- /**
- * @see OrderedFsSet_array#ceiling(TOP)
- */
- @Override
- public TOP ceiling(TOP fs) {
- return set.ceiling(fs);
- }
-
- /**
- * @see OrderedFsSet_array#ceilingPos(TOP)
- * @param fs the Feature Structure to use for positioning
- * @return -
- */
- public int ceilingPos(TOP fs) {
- return set.ceilingPos(fs);
- }
-
- /**
- * @see OrderedFsSet_array#higher(TOP)
- */
- @Override
- public TOP higher(TOP fs) {
- return set.higher(fs);
- }
-
- /**
- * @see OrderedFsSet_array#higherPos(TOP)
- * @param fs the Feature Structure to use for positioning
- * @return -
- */
- public int higherPos(TOP fs) {
- return set.higherPos(fs);
- }
-
- /**
- * @see OrderedFsSet_array#pollFirst()
- */
- @Override
- public TOP pollFirst() {
- return set.pollFirst();
- }
-
- /**
- * @see OrderedFsSet_array#pollLast()
- */
- @Override
- public TOP pollLast() {
- return set.pollLast();
- }
-
- /**
- * @see OrderedFsSet_array#iterator()
- */
-// @Override
-// public Iterator<TOP> iterator() {
-// return set.iterator();
+// /**
+// * @return the modification count
+// */
+// public int getModificationCount() {
+// return set.getModificationCount();
// }
- /**
- * @see Iterable#iterator()
- */
- @Override
- public Iterator<TOP> iterator() {
- if (set.isEmpty()) {
- return Collections.emptyIterator();
- }
-
- return new Iterator<TOP>() {
- private int pos = set.a_firstUsedslot;
- { incrToNext(); } // non-static initializer code
-
- @Override
- public boolean hasNext() {
- set.processBatch();
- return pos < set.a_nextFreeslot;
- }
-
- @Override
- public TOP next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- TOP r = set.a[pos++];
- incrToNext();
- return r;
- }
-
- private void incrToNext() {
- while (pos < set.a_nextFreeslot) {
- if (set.a[pos] != null) {
- break;
- }
- pos ++;
- }
- }
-
- };
- }
-
- /**
- * @see OrderedFsSet_array#descendingSet()
- */
- @Override
- public NavigableSet<TOP> descendingSet() {
- throw new UnsupportedOperationException(); // unused
- }
-
- /**
- * @see OrderedFsSet_array#descendingIterator()
- */
-// @Override
-// public Iterator<TOP> descendingIterator() {
-// return set.descendingIterator();
-// }
- /**
- * @see NavigableSet#descendingIterator()
- */
- @Override
- public Iterator<TOP> descendingIterator() {
- set.processBatch();
- return new Iterator<TOP>() {
- private int pos = set.a_nextFreeslot - 1; // 2 slots: next free = 2, first slot = 0
- // 1 slot: next free = 1, first slot = 0
- // 0 slots: next free = 0; first slot = 0 (not -1)
- { if (pos >= 0) { // pos is -1 if set is empty
- decrToNext();
- }
- }
-
- @Override
- public boolean hasNext() {
- return pos >= set.a_firstUsedslot;
- }
-
- @Override
- public TOP next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
-
- TOP r = set.a[pos--];
- decrToNext();
- return r;
- }
-
- private void decrToNext() {
- while (pos >= set.a_firstUsedslot) {
- if (set.a[pos] != null) {
- break;
- }
- pos --;
- }
- }
- };
- }
-
- /**
- * @see OrderedFsSet_array#subSet(TOP, boolean, TOP, boolean)
- */
- @Override
- public NavigableSet<TOP> subSet(TOP fromElement, boolean fromInclusive, TOP toElement,
- boolean toInclusive) {
- return new SubSet(sosa, fromElement, fromInclusive, toElement, toInclusive, false, null);
- }
-
- /**
- * @see OrderedFsSet_array#headSet(TOP, boolean)
- */
- @Override
- public NavigableSet<TOP> headSet(TOP toElement, boolean inclusive) {
- if (isEmpty()) {
- return this;
- }
- return new SubSet(sosa, first(), true, toElement, inclusive, false, null);
- }
-
- /**
- * @see OrderedFsSet_array#tailSet(TOP, boolean)
- */
- @Override
- public NavigableSet<TOP> tailSet(TOP fromElement, boolean inclusive) {
- if (isEmpty()) {
- return this;
- }
- return new SubSet(sosa, fromElement, inclusive, last(), true, false, null);
- }
-
- /**
- * @see OrderedFsSet_array#subSet(TOP, TOP)
- */
- @Override
- public SortedSet<TOP> subSet(TOP fromElement, TOP toElement) {
- return new SubSet(sosa, fromElement, true, toElement, false, false, null);
- }
-
- /**
- * @see OrderedFsSet_array#headSet(TOP)
- */
- @Override
- public SortedSet<TOP> headSet(TOP toElement) {
- return headSet(toElement, false);
- }
-
- /**
- * @see OrderedFsSet_array#tailSet(TOP)
- */
- @Override
- public SortedSet<TOP> tailSet(TOP fromElement) {
- return tailSet(fromElement, true);
- }
-
- /**
- * @return the modification count
- */
- public int getModificationCount() {
- return set.getModificationCount();
- }
/**
* @see OrderedFsSet_array#toString()
@@ -497,6 +105,9 @@ public class CopyOnWriteOrderedFsSet_arr
public String toString() {
return set.toString();
}
-
+
+ public OrderedFsSet_array getOfsa() {
+ return set;
+ }
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java?rev=1802497&r1=1802496&r2=1802497&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/ObjHashSet.java Thu Jul 20 14:44:41 2017
@@ -68,7 +68,7 @@ public class ObjHashSet<T> implements Se
private boolean secondTimeShrinkable = false;
- private int modificationCount = 0;
+// private int modificationCount = 0;
public ObjHashSet(Class<T> clazz, T removedMarker) {
this(12, clazz, removedMarker); // default initial size
@@ -105,9 +105,9 @@ public class ObjHashSet<T> implements Se
this.sizeWhichTriggersExpansion = ohs.sizeWhichTriggersExpansion;
this.size = ohs.size;
this.nbrRemoved = ohs.nbrRemoved;
- this.keys = ohs.keys.clone();
+ this.keys = Arrays.copyOf(ohs.keys, ohs.keys.length);
this.secondTimeShrinkable = ohs.secondTimeShrinkable;
- this.modificationCount = ohs.modificationCount;
+// this.modificationCount = ohs.modificationCount;
}
@@ -121,9 +121,9 @@ public class ObjHashSet<T> implements Se
this.sizeWhichTriggersExpansion = ohs.sizeWhichTriggersExpansion;
this.size = ohs.size;
this.nbrRemoved = ohs.nbrRemoved;
- this.keys = (size == 0) ? emptyKeyArray() : ohs.keys.clone();
+ this.keys = (size == 0) ? emptyKeyArray() : Arrays.copyOf(ohs.keys, ohs.keys.length);
this.secondTimeShrinkable = ohs.secondTimeShrinkable;
- this.modificationCount = ohs.modificationCount;
+// this.modificationCount = ohs.modificationCount;
}
private T[] emptyKeyArray() {
@@ -204,7 +204,7 @@ public class ObjHashSet<T> implements Se
private void resetTable() {
resetHistogram();
size = 0;
- modificationCount ++;
+// modificationCount ++;
}
@Override
@@ -321,7 +321,7 @@ public class ObjHashSet<T> implements Se
}
keys[i] = obj;
incrementSize();
- modificationCount ++;
+// modificationCount ++;
return true;
}
@@ -357,7 +357,7 @@ public class ObjHashSet<T> implements Se
// found, remove it
keys[pos] = removedMarker; // at runtime, this cast is a no-op
size --;
- modificationCount ++;
+// modificationCount ++;
nbrRemoved ++;
return true;
}
@@ -625,11 +625,11 @@ public class ObjHashSet<T> implements Se
return anyChanged;
}
- /**
- * @return the modificiation count
- */
- public int getModificationCount() {
- return modificationCount;
- }
+// /**
+// * @return the modificiation count
+// */
+// public int getModificationCount() {
+// return modificationCount;
+// }
}