Files
rr3-apk/decompiled-community/sources/com/google/common/collect/CompactHashMap.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

771 lines
26 KiB
Java

package com.google.common.collect;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Ints;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
/* loaded from: classes3.dex */
public class CompactHashMap extends AbstractMap implements Serializable {
public static final Object NOT_FOUND = new Object();
public transient int[] entries;
public transient Set entrySetView;
public transient Set keySetView;
public transient Object[] keys;
public transient int metadata;
public transient int size;
public transient Object table;
public transient Object[] values;
public transient Collection valuesView;
public void accessEntry(int i) {
}
public int adjustAfterRemove(int i, int i2) {
return i - 1;
}
public int getSuccessor(int i) {
int i2 = i + 1;
if (i2 < this.size) {
return i2;
}
return -1;
}
public final int hashTableMask() {
return (1 << (this.metadata & 31)) - 1;
}
public void incrementModCount() {
this.metadata += 32;
}
public boolean needsAllocArrays() {
return this.table == null;
}
public static /* synthetic */ int access$1210(CompactHashMap compactHashMap) {
int i = compactHashMap.size;
compactHashMap.size = i - 1;
return i;
}
public static CompactHashMap create() {
return new CompactHashMap();
}
public CompactHashMap() {
init(3);
}
public void init(int i) {
Preconditions.checkArgument(i >= 0, "Expected size must be >= 0");
this.metadata = Ints.constrainToRange(i, 1, 1073741823);
}
public int allocArrays() {
Preconditions.checkState(needsAllocArrays(), "Arrays already allocated");
int i = this.metadata;
int tableSize = CompactHashing.tableSize(i);
this.table = CompactHashing.createTable(tableSize);
setHashTableMask(tableSize - 1);
this.entries = new int[i];
this.keys = new Object[i];
this.values = new Object[i];
return i;
}
public Map delegateOrNull() {
Object obj = this.table;
if (obj instanceof Map) {
return (Map) obj;
}
return null;
}
public Map createHashFloodingResistantDelegate(int i) {
return new LinkedHashMap(i, 1.0f);
}
public Map convertToHashFloodingResistantImplementation() {
Map createHashFloodingResistantDelegate = createHashFloodingResistantDelegate(hashTableMask() + 1);
int firstEntryIndex = firstEntryIndex();
while (firstEntryIndex >= 0) {
createHashFloodingResistantDelegate.put(key(firstEntryIndex), value(firstEntryIndex));
firstEntryIndex = getSuccessor(firstEntryIndex);
}
this.table = createHashFloodingResistantDelegate;
this.entries = null;
this.keys = null;
this.values = null;
incrementModCount();
return createHashFloodingResistantDelegate;
}
public final void setHashTableMask(int i) {
this.metadata = CompactHashing.maskCombine(this.metadata, 32 - Integer.numberOfLeadingZeros(i), 31);
}
@Override // java.util.AbstractMap, java.util.Map
public Object put(Object obj, Object obj2) {
int resizeTable;
int i;
if (needsAllocArrays()) {
allocArrays();
}
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.put(obj, obj2);
}
int[] requireEntries = requireEntries();
Object[] requireKeys = requireKeys();
Object[] requireValues = requireValues();
int i2 = this.size;
int i3 = i2 + 1;
int smearedHash = Hashing.smearedHash(obj);
int hashTableMask = hashTableMask();
int i4 = smearedHash & hashTableMask;
int tableGet = CompactHashing.tableGet(requireTable(), i4);
if (tableGet != 0) {
int hashPrefix = CompactHashing.getHashPrefix(smearedHash, hashTableMask);
int i5 = 0;
while (true) {
int i6 = tableGet - 1;
int i7 = requireEntries[i6];
if (CompactHashing.getHashPrefix(i7, hashTableMask) == hashPrefix && Objects.equal(obj, requireKeys[i6])) {
Object obj3 = requireValues[i6];
requireValues[i6] = obj2;
accessEntry(i6);
return obj3;
}
int next = CompactHashing.getNext(i7, hashTableMask);
i5++;
if (next != 0) {
tableGet = next;
} else {
if (i5 >= 9) {
return convertToHashFloodingResistantImplementation().put(obj, obj2);
}
if (i3 > hashTableMask) {
resizeTable = resizeTable(hashTableMask, CompactHashing.newCapacity(hashTableMask), smearedHash, i2);
} else {
requireEntries[i6] = CompactHashing.maskCombine(i7, i3, hashTableMask);
}
}
}
} else if (i3 > hashTableMask) {
resizeTable = resizeTable(hashTableMask, CompactHashing.newCapacity(hashTableMask), smearedHash, i2);
i = resizeTable;
} else {
CompactHashing.tableSet(requireTable(), i4, i3);
i = hashTableMask;
}
resizeMeMaybe(i3);
insertEntry(i2, obj, obj2, smearedHash, i);
this.size = i3;
incrementModCount();
return null;
}
public void insertEntry(int i, Object obj, Object obj2, int i2, int i3) {
setEntry(i, CompactHashing.maskCombine(i2, 0, i3));
setKey(i, obj);
setValue(i, obj2);
}
public final void resizeMeMaybe(int i) {
int min;
int length = requireEntries().length;
if (i <= length || (min = Math.min(1073741823, (Math.max(1, length >>> 1) + length) | 1)) == length) {
return;
}
resizeEntries(min);
}
public void resizeEntries(int i) {
this.entries = Arrays.copyOf(requireEntries(), i);
this.keys = Arrays.copyOf(requireKeys(), i);
this.values = Arrays.copyOf(requireValues(), i);
}
public final int resizeTable(int i, int i2, int i3, int i4) {
Object createTable = CompactHashing.createTable(i2);
int i5 = i2 - 1;
if (i4 != 0) {
CompactHashing.tableSet(createTable, i3 & i5, i4 + 1);
}
Object requireTable = requireTable();
int[] requireEntries = requireEntries();
for (int i6 = 0; i6 <= i; i6++) {
int tableGet = CompactHashing.tableGet(requireTable, i6);
while (tableGet != 0) {
int i7 = tableGet - 1;
int i8 = requireEntries[i7];
int hashPrefix = CompactHashing.getHashPrefix(i8, i) | i6;
int i9 = hashPrefix & i5;
int tableGet2 = CompactHashing.tableGet(createTable, i9);
CompactHashing.tableSet(createTable, i9, tableGet);
requireEntries[i7] = CompactHashing.maskCombine(hashPrefix, tableGet2, i5);
tableGet = CompactHashing.getNext(i8, i);
}
}
this.table = createTable;
setHashTableMask(i5);
return i5;
}
public final int indexOf(Object obj) {
if (needsAllocArrays()) {
return -1;
}
int smearedHash = Hashing.smearedHash(obj);
int hashTableMask = hashTableMask();
int tableGet = CompactHashing.tableGet(requireTable(), smearedHash & hashTableMask);
if (tableGet == 0) {
return -1;
}
int hashPrefix = CompactHashing.getHashPrefix(smearedHash, hashTableMask);
do {
int i = tableGet - 1;
int entry = entry(i);
if (CompactHashing.getHashPrefix(entry, hashTableMask) == hashPrefix && Objects.equal(obj, key(i))) {
return i;
}
tableGet = CompactHashing.getNext(entry, hashTableMask);
} while (tableGet != 0);
return -1;
}
@Override // java.util.AbstractMap, java.util.Map
public boolean containsKey(Object obj) {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.containsKey(obj);
}
return indexOf(obj) != -1;
}
@Override // java.util.AbstractMap, java.util.Map
public Object get(Object obj) {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.get(obj);
}
int indexOf = indexOf(obj);
if (indexOf == -1) {
return null;
}
accessEntry(indexOf);
return value(indexOf);
}
@Override // java.util.AbstractMap, java.util.Map
public Object remove(Object obj) {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.remove(obj);
}
Object removeHelper = removeHelper(obj);
if (removeHelper == NOT_FOUND) {
return null;
}
return removeHelper;
}
public final Object removeHelper(Object obj) {
if (needsAllocArrays()) {
return NOT_FOUND;
}
int hashTableMask = hashTableMask();
int remove = CompactHashing.remove(obj, null, hashTableMask, requireTable(), requireEntries(), requireKeys(), null);
if (remove == -1) {
return NOT_FOUND;
}
Object value = value(remove);
moveLastEntry(remove, hashTableMask);
this.size--;
incrementModCount();
return value;
}
public void moveLastEntry(int i, int i2) {
Object requireTable = requireTable();
int[] requireEntries = requireEntries();
Object[] requireKeys = requireKeys();
Object[] requireValues = requireValues();
int size = size();
int i3 = size - 1;
if (i < i3) {
Object obj = requireKeys[i3];
requireKeys[i] = obj;
requireValues[i] = requireValues[i3];
requireKeys[i3] = null;
requireValues[i3] = null;
requireEntries[i] = requireEntries[i3];
requireEntries[i3] = 0;
int smearedHash = Hashing.smearedHash(obj) & i2;
int tableGet = CompactHashing.tableGet(requireTable, smearedHash);
if (tableGet == size) {
CompactHashing.tableSet(requireTable, smearedHash, i + 1);
return;
}
while (true) {
int i4 = tableGet - 1;
int i5 = requireEntries[i4];
int next = CompactHashing.getNext(i5, i2);
if (next == size) {
requireEntries[i4] = CompactHashing.maskCombine(i5, i + 1, i2);
return;
}
tableGet = next;
}
} else {
requireKeys[i] = null;
requireValues[i] = null;
requireEntries[i] = 0;
}
}
public int firstEntryIndex() {
return isEmpty() ? -1 : 0;
}
public abstract class Itr implements Iterator {
public int currentIndex;
public int expectedMetadata;
public int indexToRemove;
public abstract Object getOutput(int i);
@Override // java.util.Iterator
public boolean hasNext() {
return this.currentIndex >= 0;
}
public void incrementExpectedModCount() {
this.expectedMetadata += 32;
}
public Itr() {
this.expectedMetadata = CompactHashMap.this.metadata;
this.currentIndex = CompactHashMap.this.firstEntryIndex();
this.indexToRemove = -1;
}
@Override // java.util.Iterator
public Object next() {
checkForConcurrentModification();
if (!hasNext()) {
throw new NoSuchElementException();
}
int i = this.currentIndex;
this.indexToRemove = i;
Object output = getOutput(i);
this.currentIndex = CompactHashMap.this.getSuccessor(this.currentIndex);
return output;
}
@Override // java.util.Iterator
public void remove() {
checkForConcurrentModification();
CollectPreconditions.checkRemove(this.indexToRemove >= 0);
incrementExpectedModCount();
CompactHashMap compactHashMap = CompactHashMap.this;
compactHashMap.remove(compactHashMap.key(this.indexToRemove));
this.currentIndex = CompactHashMap.this.adjustAfterRemove(this.currentIndex, this.indexToRemove);
this.indexToRemove = -1;
}
public final void checkForConcurrentModification() {
if (CompactHashMap.this.metadata != this.expectedMetadata) {
throw new ConcurrentModificationException();
}
}
}
@Override // java.util.AbstractMap, java.util.Map
public Set keySet() {
Set set = this.keySetView;
if (set != null) {
return set;
}
Set createKeySet = createKeySet();
this.keySetView = createKeySet;
return createKeySet;
}
public Set createKeySet() {
return new KeySetView();
}
public class KeySetView extends AbstractSet {
public KeySetView() {
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return CompactHashMap.this.size();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(Object obj) {
return CompactHashMap.this.containsKey(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean remove(Object obj) {
Map delegateOrNull = CompactHashMap.this.delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.keySet().remove(obj);
}
return CompactHashMap.this.removeHelper(obj) != CompactHashMap.NOT_FOUND;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public Iterator iterator() {
return CompactHashMap.this.keySetIterator();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public void clear() {
CompactHashMap.this.clear();
}
}
public Iterator keySetIterator() {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.keySet().iterator();
}
return new Itr() { // from class: com.google.common.collect.CompactHashMap.1
@Override // com.google.common.collect.CompactHashMap.Itr
public Object getOutput(int i) {
return CompactHashMap.this.key(i);
}
};
}
@Override // java.util.AbstractMap, java.util.Map
public Set entrySet() {
Set set = this.entrySetView;
if (set != null) {
return set;
}
Set createEntrySet = createEntrySet();
this.entrySetView = createEntrySet;
return createEntrySet;
}
public Set createEntrySet() {
return new EntrySetView();
}
public class EntrySetView extends AbstractSet {
public EntrySetView() {
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return CompactHashMap.this.size();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public void clear() {
CompactHashMap.this.clear();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public Iterator iterator() {
return CompactHashMap.this.entrySetIterator();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(Object obj) {
Map delegateOrNull = CompactHashMap.this.delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.entrySet().contains(obj);
}
if (!(obj instanceof Map.Entry)) {
return false;
}
Map.Entry entry = (Map.Entry) obj;
int indexOf = CompactHashMap.this.indexOf(entry.getKey());
return indexOf != -1 && Objects.equal(CompactHashMap.this.value(indexOf), entry.getValue());
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean remove(Object obj) {
Map delegateOrNull = CompactHashMap.this.delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.entrySet().remove(obj);
}
if (!(obj instanceof Map.Entry)) {
return false;
}
Map.Entry entry = (Map.Entry) obj;
if (CompactHashMap.this.needsAllocArrays()) {
return false;
}
int hashTableMask = CompactHashMap.this.hashTableMask();
int remove = CompactHashing.remove(entry.getKey(), entry.getValue(), hashTableMask, CompactHashMap.this.requireTable(), CompactHashMap.this.requireEntries(), CompactHashMap.this.requireKeys(), CompactHashMap.this.requireValues());
if (remove == -1) {
return false;
}
CompactHashMap.this.moveLastEntry(remove, hashTableMask);
CompactHashMap.access$1210(CompactHashMap.this);
CompactHashMap.this.incrementModCount();
return true;
}
}
public Iterator entrySetIterator() {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.entrySet().iterator();
}
return new Itr() { // from class: com.google.common.collect.CompactHashMap.2
@Override // com.google.common.collect.CompactHashMap.Itr
public Map.Entry getOutput(int i) {
return CompactHashMap.this.new MapEntry(i);
}
};
}
public final class MapEntry extends AbstractMapEntry {
public final Object key;
public int lastKnownIndex;
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
public Object getKey() {
return this.key;
}
public MapEntry(int i) {
this.key = CompactHashMap.this.key(i);
this.lastKnownIndex = i;
}
public final void updateLastKnownIndex() {
int i = this.lastKnownIndex;
if (i == -1 || i >= CompactHashMap.this.size() || !Objects.equal(this.key, CompactHashMap.this.key(this.lastKnownIndex))) {
this.lastKnownIndex = CompactHashMap.this.indexOf(this.key);
}
}
@Override // com.google.common.collect.AbstractMapEntry, java.util.Map.Entry
public Object getValue() {
Map delegateOrNull = CompactHashMap.this.delegateOrNull();
if (delegateOrNull != null) {
return NullnessCasts.uncheckedCastNullableTToT(delegateOrNull.get(this.key));
}
updateLastKnownIndex();
int i = this.lastKnownIndex;
if (i != -1) {
return CompactHashMap.this.value(i);
}
return NullnessCasts.unsafeNull();
}
@Override // java.util.Map.Entry
public Object setValue(Object obj) {
Map delegateOrNull = CompactHashMap.this.delegateOrNull();
if (delegateOrNull != null) {
return NullnessCasts.uncheckedCastNullableTToT(delegateOrNull.put(this.key, obj));
}
updateLastKnownIndex();
int i = this.lastKnownIndex;
if (i != -1) {
Object value = CompactHashMap.this.value(i);
CompactHashMap.this.setValue(this.lastKnownIndex, obj);
return value;
}
CompactHashMap.this.put(this.key, obj);
return NullnessCasts.unsafeNull();
}
}
@Override // java.util.AbstractMap, java.util.Map
public int size() {
Map delegateOrNull = delegateOrNull();
return delegateOrNull != null ? delegateOrNull.size() : this.size;
}
@Override // java.util.AbstractMap, java.util.Map
public boolean isEmpty() {
return size() == 0;
}
@Override // java.util.AbstractMap, java.util.Map
public boolean containsValue(Object obj) {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.containsValue(obj);
}
for (int i = 0; i < this.size; i++) {
if (Objects.equal(obj, value(i))) {
return true;
}
}
return false;
}
@Override // java.util.AbstractMap, java.util.Map
public Collection values() {
Collection collection = this.valuesView;
if (collection != null) {
return collection;
}
Collection createValues = createValues();
this.valuesView = createValues;
return createValues;
}
public Collection createValues() {
return new ValuesView();
}
public class ValuesView extends AbstractCollection {
public ValuesView() {
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
return CompactHashMap.this.size();
}
@Override // java.util.AbstractCollection, java.util.Collection
public void clear() {
CompactHashMap.this.clear();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator iterator() {
return CompactHashMap.this.valuesIterator();
}
}
public Iterator valuesIterator() {
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
return delegateOrNull.values().iterator();
}
return new Itr() { // from class: com.google.common.collect.CompactHashMap.3
@Override // com.google.common.collect.CompactHashMap.Itr
public Object getOutput(int i) {
return CompactHashMap.this.value(i);
}
};
}
@Override // java.util.AbstractMap, java.util.Map
public void clear() {
if (needsAllocArrays()) {
return;
}
incrementModCount();
Map delegateOrNull = delegateOrNull();
if (delegateOrNull != null) {
this.metadata = Ints.constrainToRange(size(), 3, 1073741823);
delegateOrNull.clear();
this.table = null;
this.size = 0;
return;
}
Arrays.fill(requireKeys(), 0, this.size, (Object) null);
Arrays.fill(requireValues(), 0, this.size, (Object) null);
CompactHashing.tableClear(requireTable());
Arrays.fill(requireEntries(), 0, this.size, 0);
this.size = 0;
}
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
objectOutputStream.defaultWriteObject();
objectOutputStream.writeInt(size());
Iterator entrySetIterator = entrySetIterator();
while (entrySetIterator.hasNext()) {
Map.Entry entry = (Map.Entry) entrySetIterator.next();
objectOutputStream.writeObject(entry.getKey());
objectOutputStream.writeObject(entry.getValue());
}
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
objectInputStream.defaultReadObject();
int readInt = objectInputStream.readInt();
if (readInt < 0) {
StringBuilder sb = new StringBuilder(25);
sb.append("Invalid size: ");
sb.append(readInt);
throw new InvalidObjectException(sb.toString());
}
init(readInt);
for (int i = 0; i < readInt; i++) {
put(objectInputStream.readObject(), objectInputStream.readObject());
}
}
public final Object requireTable() {
Object obj = this.table;
java.util.Objects.requireNonNull(obj);
return obj;
}
public final int[] requireEntries() {
int[] iArr = this.entries;
java.util.Objects.requireNonNull(iArr);
return iArr;
}
public final Object[] requireKeys() {
Object[] objArr = this.keys;
java.util.Objects.requireNonNull(objArr);
return objArr;
}
public final Object[] requireValues() {
Object[] objArr = this.values;
java.util.Objects.requireNonNull(objArr);
return objArr;
}
public final Object key(int i) {
return requireKeys()[i];
}
public final Object value(int i) {
return requireValues()[i];
}
public final int entry(int i) {
return requireEntries()[i];
}
public final void setKey(int i, Object obj) {
requireKeys()[i] = obj;
}
public final void setValue(int i, Object obj) {
requireValues()[i] = obj;
}
public final void setEntry(int i, int i2) {
requireEntries()[i] = i2;
}
}