OpenHFT / Zero-Allocation-Hashing

Zero-allocation hashing for Java
Apache License 2.0
793 stars 136 forks source link

How to correctly calculate hash for byte[][]? #83

Open ruslangm opened 11 months ago

ruslangm commented 11 months ago

In standard hash functions in Java we can do something like:

Digest digest = new Blake2bDigest(64);
for (int i = 0; i < bytes[0].length; i++) {
    digest.update(bytes[0][i], 0, bytes[0][i].length));
}
byte[] hash = new byte[digest.getDigestSize()];
digest.doFinal(hashResult, 0);
return hash;

I understand that it's not possible to have similar API here since the main goal of this project is to have zero allocations. But what will be the correct way to calculate result hash for an array of arrays? Is there any solution except creating one big byte array and put everything into it? Thanks.