From abb52649295b8a62584087e4484a7d15eb98fd6f Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 18 Jul 2006 11:52:56 +0000 Subject: [PATCH] fix for http://www.yacy-forum.de/viewtopic.php?p=23868#23868 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2300 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/htmlFilter/htmlFilterImageEntry.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/htmlFilter/htmlFilterImageEntry.java b/source/de/anomic/htmlFilter/htmlFilterImageEntry.java index 77b3de8b0..4d40d4293 100644 --- a/source/de/anomic/htmlFilter/htmlFilterImageEntry.java +++ b/source/de/anomic/htmlFilter/htmlFilterImageEntry.java @@ -76,6 +76,10 @@ public class htmlFilterImageEntry implements Comparable { } public int hashCode() { + // if htmlFilterImageEntry elements are stored in a TreeSet, the biggest images shall be listed first + // this hash method therefore tries to compute a 'perfect hash' based on the size of the images + // unfortunately it can not be ensured that all images get different hashes, but this should appear + // only in very rare cases if ((width > 0) && (height > 0)) return ((0xFFFF - (((width * height) >> 8) & 0xFFFF)) << 16) | (url.hashCode() & 0xFFFF); else @@ -84,6 +88,9 @@ public class htmlFilterImageEntry implements Comparable { public int compareTo(Object h) { // this is needed if this object is stored in a TreeSet + // this method uses the image-size ordering from the hashCode method + // assuming that hashCode would return a 'perfect hash' this method would + // create a total ordering on images with respect on the image size assert (url != null); assert (h instanceof htmlFilterImageEntry); if (this.url.toString().equals(((htmlFilterImageEntry) h).url.toString())) return 0; @@ -91,7 +98,7 @@ public class htmlFilterImageEntry implements Comparable { int ohc = ((htmlFilterImageEntry) h).hashCode(); if (thc < ohc) return -1; if (thc > ohc) return 1; - return 0; + return this.url.toString().compareTo(((htmlFilterImageEntry) h).url.toString()); } public boolean equals(Object o) {