what-the-bank/sources/com/google/common/hash/Murmur3_32HashFunction.java

341 lines
13 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.hash;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Ints;
import com.google.common.primitives.UnsignedBytes;
import com.kofax.mobile.sdk._internal.impl.camera.h;
import io.flutter.embedding.android.KeyboardMap;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class Murmur3_32HashFunction extends AbstractHashFunction implements Serializable {
private static final int C1 = -862048943;
private static final int C2 = 461845907;
private static final int CHUNK_SIZE = 4;
private static final long serialVersionUID = 0;
private final int seed;
static final HashFunction MURMUR3_32 = new Murmur3_32HashFunction(0);
static final HashFunction GOOD_FAST_HASH_32 = new Murmur3_32HashFunction(Hashing.GOOD_FAST_HASH_SEED);
/* JADX INFO: Access modifiers changed from: private */
public static long charToThreeUtf8Bytes(char c) {
return ((((c >>> 6) & 63) | 128) << 8) | (((c >>> '\f') | h.Az) & 255) | (((c & '?') | 128) << 16);
}
/* JADX INFO: Access modifiers changed from: private */
public static long charToTwoUtf8Bytes(char c) {
return (((c >>> 6) | 960) & 255) | (((c & '?') | 128) << 8);
}
/* JADX INFO: Access modifiers changed from: private */
public static long codePointToFourUtf8Bytes(int i) {
return (((i >>> 18) | 240) & 255) | ((((i >>> 12) & 63) | 128) << 8) | ((((i >>> 6) & 63) | 128) << 16) | (((i & 63) | 128) << 24);
}
@Override // com.google.common.hash.HashFunction
public final int bits() {
return 32;
}
/* JADX INFO: Access modifiers changed from: package-private */
public Murmur3_32HashFunction(int i) {
this.seed = i;
}
@Override // com.google.common.hash.HashFunction
public final Hasher newHasher() {
return new Murmur3_32Hasher(this.seed);
}
public final String toString() {
int i = this.seed;
StringBuilder sb = new StringBuilder(31);
sb.append("Hashing.murmur3_32(");
sb.append(i);
sb.append(")");
return sb.toString();
}
public final boolean equals(Object obj) {
return (obj instanceof Murmur3_32HashFunction) && this.seed == ((Murmur3_32HashFunction) obj).seed;
}
public final int hashCode() {
return getClass().hashCode() ^ this.seed;
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public final HashCode hashInt(int i) {
return fmix(mixH1(this.seed, mixK1(i)), 4);
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public final HashCode hashLong(long j) {
return fmix(mixH1(mixH1(this.seed, mixK1((int) j)), mixK1((int) (j >>> 32))), 8);
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public final HashCode hashUnencodedChars(CharSequence charSequence) {
int i = this.seed;
for (int i2 = 1; i2 < charSequence.length(); i2 += 2) {
i = mixH1(i, mixK1(charSequence.charAt(i2 - 1) | (charSequence.charAt(i2) << 16)));
}
if ((charSequence.length() & 1) == 1) {
i ^= mixK1(charSequence.charAt(charSequence.length() - 1));
}
return fmix(i, charSequence.length() << 1);
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public final HashCode hashString(CharSequence charSequence, Charset charset) {
if (Charsets.UTF_8.equals(charset)) {
int length = charSequence.length();
int i = this.seed;
int i2 = 0;
int i3 = 0;
int i4 = 0;
while (true) {
int i5 = i3 + 4;
if (i5 > length) {
break;
}
char charAt = charSequence.charAt(i3);
char charAt2 = charSequence.charAt(i3 + 1);
char charAt3 = charSequence.charAt(i3 + 2);
char charAt4 = charSequence.charAt(i3 + 3);
if (charAt >= 128 || charAt2 >= 128 || charAt3 >= 128 || charAt4 >= 128) {
break;
}
i = mixH1(i, mixK1((charAt2 << '\b') | charAt | (charAt3 << 16) | (charAt4 << 24)));
i4 += 4;
i3 = i5;
}
long j = 0;
while (i3 < length) {
char charAt5 = charSequence.charAt(i3);
if (charAt5 < 128) {
j |= charAt5 << i2;
i2 += 8;
i4++;
} else if (charAt5 < 2048) {
j |= charToTwoUtf8Bytes(charAt5) << i2;
i2 += 16;
i4 += 2;
} else if (charAt5 < 55296 || charAt5 > 57343) {
j |= charToThreeUtf8Bytes(charAt5) << i2;
i2 += 24;
i4 += 3;
} else {
int codePointAt = Character.codePointAt(charSequence, i3);
if (codePointAt == charAt5) {
return hashBytes(charSequence.toString().getBytes(charset));
}
i3++;
j |= codePointToFourUtf8Bytes(codePointAt) << i2;
i4 += 4;
}
if (i2 >= 32) {
i = mixH1(i, mixK1((int) j));
j >>>= 32;
i2 -= 32;
}
i3++;
}
return fmix(mixK1((int) j) ^ i, i4);
}
return hashBytes(charSequence.toString().getBytes(charset));
}
@Override // com.google.common.hash.AbstractHashFunction, com.google.common.hash.HashFunction
public final HashCode hashBytes(byte[] bArr, int i, int i2) {
Preconditions.checkPositionIndexes(i, i + i2, bArr.length);
int i3 = this.seed;
int i4 = 0;
int i5 = 0;
while (true) {
int i6 = i5 + 4;
if (i6 > i2) {
break;
}
i3 = mixH1(i3, mixK1(getIntLittleEndian(bArr, i5 + i)));
i5 = i6;
}
int i7 = i5;
int i8 = 0;
while (i7 < i2) {
i4 ^= UnsignedBytes.toInt(bArr[i + i7]) << i8;
i7++;
i8 += 8;
}
return fmix(mixK1(i4) ^ i3, i2);
}
/* JADX INFO: Access modifiers changed from: private */
public static int getIntLittleEndian(byte[] bArr, int i) {
return Ints.fromBytes(bArr[i + 3], bArr[i + 2], bArr[i + 1], bArr[i]);
}
/* JADX INFO: Access modifiers changed from: private */
public static int mixK1(int i) {
return Integer.rotateLeft(i * C1, 15) * C2;
}
/* JADX INFO: Access modifiers changed from: private */
public static int mixH1(int i, int i2) {
return (Integer.rotateLeft(i ^ i2, 13) * 5) - 430675100;
}
/* JADX INFO: Access modifiers changed from: private */
public static HashCode fmix(int i, int i2) {
int i3 = i ^ i2;
int i4 = (i3 ^ (i3 >>> 16)) * (-2048144789);
int i5 = (i4 ^ (i4 >>> 13)) * (-1028477387);
return HashCode.fromInt(i5 ^ (i5 >>> 16));
}
/* loaded from: classes2.dex */
static final class Murmur3_32Hasher extends AbstractHasher {
private long buffer;
private int h1;
private int shift;
private int length = 0;
private boolean isDone = false;
Murmur3_32Hasher(int i) {
this.h1 = i;
}
private void update(int i, long j) {
long j2 = this.buffer;
int i2 = this.shift;
long j3 = ((j & KeyboardMap.kValueMask) << i2) | j2;
this.buffer = j3;
int i3 = i2 + (i << 3);
this.shift = i3;
this.length += i;
if (i3 >= 32) {
this.h1 = Murmur3_32HashFunction.mixH1(this.h1, Murmur3_32HashFunction.mixK1((int) j3));
this.buffer >>>= 32;
this.shift -= 32;
}
}
@Override // com.google.common.hash.PrimitiveSink
public final Hasher putByte(byte b) {
update(1, b & UnsignedBytes.MAX_VALUE);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putBytes(byte[] bArr, int i, int i2) {
Preconditions.checkPositionIndexes(i, i + i2, bArr.length);
int i3 = 0;
while (true) {
int i4 = i3 + 4;
if (i4 > i2) {
break;
}
update(4, Murmur3_32HashFunction.getIntLittleEndian(bArr, i3 + i));
i3 = i4;
}
while (i3 < i2) {
putByte(bArr[i + i3]);
i3++;
}
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putBytes(ByteBuffer byteBuffer) {
ByteOrder order = byteBuffer.order();
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
while (byteBuffer.remaining() >= 4) {
putInt(byteBuffer.getInt());
}
while (byteBuffer.hasRemaining()) {
putByte(byteBuffer.get());
}
byteBuffer.order(order);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putInt(int i) {
update(4, i);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putLong(long j) {
update(4, (int) j);
update(4, j >>> 32);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putChar(char c) {
update(2, c);
return this;
}
@Override // com.google.common.hash.AbstractHasher, com.google.common.hash.PrimitiveSink
public final Hasher putString(CharSequence charSequence, Charset charset) {
if (Charsets.UTF_8.equals(charset)) {
int length = charSequence.length();
int i = 0;
while (true) {
int i2 = i + 4;
if (i2 > length) {
break;
}
char charAt = charSequence.charAt(i);
char charAt2 = charSequence.charAt(i + 1);
char charAt3 = charSequence.charAt(i + 2);
char charAt4 = charSequence.charAt(i + 3);
if (charAt >= 128 || charAt2 >= 128 || charAt3 >= 128 || charAt4 >= 128) {
break;
}
update(4, (charAt2 << '\b') | charAt | (charAt3 << 16) | (charAt4 << 24));
i = i2;
}
while (i < length) {
char charAt5 = charSequence.charAt(i);
if (charAt5 < 128) {
update(1, charAt5);
} else if (charAt5 < 2048) {
update(2, Murmur3_32HashFunction.charToTwoUtf8Bytes(charAt5));
} else if (charAt5 < 55296 || charAt5 > 57343) {
update(3, Murmur3_32HashFunction.charToThreeUtf8Bytes(charAt5));
} else {
int codePointAt = Character.codePointAt(charSequence, i);
if (codePointAt != charAt5) {
i++;
update(4, Murmur3_32HashFunction.codePointToFourUtf8Bytes(codePointAt));
} else {
putBytes(charSequence.subSequence(i, length).toString().getBytes(charset));
return this;
}
}
i++;
}
return this;
}
return super.putString(charSequence, charset);
}
@Override // com.google.common.hash.Hasher
public final HashCode hash() {
Preconditions.checkState(!this.isDone);
this.isDone = true;
int mixK1 = this.h1 ^ Murmur3_32HashFunction.mixK1((int) this.buffer);
this.h1 = mixK1;
return Murmur3_32HashFunction.fmix(mixK1, this.length);
}
}
}