package r;

import e4.AbstractC0564h;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Map;
import p0.AbstractC0928a;
import r4.AbstractC0983h;
import s.AbstractC0996a;

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

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

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

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

    public j(int i) {
        this.f9616k = i == 0 ? AbstractC0996a.f9770a : new int[i];
        this.f9617l = i == 0 ? AbstractC0996a.f9771b : new Object[i << 1];
    }

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

    public final void b(int i) {
        int i5 = this.f9618m;
        int[] iArr = this.f9616k;
        if (iArr.length < i) {
            int[] iArrCopyOf = Arrays.copyOf(iArr, i);
            AbstractC0983h.d("copyOf(this, newSize)", iArrCopyOf);
            this.f9616k = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f9617l, i * 2);
            AbstractC0983h.d("copyOf(this, newSize)", objArrCopyOf);
            this.f9617l = objArrCopyOf;
        }
        if (this.f9618m != i5) {
            throw new ConcurrentModificationException();
        }
    }

    public final int c(int i, Object obj) {
        int i5 = this.f9618m;
        if (i5 == 0) {
            return -1;
        }
        int iA = AbstractC0996a.a(i5, i, this.f9616k);
        if (iA < 0 || AbstractC0983h.a(obj, this.f9617l[iA << 1])) {
            return iA;
        }
        int i6 = iA + 1;
        while (i6 < i5 && this.f9616k[i6] == i) {
            if (AbstractC0983h.a(obj, this.f9617l[i6 << 1])) {
                return i6;
            }
            i6++;
        }
        for (int i7 = iA - 1; i7 >= 0 && this.f9616k[i7] == i; i7--) {
            if (AbstractC0983h.a(obj, this.f9617l[i7 << 1])) {
                return i7;
            }
        }
        return ~i6;
    }

    public final void clear() {
        if (this.f9618m > 0) {
            this.f9616k = AbstractC0996a.f9770a;
            this.f9617l = AbstractC0996a.f9771b;
            this.f9618m = 0;
        }
        if (this.f9618m > 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 ? e() : c(obj.hashCode(), obj);
    }

    public final int e() {
        int i = this.f9618m;
        if (i == 0) {
            return -1;
        }
        int iA = AbstractC0996a.a(i, 0, this.f9616k);
        if (iA < 0 || this.f9617l[iA << 1] == null) {
            return iA;
        }
        int i5 = iA + 1;
        while (i5 < i && this.f9616k[i5] == 0) {
            if (this.f9617l[i5 << 1] == null) {
                return i5;
            }
            i5++;
        }
        for (int i6 = iA - 1; i6 >= 0 && this.f9616k[i6] == 0; i6--) {
            if (this.f9617l[i6 << 1] == null) {
                return i6;
            }
        }
        return ~i5;
    }

    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        try {
            if (obj instanceof j) {
                int i = this.f9618m;
                if (i != ((j) obj).f9618m) {
                    return false;
                }
                j jVar = (j) obj;
                for (int i5 = 0; i5 < i; i5++) {
                    Object objF = f(i5);
                    Object objI = i(i5);
                    Object obj2 = jVar.get(objF);
                    if (objI == null) {
                        if (obj2 != null || !jVar.containsKey(objF)) {
                            return false;
                        }
                    } else if (!objI.equals(obj2)) {
                        return false;
                    }
                }
                return true;
            }
            if (!(obj instanceof Map) || this.f9618m != ((Map) obj).size()) {
                return false;
            }
            int i6 = this.f9618m;
            for (int i7 = 0; i7 < i6; i7++) {
                Object objF2 = f(i7);
                Object objI2 = i(i7);
                Object obj3 = ((Map) obj).get(objF2);
                if (objI2 == null) {
                    if (obj3 != null || !((Map) obj).containsKey(objF2)) {
                        return false;
                    }
                } else if (!objI2.equals(obj3)) {
                    return false;
                }
            }
            return true;
        } catch (ClassCastException | NullPointerException unused) {
        }
        return false;
    }

    public final Object f(int i) {
        if (i < 0 || i >= this.f9618m) {
            throw new IllegalArgumentException(AbstractC0928a.i(i, "Expected index to be within 0..size()-1, but was ").toString());
        }
        return this.f9617l[i << 1];
    }

    public final Object g(int i) {
        int i5;
        if (i < 0 || i >= (i5 = this.f9618m)) {
            throw new IllegalArgumentException(AbstractC0928a.i(i, "Expected index to be within 0..size()-1, but was ").toString());
        }
        Object[] objArr = this.f9617l;
        int i6 = i << 1;
        Object obj = objArr[i6 + 1];
        if (i5 <= 1) {
            clear();
            return obj;
        }
        int i7 = i5 - 1;
        int[] iArr = this.f9616k;
        if (iArr.length <= 8 || i5 >= iArr.length / 3) {
            if (i < i7) {
                int i8 = i + 1;
                AbstractC0564h.N(i, i8, i5, iArr, iArr);
                Object[] objArr2 = this.f9617l;
                AbstractC0564h.O(i6, i8 << 1, i5 << 1, objArr2, objArr2);
            }
            Object[] objArr3 = this.f9617l;
            int i9 = i7 << 1;
            objArr3[i9] = null;
            objArr3[i9 + 1] = null;
        } else {
            int i10 = i5 > 8 ? i5 + (i5 >> 1) : 8;
            int[] iArrCopyOf = Arrays.copyOf(iArr, i10);
            AbstractC0983h.d("copyOf(this, newSize)", iArrCopyOf);
            this.f9616k = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f9617l, i10 << 1);
            AbstractC0983h.d("copyOf(this, newSize)", objArrCopyOf);
            this.f9617l = objArrCopyOf;
            if (i5 != this.f9618m) {
                throw new ConcurrentModificationException();
            }
            if (i > 0) {
                AbstractC0564h.N(0, 0, i, iArr, this.f9616k);
                AbstractC0564h.O(0, 0, i6, objArr, this.f9617l);
            }
            if (i < i7) {
                int i11 = i + 1;
                AbstractC0564h.N(i, i11, i5, iArr, this.f9616k);
                AbstractC0564h.O(i6, i11 << 1, i5 << 1, objArr, this.f9617l);
            }
        }
        if (i5 != this.f9618m) {
            throw new ConcurrentModificationException();
        }
        this.f9618m = i7;
        return obj;
    }

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

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

    public final Object h(int i, Object obj) {
        if (i < 0 || i >= this.f9618m) {
            throw new IllegalArgumentException(AbstractC0928a.i(i, "Expected index to be within 0..size()-1, but was ").toString());
        }
        int i5 = (i << 1) + 1;
        Object[] objArr = this.f9617l;
        Object obj2 = objArr[i5];
        objArr[i5] = obj;
        return obj2;
    }

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

    public final Object i(int i) {
        if (i < 0 || i >= this.f9618m) {
            throw new IllegalArgumentException(AbstractC0928a.i(i, "Expected index to be within 0..size()-1, but was ").toString());
        }
        return this.f9617l[(i << 1) + 1];
    }

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

    public final Object put(Object obj, Object obj2) {
        int i = this.f9618m;
        int iHashCode = obj != null ? obj.hashCode() : 0;
        int iC = obj != null ? c(iHashCode, obj) : e();
        if (iC >= 0) {
            int i5 = (iC << 1) + 1;
            Object[] objArr = this.f9617l;
            Object obj3 = objArr[i5];
            objArr[i5] = obj2;
            return obj3;
        }
        int i6 = ~iC;
        int[] iArr = this.f9616k;
        if (i >= iArr.length) {
            int i7 = 8;
            if (i >= 8) {
                i7 = (i >> 1) + i;
            } else if (i < 4) {
                i7 = 4;
            }
            int[] iArrCopyOf = Arrays.copyOf(iArr, i7);
            AbstractC0983h.d("copyOf(this, newSize)", iArrCopyOf);
            this.f9616k = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f9617l, i7 << 1);
            AbstractC0983h.d("copyOf(this, newSize)", objArrCopyOf);
            this.f9617l = objArrCopyOf;
            if (i != this.f9618m) {
                throw new ConcurrentModificationException();
            }
        }
        if (i6 < i) {
            int[] iArr2 = this.f9616k;
            int i8 = i6 + 1;
            AbstractC0564h.N(i8, i6, i, iArr2, iArr2);
            Object[] objArr2 = this.f9617l;
            AbstractC0564h.O(i8 << 1, i6 << 1, this.f9618m << 1, objArr2, objArr2);
        }
        int i9 = this.f9618m;
        if (i == i9) {
            int[] iArr3 = this.f9616k;
            if (i6 < iArr3.length) {
                iArr3[i6] = iHashCode;
                Object[] objArr3 = this.f9617l;
                int i10 = i6 << 1;
                objArr3[i10] = obj;
                objArr3[i10 + 1] = obj2;
                this.f9618m = i9 + 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 g(iD);
        }
        return null;
    }

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

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

    public final String toString() {
        if (isEmpty()) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f9618m * 28);
        sb.append('{');
        int i = this.f9618m;
        for (int i5 = 0; i5 < i; i5++) {
            if (i5 > 0) {
                sb.append(", ");
            }
            Object objF = f(i5);
            if (objF != sb) {
                sb.append(objF);
            } else {
                sb.append("(this Map)");
            }
            sb.append('=');
            Object objI = i(i5);
            if (objI != sb) {
                sb.append(objI);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        AbstractC0983h.d("StringBuilder(capacity).…builderAction).toString()", string);
        return string;
    }

    public final boolean remove(Object obj, Object obj2) {
        int iD = d(obj);
        if (iD < 0 || !AbstractC0983h.a(obj2, i(iD))) {
            return false;
        }
        g(iD);
        return true;
    }

    public final boolean replace(Object obj, Object obj2, Object obj3) {
        int iD = d(obj);
        if (iD < 0 || !AbstractC0983h.a(obj2, i(iD))) {
            return false;
        }
        h(iD, obj3);
        return true;
    }
}
