package o;

import com.google.android.gms.common.api.Api;
import java.io.NotSerializableException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.wN, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2803wN implements Map, Serializable, AJ {
    public static final C2803wN y;
    public Object[] l;
    public Object[] m;
    public int[] n;

    /* renamed from: o, reason: collision with root package name */
    public int[] f774o;
    public int p;
    public int q;
    public int r;
    public int s;
    public int t;
    public C2898xN u;
    public C2993yN v;
    public C2898xN w;
    public boolean x;

    static {
        C2803wN c2803wN = new C2803wN(0);
        c2803wN.x = true;
        y = c2803wN;
    }

    public C2803wN() {
        this(8);
    }

    private final Object writeReplace() throws NotSerializableException {
        if (!this.x) {
            throw new NotSerializableException("The map cannot be serialized while it is being built.");
        }
        Q60 q60 = new Q60();
        q60.l = this;
        return q60;
    }

    public final int a(Object obj) {
        c();
        while (true) {
            int iG = g(obj);
            int i = this.p * 2;
            int length = this.f774o.length / 2;
            if (i > length) {
                i = length;
            }
            int i2 = 0;
            while (true) {
                int[] iArr = this.f774o;
                int i3 = iArr[iG];
                if (i3 <= 0) {
                    int i4 = this.q;
                    Object[] objArr = this.l;
                    if (i4 < objArr.length) {
                        int i5 = i4 + 1;
                        this.q = i5;
                        objArr[i4] = obj;
                        this.n[i4] = iG;
                        iArr[iG] = i5;
                        this.t++;
                        this.s++;
                        if (i2 > this.p) {
                            this.p = i2;
                        }
                        return i4;
                    }
                    e(1);
                } else {
                    if (F3.c(this.l[i3 - 1], obj)) {
                        return -i3;
                    }
                    i2++;
                    if (i2 > i) {
                        h(this.f774o.length * 2);
                        break;
                    }
                    iG = iG == 0 ? this.f774o.length - 1 : iG - 1;
                }
            }
        }
    }

    public final C2803wN b() {
        c();
        this.x = true;
        return this.t > 0 ? this : y;
    }

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

    @Override // java.util.Map
    public final void clear() {
        c();
        int i = this.q - 1;
        if (i >= 0) {
            int i2 = 0;
            while (true) {
                int[] iArr = this.n;
                int i3 = iArr[i2];
                if (i3 >= 0) {
                    this.f774o[i3] = 0;
                    iArr[i2] = -1;
                }
                if (i2 == i) {
                    break;
                } else {
                    i2++;
                }
            }
        }
        AbstractC0249Jp.c0(this.l, 0, this.q);
        Object[] objArr = this.m;
        if (objArr != null) {
            AbstractC0249Jp.c0(objArr, 0, this.q);
        }
        this.t = 0;
        this.q = 0;
        this.s++;
    }

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

    @Override // java.util.Map
    public final boolean containsValue(Object obj) {
        int i;
        int i2 = this.q;
        while (true) {
            i = -1;
            i2--;
            if (i2 >= 0) {
                if (this.n[i2] >= 0 && F3.c(this.m[i2], obj)) {
                    i = i2;
                    break;
                }
            } else {
                break;
            }
        }
        return i >= 0;
    }

    public final void d(boolean z) {
        int i;
        Object[] objArr = this.m;
        int i2 = 0;
        int i3 = 0;
        while (true) {
            i = this.q;
            if (i2 >= i) {
                break;
            }
            int[] iArr = this.n;
            int i4 = iArr[i2];
            if (i4 >= 0) {
                Object[] objArr2 = this.l;
                objArr2[i3] = objArr2[i2];
                if (objArr != null) {
                    objArr[i3] = objArr[i2];
                }
                if (z) {
                    iArr[i3] = i4;
                    this.f774o[i4] = i3 + 1;
                }
                i3++;
            }
            i2++;
        }
        AbstractC0249Jp.c0(this.l, i3, i);
        if (objArr != null) {
            AbstractC0249Jp.c0(objArr, i3, this.q);
        }
        this.q = i3;
    }

    public final void e(int i) {
        Object[] objArr = this.l;
        int length = objArr.length;
        int i2 = this.q;
        int i3 = length - i2;
        int i4 = i2 - this.t;
        if (i3 < i && i3 + i4 >= i && i4 >= objArr.length / 4) {
            d(true);
            return;
        }
        int i5 = i2 + i;
        if (i5 < 0) {
            throw new OutOfMemoryError();
        }
        if (i5 > objArr.length) {
            int length2 = objArr.length;
            int i6 = length2 + (length2 >> 1);
            if (i6 - i5 < 0) {
                i6 = i5;
            }
            if (i6 - 2147483639 > 0) {
                i6 = i5 > 2147483639 ? Api.BaseClientBuilder.API_PRIORITY_OTHER : 2147483639;
            }
            this.l = Arrays.copyOf(objArr, i6);
            Object[] objArr2 = this.m;
            this.m = objArr2 != null ? Arrays.copyOf(objArr2, i6) : null;
            this.n = Arrays.copyOf(this.n, i6);
            int iHighestOneBit = Integer.highestOneBit((i6 >= 1 ? i6 : 1) * 3);
            if (iHighestOneBit > this.f774o.length) {
                h(iHighestOneBit);
            }
        }
    }

    @Override // java.util.Map
    public final Set entrySet() {
        C2898xN c2898xN = this.w;
        if (c2898xN != null) {
            return c2898xN;
        }
        C2898xN c2898xN2 = new C2898xN(this, 0);
        this.w = c2898xN2;
        return c2898xN2;
    }

    @Override // java.util.Map
    public final boolean equals(Object obj) {
        boolean z;
        if (obj != this) {
            if (obj instanceof Map) {
                Map map = (Map) obj;
                if (this.t == map.size()) {
                    for (Object obj2 : map.entrySet()) {
                        if (obj2 != null) {
                            try {
                                Map.Entry entry = (Map.Entry) obj2;
                                int iF = f(entry.getKey());
                                if (!(iF < 0 ? false : F3.c(this.m[iF], entry.getValue()))) {
                                }
                            } catch (ClassCastException unused) {
                            }
                        }
                        z = false;
                    }
                    z = true;
                    if (z) {
                    }
                }
            }
            return false;
        }
        return true;
    }

    public final int f(Object obj) {
        int iG = g(obj);
        int i = this.p;
        while (true) {
            int i2 = this.f774o[iG];
            if (i2 == 0) {
                return -1;
            }
            if (i2 > 0) {
                int i3 = i2 - 1;
                if (F3.c(this.l[i3], obj)) {
                    return i3;
                }
            }
            i--;
            if (i < 0) {
                return -1;
            }
            iG = iG == 0 ? this.f774o.length - 1 : iG - 1;
        }
    }

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

    @Override // java.util.Map
    public final Object get(Object obj) {
        int iF = f(obj);
        if (iF < 0) {
            return null;
        }
        return this.m[iF];
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0032, code lost:
    
        r3[r0] = r6;
        r5.n[r2] = r0;
        r2 = r6;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void h(int r6) {
        /*
            r5 = this;
            int r0 = r5.s
            int r0 = r0 + 1
            r5.s = r0
            int r0 = r5.q
            int r1 = r5.t
            r2 = 0
            if (r0 <= r1) goto L10
            r5.d(r2)
        L10:
            int[] r0 = new int[r6]
            r5.f774o = r0
            int r6 = java.lang.Integer.numberOfLeadingZeros(r6)
            int r6 = r6 + 1
            r5.r = r6
        L1c:
            int r6 = r5.q
            if (r2 >= r6) goto L50
            int r6 = r2 + 1
            java.lang.Object[] r0 = r5.l
            r0 = r0[r2]
            int r0 = r5.g(r0)
            int r1 = r5.p
        L2c:
            int[] r3 = r5.f774o
            r4 = r3[r0]
            if (r4 != 0) goto L3a
            r3[r0] = r6
            int[] r1 = r5.n
            r1[r2] = r0
            r2 = r6
            goto L1c
        L3a:
            int r1 = r1 + (-1)
            if (r1 < 0) goto L48
            int r4 = r0 + (-1)
            if (r0 != 0) goto L46
            int r0 = r3.length
            int r0 = r0 + (-1)
            goto L2c
        L46:
            r0 = r4
            goto L2c
        L48:
            java.lang.IllegalStateException r6 = new java.lang.IllegalStateException
            java.lang.String r0 = "This cannot happen with fixed magic multiplier and grow-only hash array. Have object hashCodes changed?"
            r6.<init>(r0)
            throw r6
        L50:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C2803wN.h(int):void");
    }

    @Override // java.util.Map
    public final int hashCode() {
        C2518tN c2518tN = new C2518tN(this, 0);
        int i = 0;
        while (c2518tN.hasNext()) {
            int i2 = c2518tN.l;
            C2803wN c2803wN = (C2803wN) c2518tN.f756o;
            if (i2 >= c2803wN.q) {
                throw new NoSuchElementException();
            }
            c2518tN.l = i2 + 1;
            c2518tN.m = i2;
            Object obj = c2803wN.l[i2];
            int iHashCode = obj != null ? obj.hashCode() : 0;
            Object obj2 = c2803wN.m[c2518tN.m];
            int iHashCode2 = obj2 != null ? obj2.hashCode() : 0;
            c2518tN.e();
            i += iHashCode ^ iHashCode2;
        }
        return i;
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x0063 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:33:? A[LOOP:0: B:9:0x001f->B:33:?, LOOP_END, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void i(int r12) {
        /*
            r11 = this;
            java.lang.Object[] r0 = r11.l
            r1 = 0
            r0[r12] = r1
            java.lang.Object[] r0 = r11.m
            if (r0 == 0) goto Lb
            r0[r12] = r1
        Lb:
            int[] r0 = r11.n
            r0 = r0[r12]
            int r1 = r11.p
            int r1 = r1 * 2
            int[] r2 = r11.f774o
            int r2 = r2.length
            int r2 = r2 / 2
            if (r1 <= r2) goto L1b
            r1 = r2
        L1b:
            r2 = 0
            r3 = r1
            r4 = r2
            r1 = r0
        L1f:
            int r5 = r0 + (-1)
            if (r0 != 0) goto L29
            int[] r0 = r11.f774o
            int r0 = r0.length
            int r0 = r0 + (-1)
            goto L2a
        L29:
            r0 = r5
        L2a:
            int r4 = r4 + 1
            int r5 = r11.p
            r6 = -1
            if (r4 <= r5) goto L36
            int[] r0 = r11.f774o
            r0[r1] = r2
            goto L67
        L36:
            int[] r5 = r11.f774o
            r7 = r5[r0]
            if (r7 != 0) goto L3f
            r5[r1] = r2
            goto L67
        L3f:
            if (r7 >= 0) goto L46
            r5[r1] = r6
        L43:
            r1 = r0
            r4 = r2
            goto L60
        L46:
            java.lang.Object[] r5 = r11.l
            int r8 = r7 + (-1)
            r5 = r5[r8]
            int r5 = r11.g(r5)
            int r5 = r5 - r0
            int[] r9 = r11.f774o
            int r10 = r9.length
            int r10 = r10 + (-1)
            r5 = r5 & r10
            if (r5 < r4) goto L60
            r9[r1] = r7
            int[] r4 = r11.n
            r4[r8] = r1
            goto L43
        L60:
            int r3 = r3 + r6
            if (r3 >= 0) goto L1f
            int[] r0 = r11.f774o
            r0[r1] = r6
        L67:
            int[] r0 = r11.n
            r0[r12] = r6
            int r12 = r11.t
            int r12 = r12 + r6
            r11.t = r12
            int r12 = r11.s
            int r12 = r12 + 1
            r11.s = r12
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C2803wN.i(int):void");
    }

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

    @Override // java.util.Map
    public final Set keySet() {
        C2898xN c2898xN = this.u;
        if (c2898xN != null) {
            return c2898xN;
        }
        C2898xN c2898xN2 = new C2898xN(this, 1);
        this.u = c2898xN2;
        return c2898xN2;
    }

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

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

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

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

    public final String toString() {
        StringBuilder sb = new StringBuilder((this.t * 3) + 2);
        sb.append("{");
        int i = 0;
        C2518tN c2518tN = new C2518tN(this, 0);
        while (c2518tN.hasNext()) {
            if (i > 0) {
                sb.append(", ");
            }
            int i2 = c2518tN.l;
            C2803wN c2803wN = (C2803wN) c2518tN.f756o;
            if (i2 >= c2803wN.q) {
                throw new NoSuchElementException();
            }
            c2518tN.l = i2 + 1;
            c2518tN.m = i2;
            Object obj = c2803wN.l[i2];
            if (obj == c2803wN) {
                sb.append("(this Map)");
            } else {
                sb.append(obj);
            }
            sb.append('=');
            Object obj2 = c2803wN.m[c2518tN.m];
            if (obj2 == c2803wN) {
                sb.append("(this Map)");
            } else {
                sb.append(obj2);
            }
            c2518tN.e();
            i++;
        }
        sb.append("}");
        return sb.toString();
    }

    @Override // java.util.Map
    public final Collection values() {
        C2993yN c2993yN = this.v;
        if (c2993yN != null) {
            return c2993yN;
        }
        C2993yN c2993yN2 = new C2993yN(0, this);
        this.v = c2993yN2;
        return c2993yN2;
    }

    public C2803wN(int i) {
        if (i < 0) {
            throw new IllegalArgumentException("capacity must be non-negative.");
        }
        Object[] objArr = new Object[i];
        int[] iArr = new int[i];
        int iHighestOneBit = Integer.highestOneBit((i < 1 ? 1 : i) * 3);
        this.l = objArr;
        this.m = null;
        this.n = iArr;
        this.f774o = new int[iHighestOneBit];
        this.p = 2;
        this.q = 0;
        this.r = Integer.numberOfLeadingZeros(iHighestOneBit) + 1;
    }
}
