488 lines
13 KiB
Java
488 lines
13 KiB
Java
package androidx.collection;
|
|
|
|
import java.util.ConcurrentModificationException;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class SimpleArrayMap<K, V> {
|
|
static Object[] d;
|
|
static int e;
|
|
static Object[] f;
|
|
static int g;
|
|
int[] a;
|
|
Object[] b;
|
|
int c;
|
|
|
|
public SimpleArrayMap() {
|
|
this.a = ContainerHelpers.a;
|
|
this.b = ContainerHelpers.c;
|
|
this.c = 0;
|
|
}
|
|
|
|
private static int a(int[] iArr, int i, int i2) {
|
|
try {
|
|
return ContainerHelpers.a(iArr, i, i2);
|
|
} catch (ArrayIndexOutOfBoundsException unused) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
}
|
|
|
|
private void e(int i) {
|
|
if (i == 8) {
|
|
synchronized (ArrayMap.class) {
|
|
if (f != null) {
|
|
Object[] objArr = f;
|
|
this.b = objArr;
|
|
f = (Object[]) objArr[0];
|
|
this.a = (int[]) objArr[1];
|
|
objArr[1] = null;
|
|
objArr[0] = null;
|
|
g--;
|
|
return;
|
|
}
|
|
}
|
|
} else if (i == 4) {
|
|
synchronized (ArrayMap.class) {
|
|
if (d != null) {
|
|
Object[] objArr2 = d;
|
|
this.b = objArr2;
|
|
d = (Object[]) objArr2[0];
|
|
this.a = (int[]) objArr2[1];
|
|
objArr2[1] = null;
|
|
objArr2[0] = null;
|
|
e--;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
this.a = new int[i];
|
|
this.b = new Object[i << 1];
|
|
}
|
|
|
|
int b(Object obj) {
|
|
int i = this.c * 2;
|
|
Object[] objArr = this.b;
|
|
if (obj == 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 (obj.equals(objArr[i3])) {
|
|
return i3 >> 1;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public V c(int i) {
|
|
int i2;
|
|
Object[] objArr = this.b;
|
|
int i3 = i << 1;
|
|
V v = (V) objArr[i3 + 1];
|
|
int i4 = this.c;
|
|
if (i4 <= 1) {
|
|
a(this.a, objArr, i4);
|
|
this.a = ContainerHelpers.a;
|
|
this.b = ContainerHelpers.c;
|
|
i2 = 0;
|
|
} else {
|
|
i2 = i4 - 1;
|
|
int[] iArr = this.a;
|
|
if (iArr.length <= 8 || i4 >= iArr.length / 3) {
|
|
if (i < i2) {
|
|
int[] iArr2 = this.a;
|
|
int i5 = i + 1;
|
|
int i6 = i2 - i;
|
|
System.arraycopy(iArr2, i5, iArr2, i, i6);
|
|
Object[] objArr2 = this.b;
|
|
System.arraycopy(objArr2, i5 << 1, objArr2, i3, i6 << 1);
|
|
}
|
|
Object[] objArr3 = this.b;
|
|
int i7 = i2 << 1;
|
|
objArr3[i7] = null;
|
|
objArr3[i7 + 1] = null;
|
|
} else {
|
|
int i8 = i4 > 8 ? i4 + (i4 >> 1) : 8;
|
|
int[] iArr3 = this.a;
|
|
Object[] objArr4 = this.b;
|
|
e(i8);
|
|
if (i4 != this.c) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
if (i > 0) {
|
|
System.arraycopy(iArr3, 0, this.a, 0, i);
|
|
System.arraycopy(objArr4, 0, this.b, 0, i3);
|
|
}
|
|
if (i < i2) {
|
|
int i9 = i + 1;
|
|
int i10 = i2 - i;
|
|
System.arraycopy(iArr3, i9, this.a, i, i10);
|
|
System.arraycopy(objArr4, i9 << 1, this.b, i3, i10 << 1);
|
|
}
|
|
}
|
|
}
|
|
if (i4 != this.c) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
this.c = i2;
|
|
return v;
|
|
}
|
|
|
|
public void clear() {
|
|
int i = this.c;
|
|
if (i > 0) {
|
|
int[] iArr = this.a;
|
|
Object[] objArr = this.b;
|
|
this.a = ContainerHelpers.a;
|
|
this.b = ContainerHelpers.c;
|
|
this.c = 0;
|
|
a(iArr, objArr, i);
|
|
}
|
|
if (this.c > 0) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
}
|
|
|
|
public boolean containsKey(Object obj) {
|
|
return a(obj) >= 0;
|
|
}
|
|
|
|
public boolean containsValue(Object obj) {
|
|
return b(obj) >= 0;
|
|
}
|
|
|
|
public V d(int i) {
|
|
return (V) this.b[(i << 1) + 1];
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (obj instanceof SimpleArrayMap) {
|
|
SimpleArrayMap simpleArrayMap = (SimpleArrayMap) obj;
|
|
if (size() != simpleArrayMap.size()) {
|
|
return false;
|
|
}
|
|
for (int i = 0; i < this.c; i++) {
|
|
try {
|
|
K b = b(i);
|
|
V d2 = d(i);
|
|
Object obj2 = simpleArrayMap.get(b);
|
|
if (d2 == null) {
|
|
if (obj2 != null || !simpleArrayMap.containsKey(b)) {
|
|
return false;
|
|
}
|
|
} else if (!d2.equals(obj2)) {
|
|
return false;
|
|
}
|
|
} catch (ClassCastException | NullPointerException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
if (obj instanceof Map) {
|
|
Map map = (Map) obj;
|
|
if (size() != map.size()) {
|
|
return false;
|
|
}
|
|
for (int i2 = 0; i2 < this.c; i2++) {
|
|
try {
|
|
K b2 = b(i2);
|
|
V d3 = d(i2);
|
|
Object obj3 = map.get(b2);
|
|
if (d3 == null) {
|
|
if (obj3 != null || !map.containsKey(b2)) {
|
|
return false;
|
|
}
|
|
} else if (!d3.equals(obj3)) {
|
|
return false;
|
|
}
|
|
} catch (ClassCastException | NullPointerException unused2) {
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public V get(Object obj) {
|
|
int a = a(obj);
|
|
if (a >= 0) {
|
|
return (V) this.b[(a << 1) + 1];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int hashCode() {
|
|
int[] iArr = this.a;
|
|
Object[] objArr = this.b;
|
|
int i = this.c;
|
|
int i2 = 0;
|
|
int i3 = 0;
|
|
int i4 = 1;
|
|
while (i2 < i) {
|
|
Object obj = objArr[i4];
|
|
i3 += (obj == null ? 0 : obj.hashCode()) ^ iArr[i2];
|
|
i2++;
|
|
i4 += 2;
|
|
}
|
|
return i3;
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
return this.c <= 0;
|
|
}
|
|
|
|
public V put(K k, V v) {
|
|
int i;
|
|
int a;
|
|
int i2 = this.c;
|
|
if (k == null) {
|
|
a = a();
|
|
i = 0;
|
|
} else {
|
|
int hashCode = k.hashCode();
|
|
i = hashCode;
|
|
a = a(k, hashCode);
|
|
}
|
|
if (a >= 0) {
|
|
int i3 = (a << 1) + 1;
|
|
Object[] objArr = this.b;
|
|
V v2 = (V) objArr[i3];
|
|
objArr[i3] = v;
|
|
return v2;
|
|
}
|
|
int i4 = ~a;
|
|
if (i2 >= this.a.length) {
|
|
int i5 = 4;
|
|
if (i2 >= 8) {
|
|
i5 = (i2 >> 1) + i2;
|
|
} else if (i2 >= 4) {
|
|
i5 = 8;
|
|
}
|
|
int[] iArr = this.a;
|
|
Object[] objArr2 = this.b;
|
|
e(i5);
|
|
if (i2 != this.c) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
int[] iArr2 = this.a;
|
|
if (iArr2.length > 0) {
|
|
System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
|
|
System.arraycopy(objArr2, 0, this.b, 0, objArr2.length);
|
|
}
|
|
a(iArr, objArr2, i2);
|
|
}
|
|
if (i4 < i2) {
|
|
int[] iArr3 = this.a;
|
|
int i6 = i4 + 1;
|
|
System.arraycopy(iArr3, i4, iArr3, i6, i2 - i4);
|
|
Object[] objArr3 = this.b;
|
|
System.arraycopy(objArr3, i4 << 1, objArr3, i6 << 1, (this.c - i4) << 1);
|
|
}
|
|
int i7 = this.c;
|
|
if (i2 == i7) {
|
|
int[] iArr4 = this.a;
|
|
if (i4 < iArr4.length) {
|
|
iArr4[i4] = i;
|
|
Object[] objArr4 = this.b;
|
|
int i8 = i4 << 1;
|
|
objArr4[i8] = k;
|
|
objArr4[i8 + 1] = v;
|
|
this.c = i7 + 1;
|
|
return null;
|
|
}
|
|
}
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
|
|
public V remove(Object obj) {
|
|
int a = a(obj);
|
|
if (a >= 0) {
|
|
return c(a);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int size() {
|
|
return this.c;
|
|
}
|
|
|
|
public String toString() {
|
|
if (isEmpty()) {
|
|
return "{}";
|
|
}
|
|
StringBuilder sb = new StringBuilder(this.c * 28);
|
|
sb.append('{');
|
|
for (int i = 0; i < this.c; i++) {
|
|
if (i > 0) {
|
|
sb.append(", ");
|
|
}
|
|
K b = b(i);
|
|
if (b != this) {
|
|
sb.append(b);
|
|
} else {
|
|
sb.append("(this Map)");
|
|
}
|
|
sb.append('=');
|
|
V d2 = d(i);
|
|
if (d2 != this) {
|
|
sb.append(d2);
|
|
} else {
|
|
sb.append("(this Map)");
|
|
}
|
|
}
|
|
sb.append('}');
|
|
return sb.toString();
|
|
}
|
|
|
|
int a(Object obj, int i) {
|
|
int i2 = this.c;
|
|
if (i2 == 0) {
|
|
return -1;
|
|
}
|
|
int a = a(this.a, i2, i);
|
|
if (a < 0 || obj.equals(this.b[a << 1])) {
|
|
return a;
|
|
}
|
|
int i3 = a + 1;
|
|
while (i3 < i2 && this.a[i3] == i) {
|
|
if (obj.equals(this.b[i3 << 1])) {
|
|
return i3;
|
|
}
|
|
i3++;
|
|
}
|
|
for (int i4 = a - 1; i4 >= 0 && this.a[i4] == i; i4--) {
|
|
if (obj.equals(this.b[i4 << 1])) {
|
|
return i4;
|
|
}
|
|
}
|
|
return ~i3;
|
|
}
|
|
|
|
public SimpleArrayMap(int i) {
|
|
if (i == 0) {
|
|
this.a = ContainerHelpers.a;
|
|
this.b = ContainerHelpers.c;
|
|
} else {
|
|
e(i);
|
|
}
|
|
this.c = 0;
|
|
}
|
|
|
|
public K b(int i) {
|
|
return (K) this.b[i << 1];
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public SimpleArrayMap(SimpleArrayMap<K, V> simpleArrayMap) {
|
|
this();
|
|
if (simpleArrayMap != 0) {
|
|
a((SimpleArrayMap) simpleArrayMap);
|
|
}
|
|
}
|
|
|
|
int a() {
|
|
int i = this.c;
|
|
if (i == 0) {
|
|
return -1;
|
|
}
|
|
int a = a(this.a, i, 0);
|
|
if (a < 0 || this.b[a << 1] == null) {
|
|
return a;
|
|
}
|
|
int i2 = a + 1;
|
|
while (i2 < i && this.a[i2] == 0) {
|
|
if (this.b[i2 << 1] == null) {
|
|
return i2;
|
|
}
|
|
i2++;
|
|
}
|
|
for (int i3 = a - 1; i3 >= 0 && this.a[i3] == 0; i3--) {
|
|
if (this.b[i3 << 1] == null) {
|
|
return i3;
|
|
}
|
|
}
|
|
return ~i2;
|
|
}
|
|
|
|
private static void a(int[] iArr, Object[] objArr, int i) {
|
|
if (iArr.length == 8) {
|
|
synchronized (ArrayMap.class) {
|
|
if (g < 10) {
|
|
objArr[0] = f;
|
|
objArr[1] = iArr;
|
|
for (int i2 = (i << 1) - 1; i2 >= 2; i2--) {
|
|
objArr[i2] = null;
|
|
}
|
|
f = objArr;
|
|
g++;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (iArr.length == 4) {
|
|
synchronized (ArrayMap.class) {
|
|
if (e < 10) {
|
|
objArr[0] = d;
|
|
objArr[1] = iArr;
|
|
for (int i3 = (i << 1) - 1; i3 >= 2; i3--) {
|
|
objArr[i3] = null;
|
|
}
|
|
d = objArr;
|
|
e++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void a(int i) {
|
|
int i2 = this.c;
|
|
int[] iArr = this.a;
|
|
if (iArr.length < i) {
|
|
Object[] objArr = this.b;
|
|
e(i);
|
|
if (this.c > 0) {
|
|
System.arraycopy(iArr, 0, this.a, 0, i2);
|
|
System.arraycopy(objArr, 0, this.b, 0, i2 << 1);
|
|
}
|
|
a(iArr, objArr, i2);
|
|
}
|
|
if (this.c != i2) {
|
|
throw new ConcurrentModificationException();
|
|
}
|
|
}
|
|
|
|
public int a(Object obj) {
|
|
return obj == null ? a() : a(obj, obj.hashCode());
|
|
}
|
|
|
|
public V a(int i, V v) {
|
|
int i2 = (i << 1) + 1;
|
|
Object[] objArr = this.b;
|
|
V v2 = (V) objArr[i2];
|
|
objArr[i2] = v;
|
|
return v2;
|
|
}
|
|
|
|
public void a(SimpleArrayMap<? extends K, ? extends V> simpleArrayMap) {
|
|
int i = simpleArrayMap.c;
|
|
a(this.c + i);
|
|
if (this.c != 0) {
|
|
for (int i2 = 0; i2 < i; i2++) {
|
|
put(simpleArrayMap.b(i2), simpleArrayMap.d(i2));
|
|
}
|
|
} else if (i > 0) {
|
|
System.arraycopy(simpleArrayMap.a, 0, this.a, 0, i);
|
|
System.arraycopy(simpleArrayMap.b, 0, this.b, 0, i << 1);
|
|
this.c = i;
|
|
}
|
|
}
|
|
}
|