Rabbit-R1/android (non root)/java/sources/androidx/collection/SimpleArrayMap.java

470 lines
20 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.collection;
import androidx.collection.internal.ContainerHelpersKt;
import androidx.exifinterface.media.ExifInterface;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Map;
import kotlin.Metadata;
import kotlin.collections.ArraysKt;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
/* compiled from: SimpleArrayMap.kt */
@Metadata(d1 = {"\u0000>\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u0011\n\u0002\b\u0002\n\u0002\u0010\u0015\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b)\n\u0002\u0010\u000e\n\u0002\b\u0002\b\u0016\u0018\u0000*\u0004\b\u0000\u0010\u0001*\u0004\b\u0001\u0010\u00022\u00020\u0003B!\b\u0016\u0012\u0018\u0010\u0004\u001a\u0014\u0012\u0006\b\u0001\u0012\u00028\u0000\u0012\u0006\b\u0001\u0012\u00028\u0001\u0018\u00010\u0000¢\u0006\u0002\u0010\u0005B\u0011\b\u0007\u0012\b\b\u0002\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\b\u0010\u000f\u001a\u00020\u0010H\u0016J\u0015\u0010\u0011\u001a\u00020\u00122\u0006\u0010\u0013\u001a\u00028\u0000H\u0016¢\u0006\u0002\u0010\u0014J\u0015\u0010\u0015\u001a\u00020\u00122\u0006\u0010\u0016\u001a\u00028\u0001H\u0016¢\u0006\u0002\u0010\u0014J\u0010\u0010\u0017\u001a\u00020\u00102\u0006\u0010\u0018\u001a\u00020\u0007H\u0016J\u0013\u0010\u0019\u001a\u00020\u00122\b\u0010\u001a\u001a\u0004\u0018\u00010\u0003H\u0096\u0002J\u0018\u0010\u001b\u001a\u0004\u0018\u00018\u00012\u0006\u0010\u0013\u001a\u00028\u0000H\u0096\u0002¢\u0006\u0002\u0010\u001cJ\u001f\u0010\u001d\u001a\u00028\u00012\b\u0010\u0013\u001a\u0004\u0018\u00010\u00032\u0006\u0010\u001e\u001a\u00028\u0001H\u0016¢\u0006\u0002\u0010\u001fJ,\u0010 \u001a\u0002H!\"\n\b\u0002\u0010!*\u0004\u0018\u00018\u00012\b\u0010\u0013\u001a\u0004\u0018\u00010\u00032\u0006\u0010\u001e\u001a\u0002H!H\u0082\\u0006\u0002\u0010\u001fJ\b\u0010\"\u001a\u00020\u0007H\u0016J\u001d\u0010#\u001a\u00020\u00072\u0006\u0010\u0013\u001a\u00028\u00002\u0006\u0010$\u001a\u00020\u0007H\u0002¢\u0006\u0002\u0010%J\u0015\u0010&\u001a\u00020\u00072\u0006\u0010\u0013\u001a\u00028\u0000H\u0016¢\u0006\u0002\u0010'J\b\u0010(\u001a\u00020\u0007H\u0002J\u0017\u0010)\u001a\u00020\u00072\u0006\u0010\u0016\u001a\u00028\u0001H\u0001¢\u0006\u0004\b*\u0010'J\b\u0010+\u001a\u00020\u0012H\u0016J\u0015\u0010,\u001a\u00028\u00002\u0006\u0010-\u001a\u00020\u0007H\u0016¢\u0006\u0002\u0010.J\u001f\u0010/\u001a\u0004\u0018\u00018\u00012\u0006\u0010\u0013\u001a\u00028\u00002\u0006\u0010\u0016\u001a\u00028\u0001H\u0016¢\u0006\u0002\u0010\u001fJ \u00100\u001a\u00020\u00102\u0016\u0010\u0004\u001a\u0012\u0012\u0006\b\u0001\u0012\u00028\u0000\u0012\u0006\b\u0001\u0012\u00028\u00010\u0000H\u0016J\u001f\u00101\u001a\u0004\u0018\u00018\u00012\u0006\u0010\u0013\u001a\u00028\u00002\u0006\u0010\u0016\u001a\u00028\u0001H\u0016¢\u0006\u0002\u0010\u001fJ\u0017\u00102\u001a\u0004\u0018\u00018\u00012\u0006\u0010\u0013\u001a\u00028\u0000H\u0016¢\u0006\u0002\u0010\u001cJ\u001d\u00102\u001a\u00020\u00122\u0006\u0010\u0013\u001a\u00028\u00002\u0006\u0010\u0016\u001a\u00028\u0001H\u0016¢\u0006\u0002\u00103J\u0015\u00104\u001a\u00028\u00012\u0006\u0010-\u001a\u00020\u0007H\u0016¢\u0006\u0002\u0010.J\u001f\u00105\u001a\u0004\u0018\u00018\u00012\u0006\u0010\u0013\u001a\u00028\u00002\u0006\u0010\u0016\u001a\u00028\u0001H\u0016¢\u0006\u0002\u0010\u001fJ%\u00105\u001a\u00020\u00122\u0006\u0010\u0013\u001a\u00028\u00002\u0006\u00106\u001a\u00028\u00012\u0006\u00107\u001a\u00028\u0001H\u0016¢\u0006\u0002\u00108J\u001d\u00109\u001a\u00028\u00012\u0006\u0010-\u001a\u00020\u00072\u0006\u0010\u0016\u001a\u00028\u0001H\u0016¢\u0006\u0002\u0010:J\b\u0010\u000e\u001a\u00020\u0007H\u0016J\b\u0010;\u001a\u00020<H\u0016J\u0015\u0010=\u001a\u00028\u00012\u0006\u0010-\u001a\u00020\u0007H\u0016¢\u0006\u0002\u0010.R\u0018\u0010\t\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00030\nX\u0082\u000e¢\u0006\u0004\n\u0002\u0010\u000bR\u000e\u0010\f\u001a\u00020\rX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u000e\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006>"}, d2 = {"Landroidx/collection/SimpleArrayMap;", "K", ExifInterface.GPS_MEASUREMENT_INTERRUPTED, "", "map", "(Landroidx/collection/SimpleArrayMap;)V", "capacity", "", "(I)V", "array", "", "[Ljava/lang/Object;", "hashes", "", "size", "clear", "", "containsKey", "", "key", "(Ljava/lang/Object;)Z", "containsValue", "value", "ensureCapacity
/* loaded from: classes.dex */
public class SimpleArrayMap<K, V> {
private Object[] array;
private int[] hashes;
private int size;
public SimpleArrayMap() {
this(0, 1, null);
}
public boolean isEmpty() {
return this.size <= 0;
}
/* renamed from: size, reason: from getter */
public int getSize() {
return this.size;
}
public SimpleArrayMap(int i) {
int[] iArr;
Object[] objArr;
if (i == 0) {
iArr = ContainerHelpersKt.EMPTY_INTS;
} else {
iArr = new int[i];
}
this.hashes = iArr;
if (i == 0) {
objArr = ContainerHelpersKt.EMPTY_OBJECTS;
} else {
objArr = new Object[i << 1];
}
this.array = objArr;
}
public /* synthetic */ SimpleArrayMap(int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this((i2 & 1) != 0 ? 0 : i);
}
public SimpleArrayMap(SimpleArrayMap<? extends K, ? extends V> simpleArrayMap) {
this(0, 1, null);
if (simpleArrayMap != null) {
putAll(simpleArrayMap);
}
}
private final int indexOf(K key, int hash) {
int i = this.size;
if (i == 0) {
return -1;
}
int binarySearch = ContainerHelpersKt.binarySearch(this.hashes, i, hash);
if (binarySearch < 0 || Intrinsics.areEqual(key, this.array[binarySearch << 1])) {
return binarySearch;
}
int i2 = binarySearch + 1;
while (i2 < i && this.hashes[i2] == hash) {
if (Intrinsics.areEqual(key, this.array[i2 << 1])) {
return i2;
}
i2++;
}
for (int i3 = binarySearch - 1; i3 >= 0 && this.hashes[i3] == hash; i3--) {
if (Intrinsics.areEqual(key, this.array[i3 << 1])) {
return i3;
}
}
return ~i2;
}
private final int indexOfNull() {
int i = this.size;
if (i == 0) {
return -1;
}
int binarySearch = ContainerHelpersKt.binarySearch(this.hashes, i, 0);
if (binarySearch < 0 || this.array[binarySearch << 1] == null) {
return binarySearch;
}
int i2 = binarySearch + 1;
while (i2 < i && this.hashes[i2] == 0) {
if (this.array[i2 << 1] == null) {
return i2;
}
i2++;
}
for (int i3 = binarySearch - 1; i3 >= 0 && this.hashes[i3] == 0; i3--) {
if (this.array[i3 << 1] == null) {
return i3;
}
}
return ~i2;
}
public void clear() {
if (this.size > 0) {
this.hashes = ContainerHelpersKt.EMPTY_INTS;
this.array = ContainerHelpersKt.EMPTY_OBJECTS;
this.size = 0;
}
if (this.size > 0) {
throw new ConcurrentModificationException();
}
}
public void ensureCapacity(int minimumCapacity) {
int i = this.size;
int[] iArr = this.hashes;
if (iArr.length < minimumCapacity) {
int[] copyOf = Arrays.copyOf(iArr, minimumCapacity);
Intrinsics.checkNotNullExpressionValue(copyOf, "copyOf(this, newSize)");
this.hashes = copyOf;
Object[] copyOf2 = Arrays.copyOf(this.array, minimumCapacity * 2);
Intrinsics.checkNotNullExpressionValue(copyOf2, "copyOf(this, newSize)");
this.array = copyOf2;
}
if (this.size != i) {
throw new ConcurrentModificationException();
}
}
public boolean containsKey(K key) {
return indexOfKey(key) >= 0;
}
public int indexOfKey(K key) {
if (key == null) {
return indexOfNull();
}
return indexOf(key, key.hashCode());
}
public final int __restricted$indexOfValue(V value) {
int i = this.size * 2;
Object[] objArr = this.array;
if (value == null) {
for (int i2 = 1; i2 < i; i2 += 2) {
if (objArr[i2] == null) {
return i2 >> 1;
}
}
return -1;
}
for (int i3 = 1; i3 < i; i3 += 2) {
if (Intrinsics.areEqual(value, objArr[i3])) {
return i3 >> 1;
}
}
return -1;
}
public boolean containsValue(V value) {
return __restricted$indexOfValue(value) >= 0;
}
/* JADX WARN: Multi-variable type inference failed */
private final <T extends V> T getOrDefaultInternal(Object key, T defaultValue) {
int indexOfKey = indexOfKey(key);
return indexOfKey >= 0 ? (T) this.array[(indexOfKey << 1) + 1] : defaultValue;
}
public K keyAt(int index) {
if (index < 0 || index >= this.size) {
throw new IllegalArgumentException(("Expected index to be within 0..size()-1, but was " + index).toString());
}
return (K) this.array[index << 1];
}
public V valueAt(int index) {
if (index < 0 || index >= this.size) {
throw new IllegalArgumentException(("Expected index to be within 0..size()-1, but was " + index).toString());
}
return (V) this.array[(index << 1) + 1];
}
public V setValueAt(int index, V value) {
if (index < 0 || index >= this.size) {
throw new IllegalArgumentException(("Expected index to be within 0..size()-1, but was " + index).toString());
}
int i = (index << 1) + 1;
Object[] objArr = this.array;
V v = (V) objArr[i];
objArr[i] = value;
return v;
}
public V put(K key, V value) {
int i = this.size;
int hashCode = key != null ? key.hashCode() : 0;
int indexOf = key != null ? indexOf(key, hashCode) : indexOfNull();
if (indexOf >= 0) {
int i2 = (indexOf << 1) + 1;
Object[] objArr = this.array;
V v = (V) objArr[i2];
objArr[i2] = value;
return v;
}
int i3 = ~indexOf;
int[] iArr = this.hashes;
if (i >= iArr.length) {
int i4 = 8;
if (i >= 8) {
i4 = (i >> 1) + i;
} else if (i < 4) {
i4 = 4;
}
int[] copyOf = Arrays.copyOf(iArr, i4);
Intrinsics.checkNotNullExpressionValue(copyOf, "copyOf(this, newSize)");
this.hashes = copyOf;
Object[] copyOf2 = Arrays.copyOf(this.array, i4 << 1);
Intrinsics.checkNotNullExpressionValue(copyOf2, "copyOf(this, newSize)");
this.array = copyOf2;
if (i != this.size) {
throw new ConcurrentModificationException();
}
}
if (i3 < i) {
int[] iArr2 = this.hashes;
int i5 = i3 + 1;
ArraysKt.copyInto(iArr2, iArr2, i5, i3, i);
Object[] objArr2 = this.array;
ArraysKt.copyInto(objArr2, objArr2, i5 << 1, i3 << 1, this.size << 1);
}
int i6 = this.size;
if (i == i6) {
int[] iArr3 = this.hashes;
if (i3 < iArr3.length) {
iArr3[i3] = hashCode;
Object[] objArr3 = this.array;
int i7 = i3 << 1;
objArr3[i7] = key;
objArr3[i7 + 1] = value;
this.size = i6 + 1;
return null;
}
}
throw new ConcurrentModificationException();
}
public void putAll(SimpleArrayMap<? extends K, ? extends V> map) {
Intrinsics.checkNotNullParameter(map, "map");
int i = map.size;
ensureCapacity(this.size + i);
if (this.size != 0) {
for (int i2 = 0; i2 < i; i2++) {
put(map.keyAt(i2), map.valueAt(i2));
}
} else if (i > 0) {
ArraysKt.copyInto(map.hashes, this.hashes, 0, 0, i);
ArraysKt.copyInto(map.array, this.array, 0, 0, i << 1);
this.size = i;
}
}
public V putIfAbsent(K key, V value) {
V v = get(key);
return v == null ? put(key, value) : v;
}
public V remove(K key) {
int indexOfKey = indexOfKey(key);
if (indexOfKey >= 0) {
return removeAt(indexOfKey);
}
return null;
}
public boolean remove(K key, V value) {
int indexOfKey = indexOfKey(key);
if (indexOfKey < 0 || !Intrinsics.areEqual(value, valueAt(indexOfKey))) {
return false;
}
removeAt(indexOfKey);
return true;
}
public V removeAt(int index) {
int i;
if (index < 0 || index >= (i = this.size)) {
throw new IllegalArgumentException(("Expected index to be within 0..size()-1, but was " + index).toString());
}
Object[] objArr = this.array;
int i2 = index << 1;
V v = (V) objArr[i2 + 1];
if (i <= 1) {
clear();
} else {
int i3 = i - 1;
int[] iArr = this.hashes;
if (iArr.length > 8 && i < iArr.length / 3) {
int i4 = i > 8 ? i + (i >> 1) : 8;
int[] copyOf = Arrays.copyOf(iArr, i4);
Intrinsics.checkNotNullExpressionValue(copyOf, "copyOf(this, newSize)");
this.hashes = copyOf;
Object[] copyOf2 = Arrays.copyOf(this.array, i4 << 1);
Intrinsics.checkNotNullExpressionValue(copyOf2, "copyOf(this, newSize)");
this.array = copyOf2;
if (i != this.size) {
throw new ConcurrentModificationException();
}
if (index > 0) {
ArraysKt.copyInto(iArr, this.hashes, 0, 0, index);
ArraysKt.copyInto(objArr, this.array, 0, 0, i2);
}
if (index < i3) {
int i5 = index + 1;
ArraysKt.copyInto(iArr, this.hashes, index, i5, i);
ArraysKt.copyInto(objArr, this.array, i2, i5 << 1, i << 1);
}
} else {
if (index < i3) {
int i6 = index + 1;
ArraysKt.copyInto(iArr, iArr, index, i6, i);
Object[] objArr2 = this.array;
ArraysKt.copyInto(objArr2, objArr2, i2, i6 << 1, i << 1);
}
Object[] objArr3 = this.array;
int i7 = i3 << 1;
objArr3[i7] = null;
objArr3[i7 + 1] = null;
}
if (i != this.size) {
throw new ConcurrentModificationException();
}
this.size = i3;
}
return v;
}
public V replace(K key, V value) {
int indexOfKey = indexOfKey(key);
if (indexOfKey >= 0) {
return setValueAt(indexOfKey, value);
}
return null;
}
public boolean replace(K key, V oldValue, V newValue) {
int indexOfKey = indexOfKey(key);
if (indexOfKey < 0 || !Intrinsics.areEqual(oldValue, valueAt(indexOfKey))) {
return false;
}
setValueAt(indexOfKey, newValue);
return true;
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
try {
if (other instanceof SimpleArrayMap) {
if (getSize() != ((SimpleArrayMap) other).getSize()) {
return false;
}
SimpleArrayMap simpleArrayMap = (SimpleArrayMap) other;
int i = this.size;
for (int i2 = 0; i2 < i; i2++) {
K keyAt = keyAt(i2);
V valueAt = valueAt(i2);
Object obj = simpleArrayMap.get(keyAt);
if (valueAt == null) {
if (obj != null || !simpleArrayMap.containsKey(keyAt)) {
return false;
}
} else if (!Intrinsics.areEqual(valueAt, obj)) {
return false;
}
}
return true;
}
if (!(other instanceof Map) || getSize() != ((Map) other).size()) {
return false;
}
int i3 = this.size;
for (int i4 = 0; i4 < i3; i4++) {
K keyAt2 = keyAt(i4);
V valueAt2 = valueAt(i4);
Object obj2 = ((Map) other).get(keyAt2);
if (valueAt2 == null) {
if (obj2 != null || !((Map) other).containsKey(keyAt2)) {
return false;
}
} else if (!Intrinsics.areEqual(valueAt2, obj2)) {
return false;
}
}
return true;
} catch (ClassCastException | NullPointerException unused) {
}
return false;
}
public int hashCode() {
int[] iArr = this.hashes;
Object[] objArr = this.array;
int i = this.size;
int i2 = 1;
int i3 = 0;
int i4 = 0;
while (i3 < i) {
Object obj = objArr[i2];
i4 += (obj != null ? obj.hashCode() : 0) ^ iArr[i3];
i3++;
i2 += 2;
}
return i4;
}
public String toString() {
if (isEmpty()) {
return "{}";
}
StringBuilder sb = new StringBuilder(this.size * 28);
sb.append('{');
int i = this.size;
for (int i2 = 0; i2 < i; i2++) {
if (i2 > 0) {
sb.append(", ");
}
K keyAt = keyAt(i2);
if (keyAt != sb) {
sb.append(keyAt);
} else {
sb.append("(this Map)");
}
sb.append('=');
V valueAt = valueAt(i2);
if (valueAt != sb) {
sb.append(valueAt);
} else {
sb.append("(this Map)");
}
}
sb.append('}');
String sb2 = sb.toString();
Intrinsics.checkNotNullExpressionValue(sb2, "StringBuilder(capacity).…builderAction).toString()");
return sb2;
}
public V get(K key) {
int indexOfKey = indexOfKey(key);
if (indexOfKey >= 0) {
return (V) this.array[(indexOfKey << 1) + 1];
}
return null;
}
/* JADX WARN: Multi-variable type inference failed */
public V getOrDefault(Object key, V defaultValue) {
int indexOfKey = indexOfKey(key);
return indexOfKey >= 0 ? (V) this.array[(indexOfKey << 1) + 1] : defaultValue;
}
}