enhanced object hash computation

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6816 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 1a8a134e0c
commit 3a50b5aa04

@ -38,6 +38,7 @@ import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.util.ByteArray;
import net.yacy.repository.LoaderDispatcher;
@ -86,7 +87,7 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaS
@Override
public int hashCode() {
return new String(href.hash()).hashCode();
return ByteArray.hashCode(href.hash());
}
public String toString() {

@ -40,6 +40,7 @@ import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.util.ByteArray;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacySeedDB;
@ -101,7 +102,7 @@ public class ResultEntry implements Comparable<ResultEntry>, Comparator<ResultEn
}
}
public int hashCode() {
return new String(urlentry.hash()).hashCode();
return ByteArray.hashCode(urlentry.hash());
}
public boolean equals(final Object obj) {
if (this == obj) return true;

@ -47,6 +47,7 @@ import net.yacy.kelondro.index.HandleSet;
import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.util.ByteArray;
import net.yacy.kelondro.util.SetTools;
import net.yacy.repository.LoaderDispatcher;
@ -180,7 +181,7 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
return o1.compareTo(o2);
}
public int hashCode() {
return new String(this.url.hash()).hashCode();
return ByteArray.hashCode(this.url.hash());
}
@Override

@ -33,6 +33,7 @@ import net.yacy.kelondro.index.Row.Entry;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.MicroDate;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.util.ByteArray;
public final class CitationReferenceRow implements Reference /*, Cloneable*/ {
@ -181,7 +182,7 @@ public final class CitationReferenceRow implements Reference /*, Cloneable*/ {
@Override
public int hashCode() {
return new String(this.metadataHash()).hashCode();
return ByteArray.hashCode(this.metadataHash());
}
@Override

@ -35,6 +35,7 @@ import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.order.MicroDate;
import net.yacy.kelondro.rwi.AbstractReference;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.util.ByteArray;
/**
* this object stores attributes to URL references inside RWI collections
@ -270,7 +271,7 @@ public final class ImageReferenceRow extends AbstractReference implements /*Imag
}
public int hashCode() {
return new String(this.metadataHash()).hashCode();
return ByteArray.hashCode(this.metadataHash());
}
public void join(Reference oe) {

@ -33,6 +33,7 @@ import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.order.MicroDate;
import net.yacy.kelondro.rwi.AbstractReference;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.util.ByteArray;
public class ImageReferenceVars extends AbstractReference implements ImageReference, Reference, Cloneable {
@ -356,7 +357,7 @@ public class ImageReferenceVars extends AbstractReference implements ImageRefere
}
public int hashCode() {
return new String(this.urlHash).hashCode();
return ByteArray.hashCode(this.urlHash);
}
public void addPosition(int position) {

@ -48,6 +48,7 @@ import jcifs.smb.SmbFileInputStream;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.Base64Order;
import net.yacy.kelondro.order.Digest;
import net.yacy.kelondro.util.ByteArray;
import net.yacy.kelondro.util.Domains;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.Punycode;
@ -747,7 +748,7 @@ public class DigestURI implements Serializable {
*/
@Override
public int hashCode() {
return new String(this.hash()).hashCode();
return ByteArray.hashCode(this.hash());
}
/* (non-Javadoc)

@ -34,6 +34,7 @@ import net.yacy.kelondro.order.Bitfield;
import net.yacy.kelondro.order.MicroDate;
import net.yacy.kelondro.rwi.AbstractReference;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.util.ByteArray;
/**
* this object stores attributes to URL references inside RWI collections
@ -339,7 +340,7 @@ public final class WordReferenceRow extends AbstractReference implements WordRef
@Override
public int hashCode() {
return new String(this.metadataHash()).hashCode();
return ByteArray.hashCode(this.metadataHash());
}
public void join(final Reference oe) {

@ -38,6 +38,7 @@ import net.yacy.kelondro.order.MicroDate;
import net.yacy.kelondro.rwi.AbstractReference;
import net.yacy.kelondro.rwi.Reference;
import net.yacy.kelondro.rwi.ReferenceContainer;
import net.yacy.kelondro.util.ByteArray;
import net.yacy.kelondro.index.Row;
@ -373,7 +374,7 @@ public class WordReferenceVars extends AbstractReference implements WordReferenc
@Override
public int hashCode() {
return new String(this.urlHash).hashCode();
return ByteArray.hashCode(this.urlHash);
}
public int compareTo(final WordReferenceVars o) {

@ -79,15 +79,22 @@ public class ByteArray {
}
public int hashCode() {
if (this.hash != 0) return this.hash;
int l = this.buffer.length;
if (this.hash != 0) return this.hash;
this.hash = hashCode(this.buffer);
return this.hash;
}
/**
* compute a hash code that is equal to the hash computation of String()
* @param b
* @return a hash number
*/
public static int hashCode(byte[] b) {
int h = 0;
while (--l >= 0) h = 31*h + buffer[l];
this.hash = h;
for (byte c: b) h = 31 * h + (c & 0xFF);
return h;
}
public boolean equals(Object other) {
ByteArray b = (ByteArray) other;
if (buffer == null && b == null) return true;
@ -110,7 +117,9 @@ public class ByteArray {
map.put(b, 2);
System.out.println("map.size() = " + map.size());
System.out.println("hashCode(a0) = " + a0.hashCode());
System.out.println("new String(a0).hashCode = " + (new String(a0.asBytes())).hashCode());
System.out.println("hashCode(a1) = " + a1.hashCode());
System.out.println("new String(a1).hashCode = " + (new String(a1.asBytes())).hashCode());
System.out.println("hashCode(b) = " + b.hashCode());
System.out.println("a0 " + ((map.containsKey(a0)) ? "in" : "not in") + " map");
System.out.println("a1 " + ((map.containsKey(a1)) ? "in" : "not in") + " map");

Loading…
Cancel
Save