package androidx.collection; import java.util.ConcurrentModificationException; import java.util.Map; /* loaded from: classes.dex */ public class g { /* renamed from: d, reason: collision with root package name */ static Object[] f1302d; /* renamed from: e, reason: collision with root package name */ static int f1303e; /* renamed from: f, reason: collision with root package name */ static Object[] f1304f; /* renamed from: g, reason: collision with root package name */ static int f1305g; /* renamed from: a, reason: collision with root package name */ int[] f1306a; /* renamed from: b, reason: collision with root package name */ Object[] f1307b; /* renamed from: c, reason: collision with root package name */ int f1308c; public g() { this.f1306a = c.f1279a; this.f1307b = c.f1281c; this.f1308c = 0; } private void a(int i10) { if (i10 == 8) { synchronized (g.class) { Object[] objArr = f1304f; if (objArr != null) { this.f1307b = objArr; f1304f = (Object[]) objArr[0]; this.f1306a = (int[]) objArr[1]; objArr[1] = null; objArr[0] = null; f1305g--; return; } } } else if (i10 == 4) { synchronized (g.class) { Object[] objArr2 = f1302d; if (objArr2 != null) { this.f1307b = objArr2; f1302d = (Object[]) objArr2[0]; this.f1306a = (int[]) objArr2[1]; objArr2[1] = null; objArr2[0] = null; f1303e--; return; } } } this.f1306a = new int[i10]; this.f1307b = new Object[i10 << 1]; } private static int b(int[] iArr, int i10, int i11) { try { return c.a(iArr, i10, i11); } catch (ArrayIndexOutOfBoundsException unused) { throw new ConcurrentModificationException(); } } private static void d(int[] iArr, Object[] objArr, int i10) { if (iArr.length == 8) { synchronized (g.class) { if (f1305g < 10) { objArr[0] = f1304f; objArr[1] = iArr; for (int i11 = (i10 << 1) - 1; i11 >= 2; i11--) { objArr[i11] = null; } f1304f = objArr; f1305g++; } } return; } if (iArr.length == 4) { synchronized (g.class) { if (f1303e < 10) { objArr[0] = f1302d; objArr[1] = iArr; for (int i12 = (i10 << 1) - 1; i12 >= 2; i12--) { objArr[i12] = null; } f1302d = objArr; f1303e++; } } } } public void c(int i10) { int i11 = this.f1308c; int[] iArr = this.f1306a; if (iArr.length < i10) { Object[] objArr = this.f1307b; a(i10); if (this.f1308c > 0) { System.arraycopy(iArr, 0, this.f1306a, 0, i11); System.arraycopy(objArr, 0, this.f1307b, 0, i11 << 1); } d(iArr, objArr, i11); } if (this.f1308c != i11) { throw new ConcurrentModificationException(); } } public void clear() { int i10 = this.f1308c; if (i10 > 0) { int[] iArr = this.f1306a; Object[] objArr = this.f1307b; this.f1306a = c.f1279a; this.f1307b = c.f1281c; this.f1308c = 0; d(iArr, objArr, i10); } if (this.f1308c > 0) { throw new ConcurrentModificationException(); } } public boolean containsKey(Object obj) { return f(obj) >= 0; } public boolean containsValue(Object obj) { return h(obj) >= 0; } int e(Object obj, int i10) { int i11 = this.f1308c; if (i11 == 0) { return -1; } int b10 = b(this.f1306a, i11, i10); if (b10 < 0) { return b10; } if (obj.equals(this.f1307b[b10 << 1])) { return b10; } int i12 = b10 + 1; while (i12 < i11 && this.f1306a[i12] == i10) { if (obj.equals(this.f1307b[i12 << 1])) { return i12; } i12++; } for (int i13 = b10 - 1; i13 >= 0 && this.f1306a[i13] == i10; i13--) { if (obj.equals(this.f1307b[i13 << 1])) { return i13; } } return ~i12; } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof g) { g gVar = (g) obj; if (size() != gVar.size()) { return false; } for (int i10 = 0; i10 < this.f1308c; i10++) { try { Object i11 = i(i10); Object m10 = m(i10); Object obj2 = gVar.get(i11); if (m10 == null) { if (obj2 != null || !gVar.containsKey(i11)) { return false; } } else if (!m10.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 i12 = 0; i12 < this.f1308c; i12++) { try { Object i13 = i(i12); Object m11 = m(i12); Object obj3 = map.get(i13); if (m11 == null) { if (obj3 != null || !map.containsKey(i13)) { return false; } } else if (!m11.equals(obj3)) { return false; } } catch (ClassCastException | NullPointerException unused2) { } } return true; } return false; } public int f(Object obj) { return obj == null ? g() : e(obj, obj.hashCode()); } int g() { int i10 = this.f1308c; if (i10 == 0) { return -1; } int b10 = b(this.f1306a, i10, 0); if (b10 < 0) { return b10; } if (this.f1307b[b10 << 1] == null) { return b10; } int i11 = b10 + 1; while (i11 < i10 && this.f1306a[i11] == 0) { if (this.f1307b[i11 << 1] == null) { return i11; } i11++; } for (int i12 = b10 - 1; i12 >= 0 && this.f1306a[i12] == 0; i12--) { if (this.f1307b[i12 << 1] == null) { return i12; } } return ~i11; } public Object get(Object obj) { return getOrDefault(obj, null); } public Object getOrDefault(Object obj, Object obj2) { int f10 = f(obj); return f10 >= 0 ? this.f1307b[(f10 << 1) + 1] : obj2; } int h(Object obj) { int i10 = this.f1308c * 2; Object[] objArr = this.f1307b; if (obj == null) { for (int i11 = 1; i11 < i10; i11 += 2) { if (objArr[i11] == null) { return i11 >> 1; } } return -1; } for (int i12 = 1; i12 < i10; i12 += 2) { if (obj.equals(objArr[i12])) { return i12 >> 1; } } return -1; } public int hashCode() { int[] iArr = this.f1306a; Object[] objArr = this.f1307b; int i10 = this.f1308c; int i11 = 1; int i12 = 0; int i13 = 0; while (i12 < i10) { Object obj = objArr[i11]; i13 += (obj == null ? 0 : obj.hashCode()) ^ iArr[i12]; i12++; i11 += 2; } return i13; } public Object i(int i10) { return this.f1307b[i10 << 1]; } public boolean isEmpty() { return this.f1308c <= 0; } public void j(g gVar) { int i10 = gVar.f1308c; c(this.f1308c + i10); if (this.f1308c != 0) { for (int i11 = 0; i11 < i10; i11++) { put(gVar.i(i11), gVar.m(i11)); } } else if (i10 > 0) { System.arraycopy(gVar.f1306a, 0, this.f1306a, 0, i10); System.arraycopy(gVar.f1307b, 0, this.f1307b, 0, i10 << 1); this.f1308c = i10; } } public Object k(int i10) { Object[] objArr = this.f1307b; int i11 = i10 << 1; Object obj = objArr[i11 + 1]; int i12 = this.f1308c; int i13 = 0; if (i12 <= 1) { d(this.f1306a, objArr, i12); this.f1306a = c.f1279a; this.f1307b = c.f1281c; } else { int i14 = i12 - 1; int[] iArr = this.f1306a; if (iArr.length <= 8 || i12 >= iArr.length / 3) { if (i10 < i14) { int i15 = i10 + 1; int i16 = i14 - i10; System.arraycopy(iArr, i15, iArr, i10, i16); Object[] objArr2 = this.f1307b; System.arraycopy(objArr2, i15 << 1, objArr2, i11, i16 << 1); } Object[] objArr3 = this.f1307b; int i17 = i14 << 1; objArr3[i17] = null; objArr3[i17 + 1] = null; } else { a(i12 > 8 ? i12 + (i12 >> 1) : 8); if (i12 != this.f1308c) { throw new ConcurrentModificationException(); } if (i10 > 0) { System.arraycopy(iArr, 0, this.f1306a, 0, i10); System.arraycopy(objArr, 0, this.f1307b, 0, i11); } if (i10 < i14) { int i18 = i10 + 1; int i19 = i14 - i10; System.arraycopy(iArr, i18, this.f1306a, i10, i19); System.arraycopy(objArr, i18 << 1, this.f1307b, i11, i19 << 1); } } i13 = i14; } if (i12 != this.f1308c) { throw new ConcurrentModificationException(); } this.f1308c = i13; return obj; } public Object l(int i10, Object obj) { int i11 = (i10 << 1) + 1; Object[] objArr = this.f1307b; Object obj2 = objArr[i11]; objArr[i11] = obj; return obj2; } public Object m(int i10) { return this.f1307b[(i10 << 1) + 1]; } public Object put(Object obj, Object obj2) { int i10; int e10; int i11 = this.f1308c; if (obj == null) { e10 = g(); i10 = 0; } else { int hashCode = obj.hashCode(); i10 = hashCode; e10 = e(obj, hashCode); } if (e10 >= 0) { int i12 = (e10 << 1) + 1; Object[] objArr = this.f1307b; Object obj3 = objArr[i12]; objArr[i12] = obj2; return obj3; } int i13 = ~e10; int[] iArr = this.f1306a; if (i11 >= iArr.length) { int i14 = 8; if (i11 >= 8) { i14 = (i11 >> 1) + i11; } else if (i11 < 4) { i14 = 4; } Object[] objArr2 = this.f1307b; a(i14); if (i11 != this.f1308c) { throw new ConcurrentModificationException(); } int[] iArr2 = this.f1306a; if (iArr2.length > 0) { System.arraycopy(iArr, 0, iArr2, 0, iArr.length); System.arraycopy(objArr2, 0, this.f1307b, 0, objArr2.length); } d(iArr, objArr2, i11); } if (i13 < i11) { int[] iArr3 = this.f1306a; int i15 = i13 + 1; System.arraycopy(iArr3, i13, iArr3, i15, i11 - i13); Object[] objArr3 = this.f1307b; System.arraycopy(objArr3, i13 << 1, objArr3, i15 << 1, (this.f1308c - i13) << 1); } int i16 = this.f1308c; if (i11 == i16) { int[] iArr4 = this.f1306a; if (i13 < iArr4.length) { iArr4[i13] = i10; Object[] objArr4 = this.f1307b; int i17 = i13 << 1; objArr4[i17] = obj; objArr4[i17 + 1] = obj2; this.f1308c = i16 + 1; return null; } } throw new ConcurrentModificationException(); } public Object putIfAbsent(Object obj, Object obj2) { Object obj3 = get(obj); return obj3 == null ? put(obj, obj2) : obj3; } public Object remove(Object obj) { int f10 = f(obj); if (f10 >= 0) { return k(f10); } return null; } public Object replace(Object obj, Object obj2) { int f10 = f(obj); if (f10 >= 0) { return l(f10, obj2); } return null; } public int size() { return this.f1308c; } public String toString() { if (isEmpty()) { return "{}"; } StringBuilder sb = new StringBuilder(this.f1308c * 28); sb.append('{'); for (int i10 = 0; i10 < this.f1308c; i10++) { if (i10 > 0) { sb.append(", "); } Object i11 = i(i10); if (i11 != this) { sb.append(i11); } else { sb.append("(this Map)"); } sb.append('='); Object m10 = m(i10); if (m10 != this) { sb.append(m10); } else { sb.append("(this Map)"); } } sb.append('}'); return sb.toString(); } public boolean remove(Object obj, Object obj2) { int f10 = f(obj); if (f10 < 0) { return false; } Object m10 = m(f10); if (obj2 != m10 && (obj2 == null || !obj2.equals(m10))) { return false; } k(f10); return true; } public boolean replace(Object obj, Object obj2, Object obj3) { int f10 = f(obj); if (f10 < 0) { return false; } Object m10 = m(f10); if (m10 != obj2 && (obj2 == null || !obj2.equals(m10))) { return false; } l(f10, obj3); return true; } public g(int i10) { if (i10 == 0) { this.f1306a = c.f1279a; this.f1307b = c.f1281c; } else { a(i10); } this.f1308c = 0; } public g(g gVar) { this(); if (gVar != null) { j(gVar); } } }