Skip to content

Commit

Permalink
fix: int to long usage in hash operations
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Sep 2, 2024
1 parent 2f6752e commit ec9b014
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ protected SimpleHasher() {}
*/
@Override
public long hashCode(long address, long length) {
int hashValue = 0;
long hashValue = 0;
int index = 0;
while (index + 8 <= length) {
long longValue = MemoryUtil.getLong(address + index);
int longHash = getLongHashCode(longValue);
long longHash = getLongHashCode(longValue);
hashValue = combineHashCode(hashValue, longHash);
index += 8;
}
Expand Down Expand Up @@ -89,15 +89,15 @@ public long hashCode(ArrowBuf buf, long offset, long length) {
return hashCode(buf.memoryAddress() + offset, length);
}

protected int combineHashCode(int currentHashCode, int newHashCode) {
protected long combineHashCode(long currentHashCode, long newHashCode) {
return currentHashCode * 37 + newHashCode;
}

protected int getLongHashCode(long longValue) {
return Long.hashCode(longValue);
}

protected int finalizeHashCode(int hashCode) {
protected long finalizeHashCode(long hashCode) {
return hashCode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ void testHasher(String name, ArrowBufHasher hasher) {
private void verifyHashCodesEqual(
ArrowBufHasher hasher,
ArrowBuf buf1,
int offset1,
int length1,
long offset1,
long length1,
ArrowBuf buf2,
int offset2,
int length2) {
int hashCode1 = (int) hasher.hashCode(buf1, offset1, length1);
int hashCode2 = (int) hasher.hashCode(buf2, offset2, length2);
long offset2,
long length2) {
long hashCode1 = hasher.hashCode(buf1, offset1, length1);
long hashCode2 = hasher.hashCode(buf2, offset2, length2);

assertEquals(hashCode1, hashCode2);
}

Expand Down Expand Up @@ -118,8 +119,8 @@ public void testHasherLessThanInt(String name, ArrowBufHasher hasher) {

private void verifyHashCodeNotEqual(
ArrowBufHasher hasher, ArrowBuf buf1, int length1, ArrowBuf buf2, int length2) {
int hashCode1 = (int) hasher.hashCode(buf1, 0, length1);
int hashCode2 = (int) hasher.hashCode(buf2, 0, length2);
long hashCode1 = hasher.hashCode(buf1, 0, length1);
long hashCode2 = hasher.hashCode(buf2, 0, length2);
assertNotEquals(hashCode1, hashCode2);
}

Expand Down

0 comments on commit ec9b014

Please sign in to comment.