Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19222#discussion_r176985312
--- Diff:
common/unsafe/src/main/java/org/apache/spark/unsafe/hash/Murmur3_x86_32.java ---
@@ -49,49 +51,70 @@ public static int hashInt(int input, int seed) {
}
public int hashUnsafeWords(Object base, long offset, int lengthInBytes) {
- return hashUnsafeWords(base, offset, lengthInBytes, seed);
+ return hashUnsafeWordsBlock(MemoryBlock.allocateFromObject(base,
offset, lengthInBytes), seed);
}
- public static int hashUnsafeWords(Object base, long offset, int
lengthInBytes, int seed) {
+ public static int hashUnsafeWordsBlock(MemoryBlock base, int seed) {
// This is based on Guava's
`Murmur32_Hasher.processRemaining(ByteBuffer)` method.
+ int lengthInBytes = Ints.checkedCast(base.size());
assert (lengthInBytes % 8 == 0): "lengthInBytes must be a multiple of
8 (word-aligned)";
- int h1 = hashBytesByInt(base, offset, lengthInBytes, seed);
+ int h1 = hashBytesByIntBlock(base, seed);
return fmix(h1, lengthInBytes);
}
- public static int hashUnsafeBytes(Object base, long offset, int
lengthInBytes, int seed) {
+ public static int hashUnsafeWords(Object base, long offset, int
lengthInBytes, int seed) {
+ // This is based on Guava's
`Murmur32_Hasher.processRemaining(ByteBuffer)` method.
+ assert (lengthInBytes % 8 == 0): "lengthInBytes must be a multiple of
8 (word-aligned)";
+ return hashUnsafeWordsBlock(MemoryBlock.allocateFromObject(base,
offset, lengthInBytes), seed);
+ }
+
+ public static int hashUnsafeBytesBlock(MemoryBlock base, int seed) {
// This is not compatible with original and another implementations.
// But remain it for backward compatibility for the components
existing before 2.3.
+ long offset = base.getBaseOffset();
+ long lengthInBytes = base.size();
--- End diff --
shall we cast to int here instead of at the end?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]