alexandroid/decompiled/jadx/sources/com/google/common/base/SmallCharMatcher.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

108 lines
3.1 KiB
Java

package com.google.common.base;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher;
import java.util.BitSet;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@GwtIncompatible
/* loaded from: classes8.dex */
final class SmallCharMatcher extends CharMatcher.NamedFastMatcher {
private static final int C1 = -862048943;
private static final int C2 = 461845907;
private static final double DESIRED_LOAD_FACTOR = 0.5d;
static final int MAX_SIZE = 1023;
private final boolean containsZero;
private final long filter;
private final char[] table;
private SmallCharMatcher(char[] cArr, long j, boolean z, String str) {
super(str);
this.table = cArr;
this.filter = j;
this.containsZero = z;
}
private boolean checkFilter(int i) {
return ((this.filter >> i) & 1) == 1;
}
@VisibleForTesting
public static int chooseTableSize(int i) {
if (i == 1) {
return 2;
}
int highestOneBit = Integer.highestOneBit(i - 1) << 1;
while (highestOneBit * 0.5d < i) {
highestOneBit <<= 1;
}
return highestOneBit;
}
public static CharMatcher from(BitSet bitSet, String str) {
int i;
int cardinality = bitSet.cardinality();
boolean z = bitSet.get(0);
int chooseTableSize = chooseTableSize(cardinality);
char[] cArr = new char[chooseTableSize];
int i2 = chooseTableSize - 1;
int nextSetBit = bitSet.nextSetBit(0);
long j = 0;
while (nextSetBit != -1) {
long j2 = (1 << nextSetBit) | j;
int smear = smear(nextSetBit);
while (true) {
i = smear & i2;
if (cArr[i] == 0) {
break;
}
smear = i + 1;
}
cArr[i] = (char) nextSetBit;
nextSetBit = bitSet.nextSetBit(nextSetBit + 1);
j = j2;
}
return new SmallCharMatcher(cArr, j, z, str);
}
public static int smear(int i) {
return Integer.rotateLeft(i * (-862048943), 15) * C2;
}
@Override // com.google.common.base.CharMatcher
public boolean matches(char c) {
if (c == 0) {
return this.containsZero;
}
if (!checkFilter(c)) {
return false;
}
int length = this.table.length - 1;
int smear = smear(c) & length;
int i = smear;
do {
char c2 = this.table[i];
if (c2 == 0) {
return false;
}
if (c2 == c) {
return true;
}
i = (i + 1) & length;
} while (i != smear);
return false;
}
@Override // com.google.common.base.CharMatcher
public void setBits(BitSet bitSet) {
if (this.containsZero) {
bitSet.set(0);
}
for (char c : this.table) {
if (c != 0) {
bitSet.set(c);
}
}
}
}