package g.c;

import java.util.ConcurrentModificationException;
import java.util.Map;

/* JADX INFO: compiled from: SimpleArrayMap.java */
/* JADX INFO: loaded from: classes.dex */
public class g<K, V> {
    static Object[] f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    static int f445g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    static Object[] f446h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    static int f447i;
    int[] b;
    Object[] d;
    int e;

    public g() {
        this.b = c.a;
        this.d = c.c;
        this.e = 0;
    }

    private void b(int i2) {
        if (i2 == 8) {
            synchronized (a.class) {
                if (f446h != null) {
                    Object[] objArr = f446h;
                    this.d = objArr;
                    f446h = (Object[]) objArr[0];
                    this.b = (int[]) objArr[1];
                    objArr[1] = null;
                    objArr[0] = null;
                    f447i--;
                    return;
                }
            }
        } else if (i2 == 4) {
            synchronized (a.class) {
                if (f != null) {
                    Object[] objArr2 = f;
                    this.d = objArr2;
                    f = (Object[]) objArr2[0];
                    this.b = (int[]) objArr2[1];
                    objArr2[1] = null;
                    objArr2[0] = null;
                    f445g--;
                    return;
                }
            }
        }
        this.b = new int[i2];
        this.d = new Object[i2 << 1];
    }

    private static int c(int[] iArr, int i2, int i3) {
        try {
            return c.a(iArr, i2, i3);
        } catch (ArrayIndexOutOfBoundsException unused) {
            throw new ConcurrentModificationException();
        }
    }

    private static void e(int[] iArr, Object[] objArr, int i2) {
        if (iArr.length == 8) {
            synchronized (a.class) {
                if (f447i < 10) {
                    objArr[0] = f446h;
                    objArr[1] = iArr;
                    for (int i3 = (i2 << 1) - 1; i3 >= 2; i3--) {
                        objArr[i3] = null;
                    }
                    f446h = objArr;
                    f447i++;
                }
            }
            return;
        }
        if (iArr.length == 4) {
            synchronized (a.class) {
                if (f445g < 10) {
                    objArr[0] = f;
                    objArr[1] = iArr;
                    for (int i4 = (i2 << 1) - 1; i4 >= 2; i4--) {
                        objArr[i4] = null;
                    }
                    f = objArr;
                    f445g++;
                }
            }
        }
    }

    public void clear() {
        int i2 = this.e;
        if (i2 > 0) {
            int[] iArr = this.b;
            Object[] objArr = this.d;
            this.b = c.a;
            this.d = c.c;
            this.e = 0;
            e(iArr, objArr, i2);
        }
        if (this.e > 0) {
            throw new ConcurrentModificationException();
        }
    }

    public boolean containsKey(Object obj) {
        return g(obj) >= 0;
    }

    public boolean containsValue(Object obj) {
        return i(obj) >= 0;
    }

    public void d(int i2) {
        int i3 = this.e;
        int[] iArr = this.b;
        if (iArr.length < i2) {
            Object[] objArr = this.d;
            b(i2);
            if (this.e > 0) {
                System.arraycopy(iArr, 0, this.b, 0, i3);
                System.arraycopy(objArr, 0, this.d, 0, i3 << 1);
            }
            e(iArr, objArr, i3);
        }
        if (this.e != i3) {
            throw new ConcurrentModificationException();
        }
    }

    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 i2 = 0; i2 < this.e; i2++) {
                try {
                    K kJ = j(i2);
                    V vM = m(i2);
                    Object obj2 = gVar.get(kJ);
                    if (vM == null) {
                        if (obj2 != null || !gVar.containsKey(kJ)) {
                            return false;
                        }
                    } else if (!vM.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 i3 = 0; i3 < this.e; i3++) {
                try {
                    K kJ2 = j(i3);
                    V vM2 = m(i3);
                    Object obj3 = map.get(kJ2);
                    if (vM2 == null) {
                        if (obj3 != null || !map.containsKey(kJ2)) {
                            return false;
                        }
                    } else if (!vM2.equals(obj3)) {
                        return false;
                    }
                } catch (ClassCastException | NullPointerException unused2) {
                }
            }
            return true;
        }
        return false;
    }

    int f(Object obj, int i2) {
        int i3 = this.e;
        if (i3 == 0) {
            return -1;
        }
        int iC = c(this.b, i3, i2);
        if (iC < 0 || obj.equals(this.d[iC << 1])) {
            return iC;
        }
        int i4 = iC + 1;
        while (i4 < i3 && this.b[i4] == i2) {
            if (obj.equals(this.d[i4 << 1])) {
                return i4;
            }
            i4++;
        }
        for (int i5 = iC - 1; i5 >= 0 && this.b[i5] == i2; i5--) {
            if (obj.equals(this.d[i5 << 1])) {
                return i5;
            }
        }
        return ~i4;
    }

    public int g(Object obj) {
        return obj == null ? h() : f(obj, obj.hashCode());
    }

    public V get(Object obj) {
        int iG = g(obj);
        if (iG >= 0) {
            return (V) this.d[(iG << 1) + 1];
        }
        return null;
    }

    int h() {
        int i2 = this.e;
        if (i2 == 0) {
            return -1;
        }
        int iC = c(this.b, i2, 0);
        if (iC < 0 || this.d[iC << 1] == null) {
            return iC;
        }
        int i3 = iC + 1;
        while (i3 < i2 && this.b[i3] == 0) {
            if (this.d[i3 << 1] == null) {
                return i3;
            }
            i3++;
        }
        for (int i4 = iC - 1; i4 >= 0 && this.b[i4] == 0; i4--) {
            if (this.d[i4 << 1] == null) {
                return i4;
            }
        }
        return ~i3;
    }

    public int hashCode() {
        int[] iArr = this.b;
        Object[] objArr = this.d;
        int i2 = this.e;
        int i3 = 1;
        int i4 = 0;
        int iHashCode = 0;
        while (i4 < i2) {
            Object obj = objArr[i3];
            iHashCode += (obj == null ? 0 : obj.hashCode()) ^ iArr[i4];
            i4++;
            i3 += 2;
        }
        return iHashCode;
    }

    int i(Object obj) {
        int i2 = this.e * 2;
        Object[] objArr = this.d;
        if (obj == null) {
            for (int i3 = 1; i3 < i2; i3 += 2) {
                if (objArr[i3] == null) {
                    return i3 >> 1;
                }
            }
            return -1;
        }
        for (int i4 = 1; i4 < i2; i4 += 2) {
            if (obj.equals(objArr[i4])) {
                return i4 >> 1;
            }
        }
        return -1;
    }

    public boolean isEmpty() {
        return this.e <= 0;
    }

    public K j(int i2) {
        return (K) this.d[i2 << 1];
    }

    public V k(int i2) {
        Object[] objArr = this.d;
        int i3 = i2 << 1;
        V v = (V) objArr[i3 + 1];
        int i4 = this.e;
        int i5 = 0;
        if (i4 <= 1) {
            e(this.b, objArr, i4);
            this.b = c.a;
            this.d = c.c;
        } else {
            int i6 = i4 - 1;
            int[] iArr = this.b;
            if (iArr.length <= 8 || i4 >= iArr.length / 3) {
                if (i2 < i6) {
                    int[] iArr2 = this.b;
                    int i7 = i2 + 1;
                    int i8 = i6 - i2;
                    System.arraycopy(iArr2, i7, iArr2, i2, i8);
                    Object[] objArr2 = this.d;
                    System.arraycopy(objArr2, i7 << 1, objArr2, i3, i8 << 1);
                }
                Object[] objArr3 = this.d;
                int i9 = i6 << 1;
                objArr3[i9] = null;
                objArr3[i9 + 1] = null;
            } else {
                int i10 = i4 > 8 ? i4 + (i4 >> 1) : 8;
                int[] iArr3 = this.b;
                Object[] objArr4 = this.d;
                b(i10);
                if (i4 != this.e) {
                    throw new ConcurrentModificationException();
                }
                if (i2 > 0) {
                    System.arraycopy(iArr3, 0, this.b, 0, i2);
                    System.arraycopy(objArr4, 0, this.d, 0, i3);
                }
                if (i2 < i6) {
                    int i11 = i2 + 1;
                    int i12 = i6 - i2;
                    System.arraycopy(iArr3, i11, this.b, i2, i12);
                    System.arraycopy(objArr4, i11 << 1, this.d, i3, i12 << 1);
                }
            }
            i5 = i6;
        }
        if (i4 != this.e) {
            throw new ConcurrentModificationException();
        }
        this.e = i5;
        return v;
    }

    public V l(int i2, V v) {
        int i3 = (i2 << 1) + 1;
        Object[] objArr = this.d;
        V v2 = (V) objArr[i3];
        objArr[i3] = v;
        return v2;
    }

    public V m(int i2) {
        return (V) this.d[(i2 << 1) + 1];
    }

    public V put(K k2, V v) {
        int i2;
        int iF;
        int i3 = this.e;
        if (k2 == null) {
            iF = h();
            i2 = 0;
        } else {
            int iHashCode = k2.hashCode();
            i2 = iHashCode;
            iF = f(k2, iHashCode);
        }
        if (iF >= 0) {
            int i4 = (iF << 1) + 1;
            Object[] objArr = this.d;
            V v2 = (V) objArr[i4];
            objArr[i4] = v;
            return v2;
        }
        int i5 = ~iF;
        if (i3 >= this.b.length) {
            int i6 = 4;
            if (i3 >= 8) {
                i6 = (i3 >> 1) + i3;
            } else if (i3 >= 4) {
                i6 = 8;
            }
            int[] iArr = this.b;
            Object[] objArr2 = this.d;
            b(i6);
            if (i3 != this.e) {
                throw new ConcurrentModificationException();
            }
            int[] iArr2 = this.b;
            if (iArr2.length > 0) {
                System.arraycopy(iArr, 0, iArr2, 0, iArr.length);
                System.arraycopy(objArr2, 0, this.d, 0, objArr2.length);
            }
            e(iArr, objArr2, i3);
        }
        if (i5 < i3) {
            int[] iArr3 = this.b;
            int i7 = i5 + 1;
            System.arraycopy(iArr3, i5, iArr3, i7, i3 - i5);
            Object[] objArr3 = this.d;
            System.arraycopy(objArr3, i5 << 1, objArr3, i7 << 1, (this.e - i5) << 1);
        }
        int i8 = this.e;
        if (i3 == i8) {
            int[] iArr4 = this.b;
            if (i5 < iArr4.length) {
                iArr4[i5] = i2;
                Object[] objArr4 = this.d;
                int i9 = i5 << 1;
                objArr4[i9] = k2;
                objArr4[i9 + 1] = v;
                this.e = i8 + 1;
                return null;
            }
        }
        throw new ConcurrentModificationException();
    }

    public V remove(Object obj) {
        int iG = g(obj);
        if (iG >= 0) {
            return k(iG);
        }
        return null;
    }

    public int size() {
        return this.e;
    }

    public String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.e * 28);
        sb.append('{');
        for (int i2 = 0; i2 < this.e; i2++) {
            if (i2 > 0) {
                sb.append(", ");
            }
            K kJ = j(i2);
            if (kJ != this) {
                sb.append(kJ);
            } else {
                sb.append("(this Map)");
            }
            sb.append('=');
            V vM = m(i2);
            if (vM != this) {
                sb.append(vM);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        return sb.toString();
    }

    public g(int i2) {
        if (i2 == 0) {
            this.b = c.a;
            this.d = c.c;
        } else {
            b(i2);
        }
        this.e = 0;
    }
}
