package o6;

import N1.C0215p;
import androidx.datastore.preferences.protobuf.C0432j;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;

/* JADX INFO: renamed from: o6.u, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1401u extends AbstractMap implements Serializable {

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final C0215p f15912y = new C0215p(7);

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

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f15916t = 0;

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final Comparator f15913q = f15912y;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final C1400t f15915s = new C1400t();

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public C1400t[] f15914r = new C1400t[16];

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

    public final C1400t a(Object obj, boolean z8) {
        int iCompareTo;
        C1400t c1400t;
        boolean z9;
        C1400t c1400t2;
        C1400t c1400t3;
        C1400t c1400t4;
        C1400t c1400t5;
        C1400t c1400t6;
        C1400t[] c1400tArr = this.f15914r;
        int iHashCode = obj.hashCode();
        int i = iHashCode ^ ((iHashCode >>> 20) ^ (iHashCode >>> 12));
        int i5 = ((i >>> 7) ^ i) ^ (i >>> 4);
        boolean z10 = true;
        int length = i5 & (c1400tArr.length - 1);
        C1400t c1400t7 = c1400tArr[length];
        C0215p c0215p = f15912y;
        C1400t c1400t8 = null;
        Comparator comparator = this.f15913q;
        if (c1400t7 != null) {
            Comparable comparable = comparator == c0215p ? (Comparable) obj : null;
            while (true) {
                Object obj2 = c1400t7.f15908v;
                iCompareTo = comparable != null ? comparable.compareTo(obj2) : comparator.compare(obj, obj2);
                if (iCompareTo == 0) {
                    return c1400t7;
                }
                C1400t c1400t9 = iCompareTo < 0 ? c1400t7.f15904r : c1400t7.f15905s;
                if (c1400t9 == null) {
                    break;
                }
                c1400t7 = c1400t9;
            }
        } else {
            iCompareTo = 0;
        }
        if (!z8) {
            return null;
        }
        C1400t c1400t10 = this.f15915s;
        if (c1400t7 != null) {
            C1400t c1400t11 = c1400t7;
            c1400t = new C1400t(c1400t11, obj, i5, c1400t10, c1400t10.f15907u);
            if (iCompareTo < 0) {
                c1400t11.f15904r = c1400t;
            } else {
                c1400t11.f15905s = c1400t;
            }
            b(c1400t11, true);
        } else {
            if (comparator == c0215p && !(obj instanceof Comparable)) {
                throw new ClassCastException(obj.getClass().getName().concat(" is not Comparable"));
            }
            c1400t = new C1400t(c1400t7, obj, i5, c1400t10, c1400t10.f15907u);
            c1400tArr[length] = c1400t;
        }
        int i8 = this.f15916t;
        this.f15916t = i8 + 1;
        if (i8 > this.f15918v) {
            C1400t[] c1400tArr2 = this.f15914r;
            int length2 = c1400tArr2.length;
            int i9 = length2 * 2;
            C1400t[] c1400tArr3 = new C1400t[i9];
            C0432j c0432j = new C0432j(2, (byte) 0);
            C0432j c0432j2 = new C0432j(2, (byte) 0);
            int i10 = 0;
            while (i10 < length2) {
                C1400t c1400t12 = c1400tArr2[i10];
                if (c1400t12 == null) {
                    z9 = z10;
                    c1400t3 = c1400t8;
                } else {
                    C1400t c1400t13 = c1400t8;
                    for (C1400t c1400t14 = c1400t12; c1400t14 != null; c1400t14 = c1400t14.f15904r) {
                        c1400t14.f15903q = c1400t13;
                        c1400t13 = c1400t14;
                    }
                    int i11 = 0;
                    int i12 = 0;
                    while (true) {
                        if (c1400t13 != null) {
                            z9 = z10;
                            C1400t c1400t15 = c1400t13.f15903q;
                            c1400t13.f15903q = c1400t8;
                            C1400t c1400t16 = c1400t13.f15905s;
                            while (true) {
                                C1400t c1400t17 = c1400t16;
                                c1400t2 = c1400t15;
                                c1400t15 = c1400t17;
                                if (c1400t15 == null) {
                                    break;
                                }
                                c1400t15.f15903q = c1400t2;
                                c1400t16 = c1400t15.f15904r;
                            }
                        } else {
                            C1400t c1400t18 = c1400t13;
                            c1400t13 = c1400t8;
                            c1400t2 = c1400t18;
                            z9 = z10;
                        }
                        if (c1400t13 == null) {
                            break;
                        }
                        if ((c1400t13.f15909w & length2) == 0) {
                            i11++;
                        } else {
                            i12++;
                        }
                        c1400t13 = c1400t2;
                        z10 = z9;
                        c1400t8 = null;
                    }
                    c0432j.f8096b = ((Integer.highestOneBit(i11) * 2) - 1) - i11;
                    c0432j.f8098d = 0;
                    c0432j.f8097c = 0;
                    c1400t3 = null;
                    c0432j.f8099e = null;
                    c0432j2.f8096b = ((Integer.highestOneBit(i12) * 2) - 1) - i12;
                    c0432j2.f8098d = 0;
                    c0432j2.f8097c = 0;
                    c0432j2.f8099e = null;
                    C1400t c1400t19 = null;
                    while (c1400t12 != null) {
                        c1400t12.f15903q = c1400t19;
                        C1400t c1400t20 = c1400t12;
                        c1400t12 = c1400t12.f15904r;
                        c1400t19 = c1400t20;
                    }
                    while (true) {
                        if (c1400t19 != null) {
                            C1400t c1400t21 = c1400t19.f15903q;
                            c1400t19.f15903q = null;
                            C1400t c1400t22 = c1400t19.f15905s;
                            while (true) {
                                C1400t c1400t23 = c1400t22;
                                c1400t4 = c1400t21;
                                c1400t21 = c1400t23;
                                if (c1400t21 == null) {
                                    break;
                                }
                                c1400t21.f15903q = c1400t4;
                                c1400t22 = c1400t21.f15904r;
                            }
                        } else {
                            c1400t4 = c1400t19;
                            c1400t19 = null;
                        }
                        if (c1400t19 == null) {
                            break;
                        }
                        if ((c1400t19.f15909w & length2) == 0) {
                            c0432j.a(c1400t19);
                        } else {
                            c0432j2.a(c1400t19);
                        }
                        c1400t19 = c1400t4;
                    }
                    if (i11 > 0) {
                        c1400t5 = (C1400t) c0432j.f8099e;
                        if (c1400t5.f15903q != null) {
                            throw new IllegalStateException();
                        }
                    } else {
                        c1400t5 = null;
                    }
                    c1400tArr3[i10] = c1400t5;
                    int i13 = i10 + length2;
                    if (i12 > 0) {
                        c1400t6 = (C1400t) c0432j2.f8099e;
                        if (c1400t6.f15903q != null) {
                            throw new IllegalStateException();
                        }
                    } else {
                        c1400t6 = null;
                    }
                    c1400tArr3[i13] = c1400t6;
                }
                i10++;
                c1400t8 = c1400t3;
                z10 = z9;
            }
            this.f15914r = c1400tArr3;
            this.f15918v = (i9 / 4) + (i9 / 2);
        }
        this.f15917u++;
        return c1400t;
    }

    public final void b(C1400t c1400t, boolean z8) {
        while (c1400t != null) {
            C1400t c1400t2 = c1400t.f15904r;
            C1400t c1400t3 = c1400t.f15905s;
            int i = c1400t2 != null ? c1400t2.f15911y : 0;
            int i5 = c1400t3 != null ? c1400t3.f15911y : 0;
            int i8 = i - i5;
            if (i8 == -2) {
                C1400t c1400t4 = c1400t3.f15904r;
                C1400t c1400t5 = c1400t3.f15905s;
                int i9 = (c1400t4 != null ? c1400t4.f15911y : 0) - (c1400t5 != null ? c1400t5.f15911y : 0);
                if (i9 != -1 && (i9 != 0 || z8)) {
                    f(c1400t3);
                }
                e(c1400t);
                if (z8) {
                    return;
                }
            } else if (i8 == 2) {
                C1400t c1400t6 = c1400t2.f15904r;
                C1400t c1400t7 = c1400t2.f15905s;
                int i10 = (c1400t6 != null ? c1400t6.f15911y : 0) - (c1400t7 != null ? c1400t7.f15911y : 0);
                if (i10 != 1 && (i10 != 0 || z8)) {
                    e(c1400t2);
                }
                f(c1400t);
                if (z8) {
                    return;
                }
            } else if (i8 == 0) {
                c1400t.f15911y = i + 1;
                if (z8) {
                    return;
                }
            } else {
                c1400t.f15911y = Math.max(i, i5) + 1;
                if (!z8) {
                    return;
                }
            }
            c1400t = c1400t.f15903q;
        }
    }

    public final void c(C1400t c1400t, boolean z8) {
        C1400t c1400t2;
        C1400t c1400t3;
        int i;
        if (z8) {
            C1400t c1400t4 = c1400t.f15907u;
            c1400t4.f15906t = c1400t.f15906t;
            c1400t.f15906t.f15907u = c1400t4;
            c1400t.f15907u = null;
            c1400t.f15906t = null;
        }
        C1400t c1400t5 = c1400t.f15904r;
        C1400t c1400t6 = c1400t.f15905s;
        C1400t c1400t7 = c1400t.f15903q;
        int i5 = 0;
        if (c1400t5 == null || c1400t6 == null) {
            if (c1400t5 != null) {
                d(c1400t, c1400t5);
                c1400t.f15904r = null;
            } else if (c1400t6 != null) {
                d(c1400t, c1400t6);
                c1400t.f15905s = null;
            } else {
                d(c1400t, null);
            }
            b(c1400t7, false);
            this.f15916t--;
            this.f15917u++;
            return;
        }
        if (c1400t5.f15911y > c1400t6.f15911y) {
            C1400t c1400t8 = c1400t5.f15905s;
            while (true) {
                C1400t c1400t9 = c1400t8;
                c1400t3 = c1400t5;
                c1400t5 = c1400t9;
                if (c1400t5 == null) {
                    break;
                } else {
                    c1400t8 = c1400t5.f15905s;
                }
            }
        } else {
            C1400t c1400t10 = c1400t6.f15904r;
            while (true) {
                c1400t2 = c1400t6;
                c1400t6 = c1400t10;
                if (c1400t6 == null) {
                    break;
                } else {
                    c1400t10 = c1400t6.f15904r;
                }
            }
            c1400t3 = c1400t2;
        }
        c(c1400t3, false);
        C1400t c1400t11 = c1400t.f15904r;
        if (c1400t11 != null) {
            i = c1400t11.f15911y;
            c1400t3.f15904r = c1400t11;
            c1400t11.f15903q = c1400t3;
            c1400t.f15904r = null;
        } else {
            i = 0;
        }
        C1400t c1400t12 = c1400t.f15905s;
        if (c1400t12 != null) {
            i5 = c1400t12.f15911y;
            c1400t3.f15905s = c1400t12;
            c1400t12.f15903q = c1400t3;
            c1400t.f15905s = null;
        }
        c1400t3.f15911y = Math.max(i, i5) + 1;
        d(c1400t, c1400t3);
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final void clear() {
        Arrays.fill(this.f15914r, (Object) null);
        this.f15916t = 0;
        this.f15917u++;
        C1400t c1400t = this.f15915s;
        C1400t c1400t2 = c1400t.f15906t;
        while (c1400t2 != c1400t) {
            C1400t c1400t3 = c1400t2.f15906t;
            c1400t2.f15907u = null;
            c1400t2.f15906t = null;
            c1400t2 = c1400t3;
        }
        c1400t.f15907u = c1400t;
        c1400t.f15906t = c1400t;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final boolean containsKey(Object obj) {
        C1400t c1400tA = null;
        if (obj != null) {
            try {
                c1400tA = a(obj, false);
            } catch (ClassCastException unused) {
            }
        }
        return c1400tA != null;
    }

    public final void d(C1400t c1400t, C1400t c1400t2) {
        C1400t c1400t3 = c1400t.f15903q;
        c1400t.f15903q = null;
        if (c1400t2 != null) {
            c1400t2.f15903q = c1400t3;
        }
        if (c1400t3 == null) {
            this.f15914r[c1400t.f15909w & (r0.length - 1)] = c1400t2;
        } else if (c1400t3.f15904r == c1400t) {
            c1400t3.f15904r = c1400t2;
        } else {
            c1400t3.f15905s = c1400t2;
        }
    }

    public final void e(C1400t c1400t) {
        C1400t c1400t2 = c1400t.f15904r;
        C1400t c1400t3 = c1400t.f15905s;
        C1400t c1400t4 = c1400t3.f15904r;
        C1400t c1400t5 = c1400t3.f15905s;
        c1400t.f15905s = c1400t4;
        if (c1400t4 != null) {
            c1400t4.f15903q = c1400t;
        }
        d(c1400t, c1400t3);
        c1400t3.f15904r = c1400t;
        c1400t.f15903q = c1400t3;
        int iMax = Math.max(c1400t2 != null ? c1400t2.f15911y : 0, c1400t4 != null ? c1400t4.f15911y : 0) + 1;
        c1400t.f15911y = iMax;
        c1400t3.f15911y = Math.max(iMax, c1400t5 != null ? c1400t5.f15911y : 0) + 1;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Set entrySet() {
        C1399s c1399s = this.f15919w;
        if (c1399s != null) {
            return c1399s;
        }
        C1399s c1399s2 = new C1399s(this, 0);
        this.f15919w = c1399s2;
        return c1399s2;
    }

    public final void f(C1400t c1400t) {
        C1400t c1400t2 = c1400t.f15904r;
        C1400t c1400t3 = c1400t.f15905s;
        C1400t c1400t4 = c1400t2.f15904r;
        C1400t c1400t5 = c1400t2.f15905s;
        c1400t.f15904r = c1400t5;
        if (c1400t5 != null) {
            c1400t5.f15903q = c1400t;
        }
        d(c1400t, c1400t2);
        c1400t2.f15905s = c1400t;
        c1400t.f15903q = c1400t2;
        int iMax = Math.max(c1400t3 != null ? c1400t3.f15911y : 0, c1400t5 != null ? c1400t5.f15911y : 0) + 1;
        c1400t.f15911y = iMax;
        c1400t2.f15911y = Math.max(iMax, c1400t4 != null ? c1400t4.f15911y : 0) + 1;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object get(Object obj) {
        C1400t c1400tA;
        if (obj != null) {
            try {
                c1400tA = a(obj, false);
            } catch (ClassCastException unused) {
                c1400tA = null;
            }
        } else {
            c1400tA = null;
        }
        if (c1400tA != null) {
            return c1400tA.f15910x;
        }
        return null;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Set keySet() {
        C1399s c1399s = this.f15920x;
        if (c1399s != null) {
            return c1399s;
        }
        C1399s c1399s2 = new C1399s(this, 1);
        this.f15920x = c1399s2;
        return c1399s2;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object put(Object obj, Object obj2) {
        if (obj == null) {
            throw new NullPointerException("key == null");
        }
        C1400t c1400tA = a(obj, true);
        Object obj3 = c1400tA.f15910x;
        c1400tA.f15910x = obj2;
        return obj3;
    }

    @Override // java.util.AbstractMap, java.util.Map
    public final Object remove(Object obj) {
        C1400t c1400tA;
        if (obj != null) {
            try {
                c1400tA = a(obj, false);
            } catch (ClassCastException unused) {
                c1400tA = null;
            }
        } else {
            c1400tA = null;
        }
        if (c1400tA != null) {
            c(c1400tA, true);
        }
        if (c1400tA != null) {
            return c1400tA.f15910x;
        }
        return null;
    }

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