package y4;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import kotlin.jvm.internal.o;
import n2.AbstractC2612c;
import x4.AbstractC3239e;
import x4.C3236b;

/* JADX INFO: renamed from: y4.e, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C3277e implements Map, Serializable, K4.e {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final C3277e f26215q;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f26223k;
    public int l;

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

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public C3279g f26225n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public C3278f f26226o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public boolean f26227p;

    static {
        C3277e c3277e = new C3277e(0);
        c3277e.f26227p = true;
        f26215q = c3277e;
    }

    public C3277e() {
        this(8);
    }

    public final int a(Object obj) {
        c();
        while (true) {
            int iK = k(obj);
            int i6 = this.f26220e * 2;
            int length = this.f26219d.length / 2;
            if (i6 > length) {
                i6 = length;
            }
            int i7 = 0;
            while (true) {
                int[] iArr = this.f26219d;
                int i8 = iArr[iK];
                if (i8 <= 0) {
                    int i9 = this.f26221f;
                    Object[] objArr = this.f26216a;
                    if (i9 < objArr.length) {
                        int i10 = i9 + 1;
                        this.f26221f = i10;
                        objArr[i9] = obj;
                        this.f26218c[i9] = iK;
                        iArr[iK] = i10;
                        this.l++;
                        this.f26223k++;
                        if (i7 > this.f26220e) {
                            this.f26220e = i7;
                        }
                        return i9;
                    }
                    h(1);
                } else {
                    if (o.c(this.f26216a[i8 - 1], obj)) {
                        return -i8;
                    }
                    i7++;
                    if (i7 > i6) {
                        l(this.f26219d.length * 2);
                        break;
                    }
                    iK = iK == 0 ? this.f26219d.length - 1 : iK - 1;
                }
            }
        }
    }

    public final C3277e b() {
        c();
        this.f26227p = true;
        if (this.l > 0) {
            return this;
        }
        C3277e c3277e = f26215q;
        o.f(c3277e, "null cannot be cast to non-null type kotlin.collections.Map<K of kotlin.collections.builders.MapBuilder, V of kotlin.collections.builders.MapBuilder>");
        return c3277e;
    }

    public final void c() {
        if (this.f26227p) {
            throw new UnsupportedOperationException();
        }
    }

    @Override // java.util.Map
    public final void clear() {
        c();
        int i6 = this.f26221f - 1;
        if (i6 >= 0) {
            int i7 = 0;
            while (true) {
                int[] iArr = this.f26218c;
                int i8 = iArr[i7];
                if (i8 >= 0) {
                    this.f26219d[i8] = 0;
                    iArr[i7] = -1;
                }
                if (i7 == i6) {
                    break;
                } else {
                    i7++;
                }
            }
        }
        AbstractC2612c.s(this.f26216a, 0, this.f26221f);
        Object[] objArr = this.f26217b;
        if (objArr != null) {
            AbstractC2612c.s(objArr, 0, this.f26221f);
        }
        this.l = 0;
        this.f26221f = 0;
        this.f26223k++;
    }

    @Override // java.util.Map
    public final boolean containsKey(Object obj) {
        return i(obj) >= 0;
    }

    @Override // java.util.Map
    public final boolean containsValue(Object obj) {
        return j(obj) >= 0;
    }

    public final void d(boolean z6) {
        int i6;
        Object[] objArr = this.f26217b;
        int i7 = 0;
        int i8 = 0;
        while (true) {
            i6 = this.f26221f;
            if (i7 >= i6) {
                break;
            }
            int[] iArr = this.f26218c;
            int i9 = iArr[i7];
            if (i9 >= 0) {
                Object[] objArr2 = this.f26216a;
                objArr2[i8] = objArr2[i7];
                if (objArr != null) {
                    objArr[i8] = objArr[i7];
                }
                if (z6) {
                    iArr[i8] = i9;
                    this.f26219d[i9] = i8 + 1;
                }
                i8++;
            }
            i7++;
        }
        AbstractC2612c.s(this.f26216a, i8, i6);
        if (objArr != null) {
            AbstractC2612c.s(objArr, i8, this.f26221f);
        }
        this.f26221f = i8;
    }

    @Override // java.util.Map
    public final Set entrySet() {
        C3278f c3278f = this.f26226o;
        if (c3278f != null) {
            return c3278f;
        }
        C3278f c3278f2 = new C3278f(this, 0);
        this.f26226o = c3278f2;
        return c3278f2;
    }

    @Override // java.util.Map
    public final boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof Map)) {
            return false;
        }
        Map map = (Map) obj;
        return this.l == map.size() && f(map.entrySet());
    }

    public final boolean f(Collection m6) {
        o.h(m6, "m");
        for (Object obj : m6) {
            if (obj != null) {
                try {
                    if (!g((Map.Entry) obj)) {
                    }
                } catch (ClassCastException unused) {
                }
            }
            return false;
        }
        return true;
    }

    public final boolean g(Map.Entry entry) {
        o.h(entry, "entry");
        int i6 = i(entry.getKey());
        if (i6 < 0) {
            return false;
        }
        Object[] objArr = this.f26217b;
        o.e(objArr);
        return o.c(objArr[i6], entry.getValue());
    }

    @Override // java.util.Map
    public final Object get(Object obj) {
        int i6 = i(obj);
        if (i6 < 0) {
            return null;
        }
        Object[] objArr = this.f26217b;
        o.e(objArr);
        return objArr[i6];
    }

    public final void h(int i6) {
        Object[] objArrCopyOf;
        Object[] objArr = this.f26216a;
        int length = objArr.length;
        int i7 = this.f26221f;
        int i8 = length - i7;
        int i9 = i7 - this.l;
        if (i8 < i6 && i8 + i9 >= i6 && i9 >= objArr.length / 4) {
            d(true);
            return;
        }
        int i10 = i7 + i6;
        if (i10 < 0) {
            throw new OutOfMemoryError();
        }
        if (i10 > objArr.length) {
            C3236b c3236b = AbstractC3239e.Companion;
            int length2 = objArr.length;
            c3236b.getClass();
            int iE = C3236b.e(length2, i10);
            Object[] objArr2 = this.f26216a;
            o.h(objArr2, "<this>");
            Object[] objArrCopyOf2 = Arrays.copyOf(objArr2, iE);
            o.g(objArrCopyOf2, "copyOf(...)");
            this.f26216a = objArrCopyOf2;
            Object[] objArr3 = this.f26217b;
            if (objArr3 != null) {
                objArrCopyOf = Arrays.copyOf(objArr3, iE);
                o.g(objArrCopyOf, "copyOf(...)");
            } else {
                objArrCopyOf = null;
            }
            this.f26217b = objArrCopyOf;
            int[] iArrCopyOf = Arrays.copyOf(this.f26218c, iE);
            o.g(iArrCopyOf, "copyOf(...)");
            this.f26218c = iArrCopyOf;
            int iHighestOneBit = Integer.highestOneBit((iE >= 1 ? iE : 1) * 3);
            if (iHighestOneBit > this.f26219d.length) {
                l(iHighestOneBit);
            }
        }
    }

    @Override // java.util.Map
    public final int hashCode() {
        C3275c c3275c = new C3275c(this, 0);
        int i6 = 0;
        while (c3275c.hasNext()) {
            int i7 = c3275c.f6861a;
            C3277e c3277e = (C3277e) c3275c.f6864d;
            if (i7 >= c3277e.f26221f) {
                throw new NoSuchElementException();
            }
            c3275c.f6861a = i7 + 1;
            c3275c.f6862b = i7;
            Object obj = c3277e.f26216a[i7];
            int iHashCode = obj != null ? obj.hashCode() : 0;
            Object[] objArr = c3277e.f26217b;
            o.e(objArr);
            Object obj2 = objArr[c3275c.f6862b];
            int iHashCode2 = obj2 != null ? obj2.hashCode() : 0;
            c3275c.c();
            i6 += iHashCode ^ iHashCode2;
        }
        return i6;
    }

    public final int i(Object obj) {
        int iK = k(obj);
        int i6 = this.f26220e;
        while (true) {
            int i7 = this.f26219d[iK];
            if (i7 == 0) {
                return -1;
            }
            if (i7 > 0) {
                int i8 = i7 - 1;
                if (o.c(this.f26216a[i8], obj)) {
                    return i8;
                }
            }
            i6--;
            if (i6 < 0) {
                return -1;
            }
            iK = iK == 0 ? this.f26219d.length - 1 : iK - 1;
        }
    }

    @Override // java.util.Map
    public final boolean isEmpty() {
        return this.l == 0;
    }

    public final int j(Object obj) {
        int i6 = this.f26221f;
        while (true) {
            i6--;
            if (i6 < 0) {
                return -1;
            }
            if (this.f26218c[i6] >= 0) {
                Object[] objArr = this.f26217b;
                o.e(objArr);
                if (o.c(objArr[i6], obj)) {
                    return i6;
                }
            }
        }
    }

    public final int k(Object obj) {
        return ((obj != null ? obj.hashCode() : 0) * (-1640531527)) >>> this.f26222j;
    }

    @Override // java.util.Map
    public final Set keySet() {
        C3278f c3278f = this.f26224m;
        if (c3278f != null) {
            return c3278f;
        }
        C3278f c3278f2 = new C3278f(this, 1);
        this.f26224m = c3278f2;
        return c3278f2;
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0032, code lost:
    
        r3[r0] = r6;
        r5.f26218c[r2] = r0;
        r2 = r6;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void l(int i6) {
        this.f26223k++;
        int i7 = 0;
        if (this.f26221f > this.l) {
            d(false);
        }
        this.f26219d = new int[i6];
        this.f26222j = Integer.numberOfLeadingZeros(i6) + 1;
        while (i7 < this.f26221f) {
            int i8 = i7 + 1;
            int iK = k(this.f26216a[i7]);
            int i9 = this.f26220e;
            while (true) {
                int[] iArr = this.f26219d;
                if (iArr[iK] == 0) {
                    break;
                }
                i9--;
                if (i9 < 0) {
                    throw new IllegalStateException("This cannot happen with fixed magic multiplier and grow-only hash array. Have object hashCodes changed?");
                }
                iK = iK == 0 ? iArr.length - 1 : iK - 1;
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x0068 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:33:? A[LOOP:0: B:9:0x0024->B:33:?, LOOP_END, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m(int i6) {
        Object[] objArr = this.f26216a;
        o.h(objArr, "<this>");
        objArr[i6] = null;
        Object[] objArr2 = this.f26217b;
        if (objArr2 != null) {
            objArr2[i6] = null;
        }
        int length = this.f26218c[i6];
        int i7 = this.f26220e * 2;
        int length2 = this.f26219d.length / 2;
        if (i7 > length2) {
            i7 = length2;
        }
        int i8 = i7;
        int i9 = 0;
        int i10 = length;
        while (true) {
            length = length == 0 ? this.f26219d.length - 1 : length - 1;
            i9++;
            if (i9 > this.f26220e) {
                this.f26219d[i10] = 0;
                break;
            }
            int[] iArr = this.f26219d;
            int i11 = iArr[length];
            if (i11 == 0) {
                iArr[i10] = 0;
                break;
            }
            if (i11 < 0) {
                iArr[i10] = -1;
            } else {
                int i12 = i11 - 1;
                int iK = k(this.f26216a[i12]) - length;
                int[] iArr2 = this.f26219d;
                if ((iK & (iArr2.length - 1)) >= i9) {
                    iArr2[i10] = i11;
                    this.f26218c[i12] = i10;
                }
                i8--;
                if (i8 >= 0) {
                    this.f26219d[i10] = -1;
                    break;
                }
            }
            i10 = length;
            i9 = 0;
            i8--;
            if (i8 >= 0) {
            }
        }
        this.f26218c[i6] = -1;
        this.l--;
        this.f26223k++;
    }

    @Override // java.util.Map
    public final Object put(Object obj, Object obj2) {
        c();
        int iA = a(obj);
        Object[] objArr = this.f26217b;
        if (objArr == null) {
            int length = this.f26216a.length;
            if (length < 0) {
                throw new IllegalArgumentException("capacity must be non-negative.");
            }
            objArr = new Object[length];
            this.f26217b = objArr;
        }
        if (iA >= 0) {
            objArr[iA] = obj2;
            return null;
        }
        int i6 = (-iA) - 1;
        Object obj3 = objArr[i6];
        objArr[i6] = obj2;
        return obj3;
    }

    @Override // java.util.Map
    public final void putAll(Map from) {
        o.h(from, "from");
        c();
        Set<Map.Entry> setEntrySet = from.entrySet();
        if (setEntrySet.isEmpty()) {
            return;
        }
        h(setEntrySet.size());
        for (Map.Entry entry : setEntrySet) {
            int iA = a(entry.getKey());
            Object[] objArr = this.f26217b;
            if (objArr == null) {
                int length = this.f26216a.length;
                if (length < 0) {
                    throw new IllegalArgumentException("capacity must be non-negative.");
                }
                objArr = new Object[length];
                this.f26217b = objArr;
            }
            if (iA >= 0) {
                objArr[iA] = entry.getValue();
            } else {
                int i6 = (-iA) - 1;
                if (!o.c(entry.getValue(), objArr[i6])) {
                    objArr[i6] = entry.getValue();
                }
            }
        }
    }

    @Override // java.util.Map
    public final Object remove(Object obj) {
        c();
        int i6 = i(obj);
        if (i6 < 0) {
            return null;
        }
        Object[] objArr = this.f26217b;
        o.e(objArr);
        Object obj2 = objArr[i6];
        m(i6);
        return obj2;
    }

    @Override // java.util.Map
    public final int size() {
        return this.l;
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder((this.l * 3) + 2);
        sb.append("{");
        C3275c c3275c = new C3275c(this, 0);
        int i6 = 0;
        while (c3275c.hasNext()) {
            if (i6 > 0) {
                sb.append(", ");
            }
            int i7 = c3275c.f6861a;
            C3277e c3277e = (C3277e) c3275c.f6864d;
            if (i7 >= c3277e.f26221f) {
                throw new NoSuchElementException();
            }
            c3275c.f6861a = i7 + 1;
            c3275c.f6862b = i7;
            Object obj = c3277e.f26216a[i7];
            if (obj == c3277e) {
                sb.append("(this Map)");
            } else {
                sb.append(obj);
            }
            sb.append('=');
            Object[] objArr = c3277e.f26217b;
            o.e(objArr);
            Object obj2 = objArr[c3275c.f6862b];
            if (obj2 == c3277e) {
                sb.append("(this Map)");
            } else {
                sb.append(obj2);
            }
            c3275c.c();
            i6++;
        }
        sb.append("}");
        String string = sb.toString();
        o.g(string, "toString(...)");
        return string;
    }

    @Override // java.util.Map
    public final Collection values() {
        C3279g c3279g = this.f26225n;
        if (c3279g != null) {
            return c3279g;
        }
        C3279g c3279g2 = new C3279g(this);
        this.f26225n = c3279g2;
        return c3279g2;
    }

    public C3277e(int i6) {
        if (i6 < 0) {
            throw new IllegalArgumentException("capacity must be non-negative.");
        }
        Object[] objArr = new Object[i6];
        int[] iArr = new int[i6];
        int iHighestOneBit = Integer.highestOneBit((i6 < 1 ? 1 : i6) * 3);
        this.f26216a = objArr;
        this.f26217b = null;
        this.f26218c = iArr;
        this.f26219d = new int[iHighestOneBit];
        this.f26220e = 2;
        this.f26221f = 0;
        this.f26222j = Integer.numberOfLeadingZeros(iHighestOneBit) + 1;
    }
}
