package q;

import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Map;
import r.AbstractC1481a;

/* JADX INFO: loaded from: classes.dex */
public class i {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int[] f16188q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public Object[] f16189r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f16190s;

    public i(int i) {
        this.f16188q = i == 0 ? AbstractC1481a.f16345a : new int[i];
        this.f16189r = i == 0 ? AbstractC1481a.f16346b : new Object[i << 1];
    }

    public final int a(Object obj) {
        int i = this.f16190s * 2;
        Object[] objArr = this.f16189r;
        if (obj == null) {
            for (int i5 = 1; i5 < i; i5 += 2) {
                if (objArr[i5] == null) {
                    return i5 >> 1;
                }
            }
            return -1;
        }
        for (int i8 = 1; i8 < i; i8 += 2) {
            if (obj.equals(objArr[i8])) {
                return i8 >> 1;
            }
        }
        return -1;
    }

    public final int b(int i, Object obj) {
        int i5 = this.f16190s;
        if (i5 == 0) {
            return -1;
        }
        int iA = AbstractC1481a.a(i5, i, this.f16188q);
        if (iA < 0 || P6.g.a(obj, this.f16189r[iA << 1])) {
            return iA;
        }
        int i8 = iA + 1;
        while (i8 < i5 && this.f16188q[i8] == i) {
            if (P6.g.a(obj, this.f16189r[i8 << 1])) {
                return i8;
            }
            i8++;
        }
        for (int i9 = iA - 1; i9 >= 0 && this.f16188q[i9] == i; i9--) {
            if (P6.g.a(obj, this.f16189r[i9 << 1])) {
                return i9;
            }
        }
        return ~i8;
    }

    public final int c(Object obj) {
        return obj == null ? d() : b(obj.hashCode(), obj);
    }

    public final void clear() {
        if (this.f16190s > 0) {
            this.f16188q = AbstractC1481a.f16345a;
            this.f16189r = AbstractC1481a.f16346b;
            this.f16190s = 0;
        }
        if (this.f16190s > 0) {
            throw new ConcurrentModificationException();
        }
    }

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

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

    public final int d() {
        int i = this.f16190s;
        if (i == 0) {
            return -1;
        }
        int iA = AbstractC1481a.a(i, 0, this.f16188q);
        if (iA < 0 || this.f16189r[iA << 1] == null) {
            return iA;
        }
        int i5 = iA + 1;
        while (i5 < i && this.f16188q[i5] == 0) {
            if (this.f16189r[i5 << 1] == null) {
                return i5;
            }
            i5++;
        }
        for (int i8 = iA - 1; i8 >= 0 && this.f16188q[i8] == 0; i8--) {
            if (this.f16189r[i8 << 1] == null) {
                return i8;
            }
        }
        return ~i5;
    }

    public final Object e(int i) {
        boolean z8 = false;
        if (i >= 0 && i < this.f16190s) {
            z8 = true;
        }
        if (z8) {
            return this.f16189r[i << 1];
        }
        AbstractC1481a.c("Expected index to be within 0..size()-1, but was " + i);
        throw null;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        try {
            if (obj instanceof i) {
                int i = this.f16190s;
                if (i != ((i) obj).f16190s) {
                    return false;
                }
                i iVar = (i) obj;
                for (int i5 = 0; i5 < i; i5++) {
                    Object objE = e(i5);
                    Object objH = h(i5);
                    Object obj2 = iVar.get(objE);
                    if (objH == null) {
                        if (obj2 != null || !iVar.containsKey(objE)) {
                            return false;
                        }
                    } else if (!objH.equals(obj2)) {
                        return false;
                    }
                }
                return true;
            }
            if (!(obj instanceof Map) || this.f16190s != ((Map) obj).size()) {
                return false;
            }
            int i8 = this.f16190s;
            for (int i9 = 0; i9 < i8; i9++) {
                Object objE2 = e(i9);
                Object objH2 = h(i9);
                Object obj3 = ((Map) obj).get(objE2);
                if (objH2 == null) {
                    if (obj3 != null || !((Map) obj).containsKey(objE2)) {
                        return false;
                    }
                } else if (!objH2.equals(obj3)) {
                    return false;
                }
            }
            return true;
        } catch (ClassCastException | NullPointerException unused) {
        }
        return false;
    }

    public final Object f(int i) {
        if (!(i >= 0 && i < this.f16190s)) {
            AbstractC1481a.c("Expected index to be within 0..size()-1, but was " + i);
            throw null;
        }
        Object[] objArr = this.f16189r;
        int i5 = i << 1;
        Object obj = objArr[i5 + 1];
        int i8 = this.f16190s;
        if (i8 <= 1) {
            clear();
            return obj;
        }
        int i9 = i8 - 1;
        int[] iArr = this.f16188q;
        if (iArr.length <= 8 || i8 >= iArr.length / 3) {
            if (i < i9) {
                int i10 = i + 1;
                B6.j.G(i, i10, i8, iArr, iArr);
                Object[] objArr2 = this.f16189r;
                B6.j.H(i5, i10 << 1, i8 << 1, objArr2, objArr2);
            }
            Object[] objArr3 = this.f16189r;
            int i11 = i9 << 1;
            objArr3[i11] = null;
            objArr3[i11 + 1] = null;
        } else {
            int i12 = i8 > 8 ? i8 + (i8 >> 1) : 8;
            int[] iArrCopyOf = Arrays.copyOf(iArr, i12);
            P6.g.d(iArrCopyOf, "copyOf(this, newSize)");
            this.f16188q = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f16189r, i12 << 1);
            P6.g.d(objArrCopyOf, "copyOf(this, newSize)");
            this.f16189r = objArrCopyOf;
            if (i8 != this.f16190s) {
                throw new ConcurrentModificationException();
            }
            if (i > 0) {
                B6.j.G(0, 0, i, iArr, this.f16188q);
                B6.j.H(0, 0, i5, objArr, this.f16189r);
            }
            if (i < i9) {
                int i13 = i + 1;
                B6.j.G(i, i13, i8, iArr, this.f16188q);
                B6.j.H(i5, i13 << 1, i8 << 1, objArr, this.f16189r);
            }
        }
        if (i8 != this.f16190s) {
            throw new ConcurrentModificationException();
        }
        this.f16190s = i9;
        return obj;
    }

    public final Object g(int i, Object obj) {
        boolean z8 = false;
        if (i >= 0 && i < this.f16190s) {
            z8 = true;
        }
        if (!z8) {
            AbstractC1481a.c("Expected index to be within 0..size()-1, but was " + i);
            throw null;
        }
        int i5 = (i << 1) + 1;
        Object[] objArr = this.f16189r;
        Object obj2 = objArr[i5];
        objArr[i5] = obj;
        return obj2;
    }

    public Object get(Object obj) {
        int iC = c(obj);
        if (iC >= 0) {
            return this.f16189r[(iC << 1) + 1];
        }
        return null;
    }

    public final Object getOrDefault(Object obj, Object obj2) {
        int iC = c(obj);
        return iC >= 0 ? this.f16189r[(iC << 1) + 1] : obj2;
    }

    public final Object h(int i) {
        boolean z8 = false;
        if (i >= 0 && i < this.f16190s) {
            z8 = true;
        }
        if (z8) {
            return this.f16189r[(i << 1) + 1];
        }
        AbstractC1481a.c("Expected index to be within 0..size()-1, but was " + i);
        throw null;
    }

    public final int hashCode() {
        int[] iArr = this.f16188q;
        Object[] objArr = this.f16189r;
        int i = this.f16190s;
        int i5 = 1;
        int i8 = 0;
        int iHashCode = 0;
        while (i8 < i) {
            Object obj = objArr[i5];
            iHashCode += (obj != null ? obj.hashCode() : 0) ^ iArr[i8];
            i8++;
            i5 += 2;
        }
        return iHashCode;
    }

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

    public final Object put(Object obj, Object obj2) {
        int i = this.f16190s;
        int iHashCode = obj != null ? obj.hashCode() : 0;
        int iB = obj != null ? b(iHashCode, obj) : d();
        if (iB >= 0) {
            int i5 = (iB << 1) + 1;
            Object[] objArr = this.f16189r;
            Object obj3 = objArr[i5];
            objArr[i5] = obj2;
            return obj3;
        }
        int i8 = ~iB;
        int[] iArr = this.f16188q;
        if (i >= iArr.length) {
            int i9 = 8;
            if (i >= 8) {
                i9 = (i >> 1) + i;
            } else if (i < 4) {
                i9 = 4;
            }
            int[] iArrCopyOf = Arrays.copyOf(iArr, i9);
            P6.g.d(iArrCopyOf, "copyOf(this, newSize)");
            this.f16188q = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f16189r, i9 << 1);
            P6.g.d(objArrCopyOf, "copyOf(this, newSize)");
            this.f16189r = objArrCopyOf;
            if (i != this.f16190s) {
                throw new ConcurrentModificationException();
            }
        }
        if (i8 < i) {
            int[] iArr2 = this.f16188q;
            int i10 = i8 + 1;
            B6.j.G(i10, i8, i, iArr2, iArr2);
            Object[] objArr2 = this.f16189r;
            B6.j.H(i10 << 1, i8 << 1, this.f16190s << 1, objArr2, objArr2);
        }
        int i11 = this.f16190s;
        if (i == i11) {
            int[] iArr3 = this.f16188q;
            if (i8 < iArr3.length) {
                iArr3[i8] = iHashCode;
                Object[] objArr3 = this.f16189r;
                int i12 = i8 << 1;
                objArr3[i12] = obj;
                objArr3[i12 + 1] = obj2;
                this.f16190s = i11 + 1;
                return null;
            }
        }
        throw new ConcurrentModificationException();
    }

    public final Object putIfAbsent(Object obj, Object obj2) {
        Object obj3 = get(obj);
        return obj3 == null ? put(obj, obj2) : obj3;
    }

    public Object remove(Object obj) {
        int iC = c(obj);
        if (iC >= 0) {
            return f(iC);
        }
        return null;
    }

    public final Object replace(Object obj, Object obj2) {
        int iC = c(obj);
        if (iC >= 0) {
            return g(iC, obj2);
        }
        return null;
    }

    public final int size() {
        return this.f16190s;
    }

    public final String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f16190s * 28);
        sb.append('{');
        int i = this.f16190s;
        for (int i5 = 0; i5 < i; i5++) {
            if (i5 > 0) {
                sb.append(", ");
            }
            Object objE = e(i5);
            if (objE != sb) {
                sb.append(objE);
            } else {
                sb.append("(this Map)");
            }
            sb.append('=');
            Object objH = h(i5);
            if (objH != sb) {
                sb.append(objH);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        P6.g.d(string, "StringBuilder(capacity).…builderAction).toString()");
        return string;
    }

    public final boolean remove(Object obj, Object obj2) {
        int iC = c(obj);
        if (iC < 0 || !P6.g.a(obj2, h(iC))) {
            return false;
        }
        f(iC);
        return true;
    }

    public final boolean replace(Object obj, Object obj2, Object obj3) {
        int iC = c(obj);
        if (iC < 0 || !P6.g.a(obj2, h(iC))) {
            return false;
        }
        g(iC, obj3);
        return true;
    }
}
