Replies: 4 comments 6 replies
-
You didn't specify why it did not work, but I assume your byte buffers are allocated incorrectly, see https://blog.lwjgl.org/memory-management-in-lwjgl-3/. |
Beta Was this translation helpful? Give feedback.
-
Instead of: The former allocates an on-heap (non-direct) ByteBuffer, which no native API exposed by LWJGL 3 supports. |
Beta Was this translation helpful? Give feedback.
-
Although it works, I thought it will produce the same hash string as the nodejs implementations but it doesn't :( const addon = require('xxhash-addon');
const SEED = 1999999;
const hash128seed = new addon.XXHash128(SEED);
function logHash(hasher, str) {
const buffer = Buffer.from(str);
const hash = hasher.hash(buffer).toString('hex');
console.log(hash);
}
const key = 'key';
logHash(hash128seed, key); package com.company;
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
import org.lwjgl.util.xxhash.*;
import java.nio.*;
import static org.lwjgl.util.xxhash.XXHash.*;
final class Main {
private Main() {
}
public static void main(String[] args) {
int SEED = 1999999;
String key = "key";
System.out.println(key);
//Convert string to ByteBuffer:
ByteBuffer buffer = org.lwjgl.system.MemoryUtil.memUTF8(key);
XXH128Hash hash128 = XXH128(buffer, SEED, XXH128Hash.create());
System.out.format("%x%x\n", hash128.high64(), hash128.low64());
}
} nodejs xxHash -> Am I doing something wrong here or implementation is a bit different and won't get the same results? Any ideas? |
Beta Was this translation helpful? Give feedback.
-
Is it processing a null byte as the last entry for Java and no null byte in
JavaScript? I believe memUTF8 takes a second argument which says whether or
not it should add a null byte to the ByteBuffer, which could least to
different results since it defaults to true.
…On Mon, Mar 8, 2021, 07:39 stychu ***@***.***> wrote:
Yeah I've checked the nodejs package that I use and it uses v0.7.3 and
seems all hashes are different no matter if it's 32/64/128.
That's a bummer.
Maybe in the future, they will update it to v0.8.0 and then I would be
able to use LWJGL. For now, I'm forced to use
https://github.com/lz4/lz4-java as I get the same hashes between java and
nodejs.
Thanks for your inputs guys! Keep the good work
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#625 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADTJ6QFY6MZAVYNZZBKVUIDTCTHRXANCNFSM4YVSQHHA>
.
|
Beta Was this translation helpful? Give feedback.
-
How can I use your xxhash module to do hashing on a string? I can't manage to do so. Seems like this module is the only one currently available on the internet that contains xxHash128 bit version and I would like to use it to hash some strings.
Could you advise me on how to do so?
This doesn't work for me
Beta Was this translation helpful? Give feedback.
All reactions