package n;

import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Map;
import o.AbstractC2628a;
import x4.AbstractC3250p;

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

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

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

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

    public d0(int i6) {
        this.f21414a = i6 == 0 ? AbstractC2628a.f21780a : new int[i6];
        this.f21415b = i6 == 0 ? AbstractC2628a.f21782c : new Object[i6 << 1];
    }

    public final int a(Object obj) {
        int i6 = this.f21416c * 2;
        Object[] objArr = this.f21415b;
        if (obj == null) {
            for (int i7 = 1; i7 < i6; i7 += 2) {
                if (objArr[i7] == null) {
                    return i7 >> 1;
                }
            }
            return -1;
        }
        for (int i8 = 1; i8 < i6; i8 += 2) {
            if (obj.equals(objArr[i8])) {
                return i8 >> 1;
            }
        }
        return -1;
    }

    public final void b(int i6) {
        int i7 = this.f21416c;
        int[] iArr = this.f21414a;
        if (iArr.length < i6) {
            int[] iArrCopyOf = Arrays.copyOf(iArr, i6);
            kotlin.jvm.internal.o.g(iArrCopyOf, "copyOf(...)");
            this.f21414a = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f21415b, i6 * 2);
            kotlin.jvm.internal.o.g(objArrCopyOf, "copyOf(...)");
            this.f21415b = objArrCopyOf;
        }
        if (this.f21416c != i7) {
            throw new ConcurrentModificationException();
        }
    }

    public final int c(int i6, Object obj) {
        int i7 = this.f21416c;
        if (i7 == 0) {
            return -1;
        }
        int iA = AbstractC2628a.a(i7, i6, this.f21414a);
        if (iA < 0 || kotlin.jvm.internal.o.c(obj, this.f21415b[iA << 1])) {
            return iA;
        }
        int i8 = iA + 1;
        while (i8 < i7 && this.f21414a[i8] == i6) {
            if (kotlin.jvm.internal.o.c(obj, this.f21415b[i8 << 1])) {
                return i8;
            }
            i8++;
        }
        for (int i9 = iA - 1; i9 >= 0 && this.f21414a[i9] == i6; i9--) {
            if (kotlin.jvm.internal.o.c(obj, this.f21415b[i9 << 1])) {
                return i9;
            }
        }
        return ~i8;
    }

    public final void clear() {
        if (this.f21416c > 0) {
            this.f21414a = AbstractC2628a.f21780a;
            this.f21415b = AbstractC2628a.f21782c;
            this.f21416c = 0;
        }
        if (this.f21416c > 0) {
            throw new ConcurrentModificationException();
        }
    }

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

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

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

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        try {
            if (obj instanceof d0) {
                int i6 = this.f21416c;
                if (i6 != ((d0) obj).f21416c) {
                    return false;
                }
                d0 d0Var = (d0) obj;
                for (int i7 = 0; i7 < i6; i7++) {
                    Object objG = g(i7);
                    Object objJ = j(i7);
                    Object obj2 = d0Var.get(objG);
                    if (objJ == null) {
                        if (obj2 != null || !d0Var.containsKey(objG)) {
                            return false;
                        }
                    } else if (!objJ.equals(obj2)) {
                        return false;
                    }
                }
                return true;
            }
            if (!(obj instanceof Map) || this.f21416c != ((Map) obj).size()) {
                return false;
            }
            int i8 = this.f21416c;
            for (int i9 = 0; i9 < i8; i9++) {
                Object objG2 = g(i9);
                Object objJ2 = j(i9);
                Object obj3 = ((Map) obj).get(objG2);
                if (objJ2 == null) {
                    if (obj3 != null || !((Map) obj).containsKey(objG2)) {
                        return false;
                    }
                } else if (!objJ2.equals(obj3)) {
                    return false;
                }
            }
            return true;
        } catch (ClassCastException | NullPointerException unused) {
        }
        return false;
    }

    public final int f() {
        int i6 = this.f21416c;
        if (i6 == 0) {
            return -1;
        }
        int iA = AbstractC2628a.a(i6, 0, this.f21414a);
        if (iA < 0 || this.f21415b[iA << 1] == null) {
            return iA;
        }
        int i7 = iA + 1;
        while (i7 < i6 && this.f21414a[i7] == 0) {
            if (this.f21415b[i7 << 1] == null) {
                return i7;
            }
            i7++;
        }
        for (int i8 = iA - 1; i8 >= 0 && this.f21414a[i8] == 0; i8--) {
            if (this.f21415b[i8 << 1] == null) {
                return i8;
            }
        }
        return ~i7;
    }

    public final Object g(int i6) {
        boolean z6 = false;
        if (i6 >= 0 && i6 < this.f21416c) {
            z6 = true;
        }
        if (z6) {
            return this.f21415b[i6 << 1];
        }
        AbstractC2628a.c("Expected index to be within 0..size()-1, but was " + i6);
        throw null;
    }

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

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

    public final Object h(int i6) {
        if (!(i6 >= 0 && i6 < this.f21416c)) {
            AbstractC2628a.c("Expected index to be within 0..size()-1, but was " + i6);
            throw null;
        }
        Object[] objArr = this.f21415b;
        int i7 = i6 << 1;
        Object obj = objArr[i7 + 1];
        int i8 = this.f21416c;
        if (i8 <= 1) {
            clear();
            return obj;
        }
        int i9 = i8 - 1;
        int[] iArr = this.f21414a;
        if (iArr.length <= 8 || i8 >= iArr.length / 3) {
            if (i6 < i9) {
                int i10 = i6 + 1;
                AbstractC3250p.x(i6, i10, i8, iArr, iArr);
                Object[] objArr2 = this.f21415b;
                AbstractC3250p.B(objArr2, i7, objArr2, i10 << 1, i8 << 1);
            }
            Object[] objArr3 = this.f21415b;
            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);
            kotlin.jvm.internal.o.g(iArrCopyOf, "copyOf(...)");
            this.f21414a = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f21415b, i12 << 1);
            kotlin.jvm.internal.o.g(objArrCopyOf, "copyOf(...)");
            this.f21415b = objArrCopyOf;
            if (i8 != this.f21416c) {
                throw new ConcurrentModificationException();
            }
            if (i6 > 0) {
                AbstractC3250p.x(0, 0, i6, iArr, this.f21414a);
                AbstractC3250p.B(objArr, 0, this.f21415b, 0, i7);
            }
            if (i6 < i9) {
                int i13 = i6 + 1;
                AbstractC3250p.x(i6, i13, i8, iArr, this.f21414a);
                AbstractC3250p.B(objArr, i7, this.f21415b, i13 << 1, i8 << 1);
            }
        }
        if (i8 != this.f21416c) {
            throw new ConcurrentModificationException();
        }
        this.f21416c = i9;
        return obj;
    }

    public final int hashCode() {
        int[] iArr = this.f21414a;
        Object[] objArr = this.f21415b;
        int i6 = this.f21416c;
        int i7 = 1;
        int i8 = 0;
        int iHashCode = 0;
        while (i8 < i6) {
            Object obj = objArr[i7];
            iHashCode += (obj != null ? obj.hashCode() : 0) ^ iArr[i8];
            i8++;
            i7 += 2;
        }
        return iHashCode;
    }

    public final Object i(int i6, Object obj) {
        boolean z6 = false;
        if (i6 >= 0 && i6 < this.f21416c) {
            z6 = true;
        }
        if (!z6) {
            AbstractC2628a.c("Expected index to be within 0..size()-1, but was " + i6);
            throw null;
        }
        int i7 = (i6 << 1) + 1;
        Object[] objArr = this.f21415b;
        Object obj2 = objArr[i7];
        objArr[i7] = obj;
        return obj2;
    }

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

    public final Object j(int i6) {
        boolean z6 = false;
        if (i6 >= 0 && i6 < this.f21416c) {
            z6 = true;
        }
        if (z6) {
            return this.f21415b[(i6 << 1) + 1];
        }
        AbstractC2628a.c("Expected index to be within 0..size()-1, but was " + i6);
        throw null;
    }

    public final Object put(Object obj, Object obj2) {
        int i6 = this.f21416c;
        int iHashCode = obj != null ? obj.hashCode() : 0;
        int iC = obj != null ? c(iHashCode, obj) : f();
        if (iC >= 0) {
            int i7 = (iC << 1) + 1;
            Object[] objArr = this.f21415b;
            Object obj3 = objArr[i7];
            objArr[i7] = obj2;
            return obj3;
        }
        int i8 = ~iC;
        int[] iArr = this.f21414a;
        if (i6 >= iArr.length) {
            int i9 = 8;
            if (i6 >= 8) {
                i9 = (i6 >> 1) + i6;
            } else if (i6 < 4) {
                i9 = 4;
            }
            int[] iArrCopyOf = Arrays.copyOf(iArr, i9);
            kotlin.jvm.internal.o.g(iArrCopyOf, "copyOf(...)");
            this.f21414a = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f21415b, i9 << 1);
            kotlin.jvm.internal.o.g(objArrCopyOf, "copyOf(...)");
            this.f21415b = objArrCopyOf;
            if (i6 != this.f21416c) {
                throw new ConcurrentModificationException();
            }
        }
        if (i8 < i6) {
            int[] iArr2 = this.f21414a;
            int i10 = i8 + 1;
            AbstractC3250p.x(i10, i8, i6, iArr2, iArr2);
            Object[] objArr2 = this.f21415b;
            AbstractC3250p.B(objArr2, i10 << 1, objArr2, i8 << 1, this.f21416c << 1);
        }
        int i11 = this.f21416c;
        if (i6 == i11) {
            int[] iArr3 = this.f21414a;
            if (i8 < iArr3.length) {
                iArr3[i8] = iHashCode;
                Object[] objArr3 = this.f21415b;
                int i12 = i8 << 1;
                objArr3[i12] = obj;
                objArr3[i12 + 1] = obj2;
                this.f21416c = 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 iD = d(obj);
        if (iD >= 0) {
            return h(iD);
        }
        return null;
    }

    public final Object replace(Object obj, Object obj2) {
        int iD = d(obj);
        if (iD >= 0) {
            return i(iD, obj2);
        }
        return null;
    }

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

    public final String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f21416c * 28);
        sb.append('{');
        int i6 = this.f21416c;
        for (int i7 = 0; i7 < i6; i7++) {
            if (i7 > 0) {
                sb.append(", ");
            }
            Object objG = g(i7);
            if (objG != sb) {
                sb.append(objG);
            } else {
                sb.append("(this Map)");
            }
            sb.append('=');
            Object objJ = j(i7);
            if (objJ != sb) {
                sb.append(objJ);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        kotlin.jvm.internal.o.g(string, "toString(...)");
        return string;
    }

    public final boolean remove(Object obj, Object obj2) {
        int iD = d(obj);
        if (iD < 0 || !kotlin.jvm.internal.o.c(obj2, j(iD))) {
            return false;
        }
        h(iD);
        return true;
    }

    public final boolean replace(Object obj, Object obj2, Object obj3) {
        int iD = d(obj);
        if (iD < 0 || !kotlin.jvm.internal.o.c(obj2, j(iD))) {
            return false;
        }
        i(iD, obj3);
        return true;
    }
}
