Skip to content

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

fix for bug in SortStack (did not appear to shrink according to required size) - caused bad and unsufficient search results

orbiter93caa38d5572
diff --git a/source/net/yacy/kelondro/util/SortStack.java b/source/net/yacy/kelondro/util/SortStack.java
index 3ffdd464e..a4f29adb6 100644
--- a/source/net/yacy/kelondro/util/SortStack.java
+++ b/source/net/yacy/kelondro/util/SortStack.java
@@ -62,6 +62,13 @@ public class SortStack<E> {
}
public int size() {
+ /*
+ int c = 0;
+ synchronized (onstack) {
+ for (List<E> l: onstack.values()) c += l.size();
+ assert c == this.instack.size() : "c = " + c + "; this.size() = " + this.instack.size();
+ }
+ */
return this.instack.size();
}
@@ -71,10 +78,10 @@ public class SortStack<E> {
* @param weight
*/
public void push(final E element, Long weight) {
- if (this.instack.put(element, PRESENT) != null) return;
-
// put the element on the stack
synchronized (this.onstack) {
+ if (this.instack.put(element, PRESENT) != null) return;
+
List<E> l = this.onstack.get(weight);
if (l == null) {
l = new LinkedList<E>();
@@ -83,13 +90,15 @@ public class SortStack<E> {
} else {
l.add(element);
}
+ //this.instack.put(element, PRESENT);
}
-
// check maximum size of the stack an remove elements if the stack gets too large
if (this.maxsize <= 0) return;
while (!this.onstack.isEmpty() && this.onstack.size() > this.maxsize) synchronized (this.onstack) {
+ List<E> l;
if (!this.onstack.isEmpty() && this.onstack.size() > this.maxsize) {
- this.onstack.remove(this.onstack.lastKey());
+ l = this.onstack.remove(this.onstack.lastKey());
+ for (E e: l) instack.remove(e);
}
}
}
@@ -137,9 +146,8 @@ public class SortStack<E> {
}
public void remove(final E element) {
- if (!this.instack.contains(element)) return;
-
synchronized (this.onstack) {
+ if (!this.instack.contains(element)) return;
for (Map.Entry<Long,List<E>> entry: this.onstack.entrySet()) {
Iterator<E> i = entry.getValue().iterator();
while (i.hasNext()) {