.hashcode and .equals need to use storage with offsets; no more super methods.
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java
index 5ca7946..e042840 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerBytesWritable.java
@@ -25,6 +25,7 @@
import org.apache.hadoop.io.WritableComparator;
import edu.uci.ics.genomix.data.KmerUtil;
+import edu.uci.ics.genomix.data.Marshal;
/**
* Fixed, static-length Kmer used as the key and edge values of each
@@ -152,7 +153,7 @@
public static int getKmerLength() {
return lettersInKmer;
}
-
+
public static int getBytesPerKmer() {
return bytesUsed;
}
@@ -333,13 +334,21 @@
@Override
public int hashCode() {
- return super.hashCode() * 31 + lettersInKmer;
+ return Marshal.hashBytes(bytes, offset, bytesUsed);
}
@Override
public boolean equals(Object right_obj) {
- if (right_obj instanceof KmerBytesWritable)
- return super.equals(right_obj);
+ if (right_obj instanceof KmerBytesWritable) {
+ // since these may be backed by storage of different sizes, we have to manually check each byte
+ KmerBytesWritable right = (KmerBytesWritable) right_obj;
+ for (int i=0; i < bytesUsed; i++) {
+ if (bytes[offset + i] != right.bytes[right.offset + i]) {
+ return false;
+ }
+ }
+ return true;
+ }
return false;
}
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerListWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerListWritable.java
index 995643e..b021e1d 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerListWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/KmerListWritable.java
@@ -15,10 +15,6 @@
/**
* A list of fixed-length kmers. The length of this list is stored internally.
*/
- @Override
- public int hashCode() {
- return Marshal.hashBytes(getByteArray(), getStartOffset(), getLength());
- }
public class KmerListWritable implements Writable, Iterable<KmerBytesWritable>, Serializable {
private static final long serialVersionUID = 1L;
protected static final byte[] EMPTY_BYTES = { 0, 0, 0, 0 };
@@ -252,4 +248,8 @@
return sbuilder.toString();
}
+ @Override
+ public int hashCode() {
+ return Marshal.hashBytes(getByteArray(), getStartOffset(), getLength());
+ }
}
diff --git a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/VKmerBytesWritable.java b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/VKmerBytesWritable.java
index 133724b..48fc388 100644
--- a/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/VKmerBytesWritable.java
+++ b/genomix/genomix-data/src/main/java/edu/uci/ics/genomix/type/VKmerBytesWritable.java
@@ -329,9 +329,21 @@
}
@Override
- public boolean equals(Object right) {
- if (right instanceof VKmerBytesWritable) {
- return lettersInKmer == ((VKmerBytesWritable) right).lettersInKmer && super.equals(right); // compare bytes directly
+ public int hashCode() {
+ return Marshal.hashBytes(bytes, kmerStartOffset - HEADER_SIZE, bytesUsed + HEADER_SIZE);
+ }
+
+ @Override
+ public boolean equals(Object right_obj) {
+ if (right_obj instanceof VKmerBytesWritable) {
+ // since these may be backed by storage of different sizes, we have to manually check each byte, including the header
+ VKmerBytesWritable right = (VKmerBytesWritable) right_obj;
+ for (int i = -HEADER_SIZE; i < bytesUsed; i++) {
+ if (bytes[kmerStartOffset + i] != right.bytes[right.kmerStartOffset + i]) {
+ return false;
+ }
+ }
+ return true;
}
return false;
}