You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ra...@apache.org on 2017/01/18 11:31:31 UTC
hbase git commit: HBASE-17483 Add equals/hashcode for OffheapKeyValue
(Ram)
Repository: hbase
Updated Branches:
refs/heads/master b779143fd -> 406f66a4e
HBASE-17483 Add equals/hashcode for OffheapKeyValue (Ram)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/406f66a4
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/406f66a4
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/406f66a4
Branch: refs/heads/master
Commit: 406f66a4e89f0d3a52225bce6a5a33cf54b9d75c
Parents: b779143
Author: Ramkrishna <ra...@intel.com>
Authored: Wed Jan 18 17:00:57 2017 +0530
Committer: Ramkrishna <ra...@intel.com>
Committed: Wed Jan 18 17:00:57 2017 +0530
----------------------------------------------------------------------
.../apache/hadoop/hbase/OffheapKeyValue.java | 34 ++++++++++++++++++++
1 file changed, 34 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/406f66a4/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java
----------------------------------------------------------------------
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java
index ab1f6ef..c08927c 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/OffheapKeyValue.java
@@ -310,4 +310,38 @@ public class OffheapKeyValue extends ByteBufferCell implements ExtendedCell {
kv.setSequenceId(this.getSequenceId());
return kv;
}
+
+ /**
+ * Needed doing 'contains' on List. Only compares the key portion, not the value.
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof Cell)) {
+ return false;
+ }
+ return CellUtil.equals(this, (Cell) other);
+ }
+
+ /**
+ * In line with {@link #equals(Object)}, only uses the key portion, not the value.
+ */
+ @Override
+ public int hashCode() {
+ return calculateHashForKey(this);
+ }
+
+ private int calculateHashForKey(ByteBufferCell cell) {
+ int rowHash = ByteBufferUtils.hashCode(cell.getRowByteBuffer(), cell.getRowPosition(),
+ cell.getRowLength());
+ int familyHash = ByteBufferUtils.hashCode(cell.getFamilyByteBuffer(), cell.getFamilyPosition(),
+ cell.getFamilyLength());
+ int qualifierHash = ByteBufferUtils.hashCode(cell.getQualifierByteBuffer(),
+ cell.getQualifierPosition(), cell.getQualifierLength());
+
+ int hash = 31 * rowHash + familyHash;
+ hash = 31 * hash + qualifierHash;
+ hash = 31 * hash + (int) cell.getTimestamp();
+ hash = 31 * hash + cell.getTypeByte();
+ return hash;
+ }
}