More hash specifics
This commit is contained in:
parent
3ec189804c
commit
78c3a3c35e
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.7.0
|
projectVersion=2.7.1
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kommons.util;
|
package ru.dbotthepony.kommons.util;
|
||||||
|
|
||||||
|
import java.security.DigestException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -108,8 +109,7 @@ public final class XXHash32 extends MessageDigest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public int digestAsInt() {
|
||||||
protected byte[] engineDigest() {
|
|
||||||
int h32;
|
int h32;
|
||||||
|
|
||||||
if (length >= 16) {
|
if (length >= 16) {
|
||||||
@ -146,6 +146,13 @@ public final class XXHash32 extends MessageDigest {
|
|||||||
|
|
||||||
engineReset();
|
engineReset();
|
||||||
|
|
||||||
|
return h32;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected byte[] engineDigest() {
|
||||||
|
int h32 = digestAsInt();
|
||||||
|
|
||||||
byte[] result = new byte[4];
|
byte[] result = new byte[4];
|
||||||
|
|
||||||
result[0] = (byte) (h32 >>> 24);
|
result[0] = (byte) (h32 >>> 24);
|
||||||
@ -156,6 +163,28 @@ public final class XXHash32 extends MessageDigest {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int engineGetDigestLength() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
|
||||||
|
if (len < 4)
|
||||||
|
throw new DigestException("partial digests not returned");
|
||||||
|
|
||||||
|
if (buf.length - offset < 4)
|
||||||
|
throw new DigestException("insufficient space in the output "
|
||||||
|
+ "buffer to store the digest");
|
||||||
|
|
||||||
|
int h32 = digestAsInt();
|
||||||
|
buf[offset] = (byte) (h32 >>> 24);
|
||||||
|
buf[offset + 1] = (byte) (h32 >>> 16);
|
||||||
|
buf[offset + 2] = (byte) (h32 >>> 8);
|
||||||
|
buf[offset + 3] = (byte) (h32);
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void engineReset() {
|
protected void engineReset() {
|
||||||
this.length = 0L;
|
this.length = 0L;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.dbotthepony.kommons.util;
|
package ru.dbotthepony.kommons.util;
|
||||||
|
|
||||||
|
import java.security.DigestException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -123,8 +124,7 @@ public final class XXHash64 extends MessageDigest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public long digestAsLong() {
|
||||||
protected byte[] engineDigest() {
|
|
||||||
long h64;
|
long h64;
|
||||||
|
|
||||||
if (length >= 32L) {
|
if (length >= 32L) {
|
||||||
@ -168,6 +168,18 @@ public final class XXHash64 extends MessageDigest {
|
|||||||
|
|
||||||
engineReset();
|
engineReset();
|
||||||
|
|
||||||
|
return h64;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int engineGetDigestLength() {
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected byte[] engineDigest() {
|
||||||
|
long h64 = digestAsLong();
|
||||||
|
|
||||||
byte[] result = new byte[8];
|
byte[] result = new byte[8];
|
||||||
|
|
||||||
result[7] = (byte) h64;
|
result[7] = (byte) h64;
|
||||||
@ -182,6 +194,29 @@ public final class XXHash64 extends MessageDigest {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int engineDigest(byte[] buf, int offset, int len) throws DigestException {
|
||||||
|
if (len < 8)
|
||||||
|
throw new DigestException("partial digests not returned");
|
||||||
|
|
||||||
|
if (buf.length - offset < 8)
|
||||||
|
throw new DigestException("insufficient space in the output "
|
||||||
|
+ "buffer to store the digest");
|
||||||
|
|
||||||
|
long h64 = digestAsLong();
|
||||||
|
|
||||||
|
buf[offset + 7] = (byte) h64;
|
||||||
|
buf[offset + 6] = (byte) (h64 >>> 8);
|
||||||
|
buf[offset + 5] = (byte) (h64 >>> 16);
|
||||||
|
buf[offset + 4] = (byte) (h64 >>> 24);
|
||||||
|
buf[offset + 3] = (byte) (h64 >>> 32);
|
||||||
|
buf[offset + 2] = (byte) (h64 >>> 40);
|
||||||
|
buf[offset + 1] = (byte) (h64 >>> 48);
|
||||||
|
buf[offset] = (byte) (h64 >>> 56);
|
||||||
|
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void engineReset() {
|
protected void engineReset() {
|
||||||
this.length = 0L;
|
this.length = 0L;
|
||||||
|
Loading…
Reference in New Issue
Block a user