summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java
diff options
context:
space:
mode:
authorErich Schubert <erich@debian.org>2012-12-14 20:45:15 +0100
committerAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:35 +0000
commit357b2761a2c0ded8cad5e4d3c1e667b7639ff7a6 (patch)
tree3dd8947bb70a67c221adc3cd4359ba1d385e2f3c /src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java
parent4343785ebed9d4145f417d86d581f18a0d31e4ac (diff)
parentb7b404fd7a726774d442562d11659d7b5368cdb9 (diff)
Import Debian changes 0.5.5-1
elki (0.5.5-1) unstable; urgency=low * New upstream release: 0.5.5 interim release.
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java b/src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java
index 2b22eba2..75f2abcf 100644
--- a/src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java
+++ b/src/de/lmu/ifi/dbs/elki/utilities/datastructures/heap/TopBoundedUpdatableHeap.java
@@ -36,12 +36,7 @@ import java.util.Comparator;
*/
public class TopBoundedUpdatableHeap<E> extends UpdatableHeap<E> {
/**
- * Serial version
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Maximum size
+ * Maximum size.
*/
protected int maxsize;
@@ -67,22 +62,19 @@ public class TopBoundedUpdatableHeap<E> extends UpdatableHeap<E> {
}
@Override
- public boolean offerAt(int pos, E e) {
+ public void offerAt(int pos, E e) {
// don't add if we hit maxsize and are worse
- if(pos == NO_VALUE && super.size() >= maxsize) {
- ensureValid();
- if(compare(e, queue[0]) < 0) {
- // while we did not change, this still was "successful".
- return true;
- }
- // pos = index.get(e); // Should not be needed.
+ if (pos != NO_VALUE || super.size() < maxsize) {
+ super.offerAt(pos, e);
+ return;
}
- boolean result = super.offerAt(pos, e);
- // purge unneeded entry(s)
- while(super.size() > maxsize) {
- handleOverflow(super.poll());
+ ensureValid();
+ if (compare(e, queue[0]) < 0) {
+ // while we did not change, this still was "successful".
+ return;
}
- return result;
+ E prev = super.replaceTopElement(e);
+ handleOverflow(prev);
}
/**
@@ -93,12 +85,11 @@ public class TopBoundedUpdatableHeap<E> extends UpdatableHeap<E> {
* @return True when an update is needed
*/
protected int compare(Object e, Object object) {
- if(comparator == null) {
+ if (comparator == null) {
@SuppressWarnings("unchecked")
Comparable<Object> c = (Comparable<Object>) e;
return c.compareTo(queue[0]);
- }
- else {
+ } else {
return comparator.compare(e, queue[0]);
}
}
@@ -114,9 +105,11 @@ public class TopBoundedUpdatableHeap<E> extends UpdatableHeap<E> {
}
/**
+ * Get the maximum size.
+ *
* @return the maximum size
*/
public int getMaxSize() {
return maxsize;
}
-} \ No newline at end of file
+}