package F3;

import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;

/* JADX INFO: loaded from: classes3.dex */
public abstract class Z extends J implements Set {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final /* synthetic */ int f1526c = 0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public transient O f1527b;

    public static int n(int i6) {
        int iMax = Math.max(i6, 2);
        if (iMax >= 751619276) {
            A4.g.l(iMax < 1073741824, "collection too large");
            return 1073741824;
        }
        int iHighestOneBit = Integer.highestOneBit(iMax - 1) << 1;
        while (((double) iHighestOneBit) * 0.7d < iMax) {
            iHighestOneBit <<= 1;
        }
        return iHighestOneBit;
    }

    public static Z o(int i6, Object... objArr) {
        if (i6 == 0) {
            return v0.f1615m;
        }
        if (i6 == 1) {
            Object obj = objArr[0];
            Objects.requireNonNull(obj);
            return new B0(obj);
        }
        int iN = n(i6);
        Object[] objArr2 = new Object[iN];
        int i7 = iN - 1;
        int i8 = 0;
        int i9 = 0;
        for (int i10 = 0; i10 < i6; i10++) {
            Object obj2 = objArr[i10];
            if (obj2 == null) {
                throw new NullPointerException(Z0.o.l("at index ", i10));
            }
            int iHashCode = obj2.hashCode();
            int iS = AbstractC0220u.s(iHashCode);
            while (true) {
                int i11 = iS & i7;
                Object obj3 = objArr2[i11];
                if (obj3 == null) {
                    objArr[i9] = obj2;
                    objArr2[i11] = obj2;
                    i8 += iHashCode;
                    i9++;
                    break;
                }
                if (obj3.equals(obj2)) {
                    break;
                }
                iS++;
            }
        }
        Arrays.fill(objArr, i9, i6, (Object) null);
        if (i9 == 1) {
            Object obj4 = objArr[0];
            Objects.requireNonNull(obj4);
            return new B0(obj4);
        }
        if (n(i9) < iN / 2) {
            return o(i9, objArr);
        }
        int length = objArr.length;
        if (i9 < (length >> 1) + (length >> 2)) {
            objArr = Arrays.copyOf(objArr, i9);
        }
        return new v0(objArr, i8, objArr2, i7, i9);
    }

    public static Z p(Collection collection) {
        if ((collection instanceof Z) && !(collection instanceof SortedSet)) {
            Z z6 = (Z) collection;
            if (!z6.l()) {
                return z6;
            }
        }
        Object[] array = collection.toArray();
        return o(array.length, array);
    }

    @Override // F3.J
    public O e() {
        O o6 = this.f1527b;
        if (o6 != null) {
            return o6;
        }
        O oQ = q();
        this.f1527b = oQ;
        return oQ;
    }

    @Override // java.util.Collection, java.util.Set
    public final boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if ((obj instanceof Z) && (this instanceof v0)) {
            Z z6 = (Z) obj;
            z6.getClass();
            if ((z6 instanceof v0) && hashCode() != obj.hashCode()) {
                return false;
            }
        }
        return AbstractC0220u.h(this, obj);
    }

    @Override // java.util.Collection, java.util.Set
    public int hashCode() {
        return AbstractC0220u.m(this);
    }

    public O q() {
        Object[] array = toArray(J.f1502a);
        M m6 = O.f1509b;
        return O.n(array.length, array);
    }
}
