Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- fixed bug in ordering - fixed ConcurrentModificationException in set join

orbiter0ce17d823a02
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<Segment> {
}
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<Integer> 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<Integer> a, Collection<Integer> 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<Integer> a, Collection<Integer> 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<Integer> a) {
- assert a != null;
- if (a.size() == 0) return -1;
+ if (a == null || a.size() == 0) return Integer.MIN_VALUE;
Iterator<Integer> 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<Integer> a) {
- assert a != null;
- if (a.size() == 0) return -1;
+ if (a == null || a.size() == 0) return Integer.MAX_VALUE;
Iterator<Integer> 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 <r) r = s;
+ if (s < r) r = s;
}
return r;
}
public int maxposition() {
- assert positions().size() > 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 <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());
- synchronized (mi) {
+ synchronized (small) {
+ final Iterator<Map.Entry<A, B>> mi = small.entrySet().iterator();
Map.Entry<A, B> 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()));