From 0ce17d823a028a8a2ce7360b17bb460e51d81823 Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 24 Feb 2011 10:32:46 +0000 Subject: [PATCH] - 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 --- source/de/anomic/search/Segments.java | 2 ++ .../yacy/kelondro/rwi/AbstractReference.java | 31 +++++++++---------- source/net/yacy/kelondro/util/SetTools.java | 8 +++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/de/anomic/search/Segments.java b/source/de/anomic/search/Segments.java index d8df58835..5e9aaf63e 100644 --- a/source/de/anomic/search/Segments.java +++ b/source/de/anomic/search/Segments.java @@ -157,12 +157,14 @@ public class Segments implements Iterable { } public long RWICount() { + if (this.segments == null) return 0; long c = 0; for (Segment s: this.segments.values()) c += (long) s.termIndex().sizesMax(); return c; } public int RWIBufferCount() { + if (this.segments == null) return 0; int c = 0; for (Segment s: this.segments.values()) c += s.termIndex().getBufferSize(); return c; diff --git a/source/net/yacy/kelondro/rwi/AbstractReference.java b/source/net/yacy/kelondro/rwi/AbstractReference.java index 0429e0821..83ea4c982 100644 --- a/source/net/yacy/kelondro/rwi/AbstractReference.java +++ b/source/net/yacy/kelondro/rwi/AbstractReference.java @@ -34,32 +34,34 @@ public abstract class AbstractReference implements Reference { protected static void a(Collection a, int i) { 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.add(i); } protected static int max(Collection a, Collection b) { - assert a != null; - if (a.size() == 0) return max(b); - if (b.size() == 0) return max(a); - return Math.max(max(a), max(b)); + if (a == null || a.size() == 0) return max(b); + if (b == null || b.size() == 0) return max(a); + int ma = max(a); + 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 a, Collection b) { assert a != null; - if (a.size() == 0) return min(b); - if (b.size() == 0) return min(a); + if (a == null || a.size() == 0) return min(b); + if (b == null || b.size() == 0) return min(a); int ma = min(a); int mb = min(b); - if (ma == -1) return mb; - if (mb == -1) return ma; + if (ma == Integer.MAX_VALUE) return mb; + if (mb == Integer.MAX_VALUE) return ma; return Math.min(ma, mb); } private static int max(Collection a) { - assert a != null; - if (a.size() == 0) return -1; + if (a == null || a.size() == 0) return Integer.MIN_VALUE; Iterator i = a.iterator(); if (a.size() == 1) return 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 a) { - assert a != null; - if (a.size() == 0) return -1; + if (a == null || a.size() == 0) return Integer.MAX_VALUE; Iterator i = a.iterator(); if (a.size() == 1) return i.next(); if (a.size() == 2) return Math.min(i.next(), i.next()); @@ -82,18 +83,16 @@ public abstract class AbstractReference implements Reference { int s; while (i.hasNext()) { s = i.next(); - if (s 0; return max(positions()); } public int minposition() { - assert positions().size() > 0; return min(positions()); } diff --git a/source/net/yacy/kelondro/util/SetTools.java b/source/net/yacy/kelondro/util/SetTools.java index 385260a2c..de190b8ba 100644 --- a/source/net/yacy/kelondro/util/SetTools.java +++ b/source/net/yacy/kelondro/util/SetTools.java @@ -136,15 +136,17 @@ public final class SetTools { @SuppressWarnings("unchecked") private static SortedMap joinConstructiveByTest(final SortedMap small, final SortedMap large, final boolean concatStrings) { - final Iterator> mi = small.entrySet().iterator(); final SortedMap result = new TreeMap(large.comparator()); - synchronized (mi) { + synchronized (small) { + final Iterator> mi = small.entrySet().iterator(); Map.Entry mentry1; B mobj2; loop: while (mi.hasNext()) { try { mentry1 = mi.next(); - mobj2 = large.get(mentry1.getKey()); + synchronized (large) { + mobj2 = large.get(mentry1.getKey()); + } if (mobj2 != null) { if (mentry1.getValue() instanceof String) { result.put(mentry1.getKey(), (B) ((concatStrings) ? (mentry1.getValue() + (String) mobj2) : mentry1.getValue()));