Author: toad
Date: 2009-02-03 18:12:35 +0000 (Tue, 03 Feb 2009)
New Revision: 25501
Modified:
branches/db4o/freenet/src/freenet/keys/CHKBlock.java
branches/db4o/freenet/src/freenet/keys/ClientCHKBlock.java
Log:
More hashCode
Modified: branches/db4o/freenet/src/freenet/keys/CHKBlock.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/CHKBlock.java 2009-02-03
18:07:08 UTC (rev 25500)
+++ branches/db4o/freenet/src/freenet/keys/CHKBlock.java 2009-02-03
18:12:35 UTC (rev 25501)
@@ -4,10 +4,12 @@
package freenet.keys;
import java.security.MessageDigest;
+import java.util.Arrays;
import com.db4o.ObjectContainer;
import freenet.crypt.SHA256;
+import freenet.support.Fields;
/**
* @author amphibian
@@ -21,6 +23,7 @@
final byte[] headers;
final short hashIdentifier;
final NodeCHK chk;
+ final int hashCode;
public static final int MAX_LENGTH_BEFORE_COMPRESSION = Integer.MAX_VALUE;
public static final int TOTAL_HEADERS_LENGTH = 36;
public static final int DATA_LENGTH = 32768;
@@ -67,6 +70,7 @@
// Logger.debug(CHKBlock.class, "Data length: "+data.length+", header
length: "+header.length);
if((key != null) && !verify) {
this.chk = key;
+ hashCode = key.hashCode() ^ Fields.hashCode(data) ^
Fields.hashCode(headers) ^ cryptoAlgorithm;
return;
}
@@ -90,6 +94,7 @@
}
// Otherwise it checks out
}
+ hashCode = key.hashCode() ^ Fields.hashCode(data) ^
Fields.hashCode(headers) ^ cryptoAlgorithm;
}
public Key getKey() {
@@ -116,6 +121,20 @@
return getKey().getRoutingKey();
}
+ public int hashCode() {
+ return hashCode;
+ }
+
+ public boolean equals(Object o) {
+ if(!(o instanceof CHKBlock)) return false;
+ CHKBlock block = (CHKBlock) o;
+ if(!chk.equals(block.chk)) return false;
+ if(!Arrays.equals(data, block.data)) return false;
+ if(!Arrays.equals(headers, block.headers)) return false;
+ if(hashIdentifier != block.hashIdentifier) return false;
+ return true;
+ }
+
public boolean objectCanNew(ObjectContainer container) {
/* Storing an SSKBlock is not supported. There are some
complications, so lets
* not implement this since we don't actually use the
functionality atm.
Modified: branches/db4o/freenet/src/freenet/keys/ClientCHKBlock.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/ClientCHKBlock.java 2009-02-03
18:07:08 UTC (rev 25500)
+++ branches/db4o/freenet/src/freenet/keys/ClientCHKBlock.java 2009-02-03
18:12:35 UTC (rev 25501)
@@ -239,4 +239,14 @@
throw new UnsupportedOperationException("ClientCHKBlock storage
in database not supported");
}
+ public int hashCode() {
+ return key.hashCode;
+ }
+
+ public boolean equals(Object o) {
+ if(!(o instanceof ClientCHKBlock)) return false;
+ ClientCHKBlock block = (ClientCHKBlock) o;
+ if(!key.equals(block.key)) return false;
+ return super.equals(o);
+ }
}
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs