Skip to content

Commit

Permalink
fix: adding hashcode usage changes in vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
vibhatha committed Sep 2, 2024
1 parent 56e7161 commit cbd4f7a
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ private static int memcmp(
}

/** Compute hashCode with the given {@link ArrowBuf} and start/end index. */
public static int hash(final ArrowBuf buf, long start, long end) {
public static long hash(final ArrowBuf buf, long start, long end) {

return hash(SimpleHasher.INSTANCE, buf, start, end);
}

/**
* Compute hashCode with the given {@link ArrowBufHasher}, {@link ArrowBuf} and start/end index.
*/
public static final int hash(ArrowBufHasher hasher, final ArrowBuf buf, long start, long end) {
public static final long hash(ArrowBufHasher hasher, final ArrowBuf buf, long start, long end) {

if (hasher == null) {
hasher = SimpleHasher.INSTANCE;
Expand All @@ -313,7 +313,7 @@ public static final int hash(ArrowBufHasher hasher, final ArrowBuf buf, long sta
}

/** Generate a new hashCode with the given current hashCode and new hashCode. */
public static int combineHash(int currentHash, int newHash) {
public static long combineHash(long currentHash, long newHash) {
return currentHash * 31 + newHash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public int hashCode(int index, ArrowBufHasher hasher) {
}
long start = (long) typeWidth * index;
long end = (long) typeWidth * (index + 1);
return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end);
return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ public int hashCode(int index, ArrowBufHasher hasher) {
}
final long start = getStartOffset(index);
final long end = getEndOffset(index);
return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end);
return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ public int hashCode(int index, ArrowBufHasher hasher) {
}
final int start = getStartOffset(index);
final int end = getEndOffset(index);
return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end);
return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1600,15 +1600,15 @@ public int hashCode(int index, ArrowBufHasher hasher) {
final int length = getValueLength(index);
if (length < INLINE_SIZE) {
int start = index * ELEMENT_SIZE + LENGTH_WIDTH;
return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, start + length);
return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, start + length);
} else {
final int bufIndex =
viewBuffer.getInt(((long) index * ELEMENT_SIZE) + LENGTH_WIDTH + PREFIX_WIDTH);
final int dataOffset =
viewBuffer.getInt(
((long) index * ELEMENT_SIZE) + LENGTH_WIDTH + PREFIX_WIDTH + BUF_INDEX_WIDTH);
ArrowBuf dataBuf = dataBuffers.get(bufIndex);
return ByteFunctionHelpers.hash(hasher, dataBuf, dataOffset, dataOffset + length);
return (int) ByteFunctionHelpers.hash(hasher, dataBuf, dataOffset, dataOffset + length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ public int hashCode(int index, ArrowBufHasher hasher) {
}
int hash = 0;
for (int i = 0; i < listSize; i++) {
hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(index * listSize + i, hasher));
hash =
(int)
ByteFunctionHelpers.combineHash(hash, vector.hashCode(index * listSize + i, hasher));
}
return hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ public int hashCode(int index, ArrowBufHasher hasher) {
final long start = offsetBuffer.getLong((long) index * OFFSET_WIDTH);
final long end = offsetBuffer.getLong(((long) index + 1L) * OFFSET_WIDTH);
for (long i = start; i < end; i++) {
hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher));
hash =
(int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher));
}
return hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ public int hashCode(int index, ArrowBufHasher hasher) {
final int start = offsetBuffer.getInt((long) index * OFFSET_WIDTH);
final int end = sizeBuffer.getInt((long) index * OFFSET_WIDTH);
for (int i = start; i < end; i++) {
hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher));
hash =
(int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher));
}
return hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public int hashCode(int index, ArrowBufHasher hasher) {
final int start = offsetBuffer.getInt(index * OFFSET_WIDTH);
final int end = offsetBuffer.getInt((index + 1) * OFFSET_WIDTH);
for (int i = start; i < end; i++) {
hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher));
hash = (int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher));
}
return hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public int hashCode(int index, ArrowBufHasher hasher) {
final int start = offsetBuffer.getInt(index * OFFSET_WIDTH);
final int end = sizeBuffer.getInt(index * OFFSET_WIDTH);
for (int i = start; i < end; i++) {
hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher));
hash = (int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher));
}
return hash;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public int hashCode(int index, ArrowBufHasher hasher) {
int hash = 0;
for (FieldVector v : getChildren()) {
if (index < v.getValueCount()) {
hash = ByteFunctionHelpers.combineHash(hash, v.hashCode(index, hasher));
hash = (int) ByteFunctionHelpers.combineHash(hash, v.hashCode(index, hasher));
}
}
return hash;
Expand Down

0 comments on commit cbd4f7a

Please sign in to comment.