divijvaidya commented on code in PR #12685: URL: https://github.com/apache/kafka/pull/12685#discussion_r1264409803
########## clients/src/main/java/org/apache/kafka/common/utils/Utils.java: ########## @@ -517,6 +519,50 @@ public static int murmur2(final byte[] data) { return h; } + /** + * Generates 32 bit murmur2 hash from ByteBuffer + * @param data ByteBuffer to hash + * @return 32 bit hash of the given ByteBuffer + */ + @SuppressWarnings("fallthrough") + public static int murmur2(ByteBuffer data) { + final int length = data.remaining(); + final int seed = 0x9747b28c; + // 'm' and 'r' are mixing constants generated offline. + // They're not really 'magic', they just happen to work well. + final int m = 0x5bd1e995; + final int r = 24; + + // Initialize the hash to a random value + int h = seed ^ length; + final int length4 = length / 4; + data = data.order() == LITTLE_ENDIAN ? data : data.slice().order(LITTLE_ENDIAN); Review Comment: > I don't think it's necessary to do that can you help me understand how this works? I am concerned about the fact that murmur2 requires little endian order but incoming data could be in big endian format. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org