- fixed bug in ordering

- fixed ConcurrentModificationException in set join


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7519 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent dec4f36700
commit 0ce17d823a

@ -157,12 +157,14 @@ public class Segments implements Iterable<Segment> {
} }
public long RWICount() { public long RWICount() {
if (this.segments == null) return 0;
long c = 0; long c = 0;
for (Segment s: this.segments.values()) c += (long) s.termIndex().sizesMax(); for (Segment s: this.segments.values()) c += (long) s.termIndex().sizesMax();
return c; return c;
} }
public int RWIBufferCount() { public int RWIBufferCount() {
if (this.segments == null) return 0;
int c = 0; int c = 0;
for (Segment s: this.segments.values()) c += s.termIndex().getBufferSize(); for (Segment s: this.segments.values()) c += s.termIndex().getBufferSize();
return c; return c;

@ -34,32 +34,34 @@ public abstract class AbstractReference implements Reference {
protected static void a(Collection<Integer> a, int i) { protected static void a(Collection<Integer> a, int i) {
assert a != null; assert a != null;
if (i < 0) return; // signal for 'do nothing' if (i == Integer.MAX_VALUE || i == Integer.MIN_VALUE) return; // signal for 'do nothing'
a.clear(); a.clear();
a.add(i); a.add(i);
} }
protected static int max(Collection<Integer> a, Collection<Integer> b) { protected static int max(Collection<Integer> a, Collection<Integer> b) {
assert a != null; if (a == null || a.size() == 0) return max(b);
if (a.size() == 0) return max(b); if (b == null || b.size() == 0) return max(a);
if (b.size() == 0) return max(a); int ma = max(a);
return Math.max(max(a), max(b)); int mb = max(b);
if (ma == Integer.MIN_VALUE) return mb;
if (mb == Integer.MIN_VALUE) return ma;
return Math.max(ma, mb);
} }
protected static int min(Collection<Integer> a, Collection<Integer> b) { protected static int min(Collection<Integer> a, Collection<Integer> b) {
assert a != null; assert a != null;
if (a.size() == 0) return min(b); if (a == null || a.size() == 0) return min(b);
if (b.size() == 0) return min(a); if (b == null || b.size() == 0) return min(a);
int ma = min(a); int ma = min(a);
int mb = min(b); int mb = min(b);
if (ma == -1) return mb; if (ma == Integer.MAX_VALUE) return mb;
if (mb == -1) return ma; if (mb == Integer.MAX_VALUE) return ma;
return Math.min(ma, mb); return Math.min(ma, mb);
} }
private static int max(Collection<Integer> a) { private static int max(Collection<Integer> a) {
assert a != null; if (a == null || a.size() == 0) return Integer.MIN_VALUE;
if (a.size() == 0) return -1;
Iterator<Integer> i = a.iterator(); Iterator<Integer> i = a.iterator();
if (a.size() == 1) return i.next(); if (a.size() == 1) return i.next();
if (a.size() == 2) return Math.max(i.next(), i.next()); if (a.size() == 2) return Math.max(i.next(), i.next());
@ -73,8 +75,7 @@ public abstract class AbstractReference implements Reference {
} }
private static int min(Collection<Integer> a) { private static int min(Collection<Integer> a) {
assert a != null; if (a == null || a.size() == 0) return Integer.MAX_VALUE;
if (a.size() == 0) return -1;
Iterator<Integer> i = a.iterator(); Iterator<Integer> i = a.iterator();
if (a.size() == 1) return i.next(); if (a.size() == 1) return i.next();
if (a.size() == 2) return Math.min(i.next(), i.next()); if (a.size() == 2) return Math.min(i.next(), i.next());
@ -88,12 +89,10 @@ public abstract class AbstractReference implements Reference {
} }
public int maxposition() { public int maxposition() {
assert positions().size() > 0;
return max(positions()); return max(positions());
} }
public int minposition() { public int minposition() {
assert positions().size() > 0;
return min(positions()); return min(positions());
} }

@ -136,15 +136,17 @@ public final class SetTools {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <A, B> SortedMap<A, B> joinConstructiveByTest(final SortedMap<A, B> small, final SortedMap<A, B> large, final boolean concatStrings) { private static <A, B> SortedMap<A, B> joinConstructiveByTest(final SortedMap<A, B> small, final SortedMap<A, B> large, final boolean concatStrings) {
final Iterator<Map.Entry<A, B>> mi = small.entrySet().iterator();
final SortedMap<A, B> result = new TreeMap<A, B>(large.comparator()); final SortedMap<A, B> result = new TreeMap<A, B>(large.comparator());
synchronized (mi) { synchronized (small) {
final Iterator<Map.Entry<A, B>> mi = small.entrySet().iterator();
Map.Entry<A, B> mentry1; Map.Entry<A, B> mentry1;
B mobj2; B mobj2;
loop: while (mi.hasNext()) { loop: while (mi.hasNext()) {
try { try {
mentry1 = mi.next(); mentry1 = mi.next();
synchronized (large) {
mobj2 = large.get(mentry1.getKey()); mobj2 = large.get(mentry1.getKey());
}
if (mobj2 != null) { if (mobj2 != null) {
if (mentry1.getValue() instanceof String) { if (mentry1.getValue() instanceof String) {
result.put(mentry1.getKey(), (B) ((concatStrings) ? (mentry1.getValue() + (String) mobj2) : mentry1.getValue())); result.put(mentry1.getKey(), (B) ((concatStrings) ? (mentry1.getValue() + (String) mobj2) : mentry1.getValue()));

Loading…
Cancel
Save