package C6;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;

/* JADX INFO: loaded from: classes.dex */
public final class g implements Map, Serializable, Q6.c {
    public static final g D;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public i f1394A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public h f1395B;

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public h f1406z;

    static {
        g gVar = new g(0);
        gVar.f1396C = true;
        D = gVar;
    }

    public g() {
        this(8);
    }

    public final int a(Object obj) {
        c();
        while (true) {
            int iJ = j(obj);
            int i = this.f1401u * 2;
            int length = this.f1400t.length / 2;
            if (i > length) {
                i = length;
            }
            int i5 = 0;
            while (true) {
                int[] iArr = this.f1400t;
                int i8 = iArr[iJ];
                if (i8 <= 0) {
                    int i9 = this.f1402v;
                    Object[] objArr = this.f1397q;
                    if (i9 < objArr.length) {
                        int i10 = i9 + 1;
                        this.f1402v = i10;
                        objArr[i9] = obj;
                        this.f1399s[i9] = iJ;
                        iArr[iJ] = i10;
                        this.f1405y++;
                        this.f1404x++;
                        if (i5 > this.f1401u) {
                            this.f1401u = i5;
                        }
                        return i9;
                    }
                    g(1);
                } else {
                    if (P6.g.a(this.f1397q[i8 - 1], obj)) {
                        return -i8;
                    }
                    i5++;
                    if (i5 > i) {
                        k(this.f1400t.length * 2);
                        break;
                    }
                    iJ = iJ == 0 ? this.f1400t.length - 1 : iJ - 1;
                }
            }
        }
    }

    public final g b() {
        c();
        this.f1396C = true;
        if (this.f1405y > 0) {
            return this;
        }
        g gVar = D;
        P6.g.c(gVar, "null cannot be cast to non-null type kotlin.collections.Map<K of kotlin.collections.builders.MapBuilder, V of kotlin.collections.builders.MapBuilder>");
        return gVar;
    }

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

    @Override // java.util.Map
    public final void clear() {
        c();
        int i = this.f1402v - 1;
        if (i >= 0) {
            int i5 = 0;
            while (true) {
                int[] iArr = this.f1399s;
                int i8 = iArr[i5];
                if (i8 >= 0) {
                    this.f1400t[i8] = 0;
                    iArr[i5] = -1;
                }
                if (i5 == i) {
                    break;
                } else {
                    i5++;
                }
            }
        }
        W2.g.F(this.f1397q, 0, this.f1402v);
        Object[] objArr = this.f1398r;
        if (objArr != null) {
            W2.g.F(objArr, 0, this.f1402v);
        }
        this.f1405y = 0;
        this.f1402v = 0;
        this.f1404x++;
    }

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

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

    public final void d(boolean z8) {
        int i;
        Object[] objArr = this.f1398r;
        int i5 = 0;
        int i8 = 0;
        while (true) {
            i = this.f1402v;
            if (i5 >= i) {
                break;
            }
            int[] iArr = this.f1399s;
            int i9 = iArr[i5];
            if (i9 >= 0) {
                Object[] objArr2 = this.f1397q;
                objArr2[i8] = objArr2[i5];
                if (objArr != null) {
                    objArr[i8] = objArr[i5];
                }
                if (z8) {
                    iArr[i8] = i9;
                    this.f1400t[i9] = i8 + 1;
                }
                i8++;
            }
            i5++;
        }
        W2.g.F(this.f1397q, i8, i);
        if (objArr != null) {
            W2.g.F(objArr, i8, this.f1402v);
        }
        this.f1402v = i8;
    }

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

    @Override // java.util.Map
    public final Set entrySet() {
        h hVar = this.f1395B;
        if (hVar != null) {
            return hVar;
        }
        h hVar2 = new h(this, 0);
        this.f1395B = hVar2;
        return hVar2;
    }

    @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.f1405y == map.size() && e(map.entrySet());
    }

    public final boolean f(Map.Entry entry) {
        P6.g.e(entry, "entry");
        int iH = h(entry.getKey());
        if (iH < 0) {
            return false;
        }
        Object[] objArr = this.f1398r;
        P6.g.b(objArr);
        return P6.g.a(objArr[iH], entry.getValue());
    }

    public final void g(int i) {
        Object[] objArrCopyOf;
        Object[] objArr = this.f1397q;
        int length = objArr.length;
        int i5 = this.f1402v;
        int i8 = length - i5;
        int i9 = i5 - this.f1405y;
        if (i8 < i && i8 + i9 >= i && i9 >= objArr.length / 4) {
            d(true);
            return;
        }
        int i10 = i5 + i;
        if (i10 < 0) {
            throw new OutOfMemoryError();
        }
        if (i10 > objArr.length) {
            int length2 = objArr.length;
            int i11 = length2 + (length2 >> 1);
            if (i11 - i10 < 0) {
                i11 = i10;
            }
            if (i11 - 2147483639 > 0) {
                i11 = i10 > 2147483639 ? Integer.MAX_VALUE : 2147483639;
            }
            Object[] objArrCopyOf2 = Arrays.copyOf(objArr, i11);
            P6.g.d(objArrCopyOf2, "copyOf(...)");
            this.f1397q = objArrCopyOf2;
            Object[] objArr2 = this.f1398r;
            if (objArr2 != null) {
                objArrCopyOf = Arrays.copyOf(objArr2, i11);
                P6.g.d(objArrCopyOf, "copyOf(...)");
            } else {
                objArrCopyOf = null;
            }
            this.f1398r = objArrCopyOf;
            int[] iArrCopyOf = Arrays.copyOf(this.f1399s, i11);
            P6.g.d(iArrCopyOf, "copyOf(...)");
            this.f1399s = iArrCopyOf;
            int iHighestOneBit = Integer.highestOneBit((i11 >= 1 ? i11 : 1) * 3);
            if (iHighestOneBit > this.f1400t.length) {
                k(iHighestOneBit);
            }
        }
    }

    @Override // java.util.Map
    public final Object get(Object obj) {
        int iH = h(obj);
        if (iH < 0) {
            return null;
        }
        Object[] objArr = this.f1398r;
        P6.g.b(objArr);
        return objArr[iH];
    }

    public final int h(Object obj) {
        int iJ = j(obj);
        int i = this.f1401u;
        while (true) {
            int i5 = this.f1400t[iJ];
            if (i5 == 0) {
                return -1;
            }
            if (i5 > 0) {
                int i8 = i5 - 1;
                if (P6.g.a(this.f1397q[i8], obj)) {
                    return i8;
                }
            }
            i--;
            if (i < 0) {
                return -1;
            }
            iJ = iJ == 0 ? this.f1400t.length - 1 : iJ - 1;
        }
    }

    @Override // java.util.Map
    public final int hashCode() {
        d dVar = new d(this, 0);
        int i = 0;
        while (dVar.hasNext()) {
            int i5 = dVar.f1390q;
            g gVar = (g) dVar.f1393t;
            if (i5 >= gVar.f1402v) {
                throw new NoSuchElementException();
            }
            dVar.f1390q = i5 + 1;
            dVar.f1391r = i5;
            Object obj = gVar.f1397q[i5];
            int iHashCode = obj != null ? obj.hashCode() : 0;
            Object[] objArr = gVar.f1398r;
            P6.g.b(objArr);
            Object obj2 = objArr[dVar.f1391r];
            int iHashCode2 = obj2 != null ? obj2.hashCode() : 0;
            dVar.e();
            i += iHashCode ^ iHashCode2;
        }
        return i;
    }

    public final int i(Object obj) {
        int i = this.f1402v;
        while (true) {
            i--;
            if (i < 0) {
                return -1;
            }
            if (this.f1399s[i] >= 0) {
                Object[] objArr = this.f1398r;
                P6.g.b(objArr);
                if (P6.g.a(objArr[i], obj)) {
                    return i;
                }
            }
        }
    }

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

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

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0032, code lost:
    
        r3[r0] = r6;
        r5.f1399s[r2] = r0;
        r2 = r6;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void k(int i) {
        this.f1404x++;
        int i5 = 0;
        if (this.f1402v > this.f1405y) {
            d(false);
        }
        this.f1400t = new int[i];
        this.f1403w = Integer.numberOfLeadingZeros(i) + 1;
        while (i5 < this.f1402v) {
            int i8 = i5 + 1;
            int iJ = j(this.f1397q[i5]);
            int i9 = this.f1401u;
            while (true) {
                int[] iArr = this.f1400t;
                if (iArr[iJ] == 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?");
                }
                iJ = iJ == 0 ? iArr.length - 1 : iJ - 1;
            }
        }
    }

    @Override // java.util.Map
    public final Set keySet() {
        h hVar = this.f1406z;
        if (hVar != null) {
            return hVar;
        }
        h hVar2 = new h(this, 1);
        this.f1406z = hVar2;
        return hVar2;
    }

    /* 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 l(int i) {
        Object[] objArr = this.f1397q;
        P6.g.e(objArr, "<this>");
        objArr[i] = null;
        Object[] objArr2 = this.f1398r;
        if (objArr2 != null) {
            objArr2[i] = null;
        }
        int length = this.f1399s[i];
        int i5 = this.f1401u * 2;
        int length2 = this.f1400t.length / 2;
        if (i5 > length2) {
            i5 = length2;
        }
        int i8 = i5;
        int i9 = 0;
        int i10 = length;
        while (true) {
            length = length == 0 ? this.f1400t.length - 1 : length - 1;
            i9++;
            if (i9 > this.f1401u) {
                this.f1400t[i10] = 0;
                break;
            }
            int[] iArr = this.f1400t;
            int i11 = iArr[length];
            if (i11 == 0) {
                iArr[i10] = 0;
                break;
            }
            if (i11 < 0) {
                iArr[i10] = -1;
            } else {
                int i12 = i11 - 1;
                int iJ = j(this.f1397q[i12]) - length;
                int[] iArr2 = this.f1400t;
                if ((iJ & (iArr2.length - 1)) >= i9) {
                    iArr2[i10] = i11;
                    this.f1399s[i12] = i10;
                }
                i8--;
                if (i8 >= 0) {
                    this.f1400t[i10] = -1;
                    break;
                }
            }
            i10 = length;
            i9 = 0;
            i8--;
            if (i8 >= 0) {
            }
        }
        this.f1399s[i] = -1;
        this.f1405y--;
        this.f1404x++;
    }

    @Override // java.util.Map
    public final Object put(Object obj, Object obj2) {
        c();
        int iA = a(obj);
        Object[] objArr = this.f1398r;
        if (objArr == null) {
            int length = this.f1397q.length;
            if (length < 0) {
                throw new IllegalArgumentException("capacity must be non-negative.");
            }
            objArr = new Object[length];
            this.f1398r = 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) {
        P6.g.e(map, "from");
        c();
        Set<Map.Entry> setEntrySet = map.entrySet();
        if (setEntrySet.isEmpty()) {
            return;
        }
        g(setEntrySet.size());
        for (Map.Entry entry : setEntrySet) {
            int iA = a(entry.getKey());
            Object[] objArr = this.f1398r;
            if (objArr == null) {
                int length = this.f1397q.length;
                if (length < 0) {
                    throw new IllegalArgumentException("capacity must be non-negative.");
                }
                objArr = new Object[length];
                this.f1398r = objArr;
            }
            if (iA >= 0) {
                objArr[iA] = entry.getValue();
            } else {
                int i = (-iA) - 1;
                if (!P6.g.a(entry.getValue(), objArr[i])) {
                    objArr[i] = entry.getValue();
                }
            }
        }
    }

    @Override // java.util.Map
    public final Object remove(Object obj) {
        c();
        int iH = h(obj);
        if (iH < 0) {
            return null;
        }
        Object[] objArr = this.f1398r;
        P6.g.b(objArr);
        Object obj2 = objArr[iH];
        l(iH);
        return obj2;
    }

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

    public final String toString() {
        StringBuilder sb = new StringBuilder((this.f1405y * 3) + 2);
        sb.append("{");
        d dVar = new d(this, 0);
        int i = 0;
        while (dVar.hasNext()) {
            if (i > 0) {
                sb.append(", ");
            }
            int i5 = dVar.f1390q;
            g gVar = (g) dVar.f1393t;
            if (i5 >= gVar.f1402v) {
                throw new NoSuchElementException();
            }
            dVar.f1390q = i5 + 1;
            dVar.f1391r = i5;
            Object obj = gVar.f1397q[i5];
            if (obj == gVar) {
                sb.append("(this Map)");
            } else {
                sb.append(obj);
            }
            sb.append('=');
            Object[] objArr = gVar.f1398r;
            P6.g.b(objArr);
            Object obj2 = objArr[dVar.f1391r];
            if (obj2 == gVar) {
                sb.append("(this Map)");
            } else {
                sb.append(obj2);
            }
            dVar.e();
            i++;
        }
        sb.append("}");
        String string = sb.toString();
        P6.g.d(string, "toString(...)");
        return string;
    }

    @Override // java.util.Map
    public final Collection values() {
        i iVar = this.f1394A;
        if (iVar != null) {
            return iVar;
        }
        i iVar2 = new i(this);
        this.f1394A = iVar2;
        return iVar2;
    }

    public g(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.f1397q = objArr;
        this.f1398r = null;
        this.f1399s = iArr;
        this.f1400t = new int[iHighestOneBit];
        this.f1401u = 2;
        this.f1402v = 0;
        this.f1403w = Integer.numberOfLeadingZeros(iHighestOneBit) + 1;
    }
}
