package defpackage;

import defpackage.ui4;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;

/* JADX INFO: loaded from: classes2.dex */
@az3
@li2
public abstract class ck4<E> extends ui4<E> implements Set<E> {
    public static final /* synthetic */ int c = 0;
    public transient bj4 b;

    public static class a<E> extends ui4.a<E> {
        public Object[] d;
        public int e;

        public a() {
            super(4);
        }

        @Override // ui4.a
        /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] and merged with bridge method [inline-methods] */
        public a c(Object obj) {
            obj.getClass();
            if (this.d != null) {
                int i = ck4.i(this.b);
                Object[] objArr = this.d;
                if (i <= objArr.length) {
                    Objects.requireNonNull(objArr);
                    int length = this.d.length - 1;
                    int iHashCode = obj.hashCode();
                    int iB = v04.b(iHashCode);
                    while (true) {
                        int i2 = iB & length;
                        Object[] objArr2 = this.d;
                        Object obj2 = objArr2[i2];
                        if (obj2 == null) {
                            objArr2[i2] = obj;
                            this.e += iHashCode;
                            super.c(obj);
                            return this;
                        }
                        if (obj2.equals(obj)) {
                            return this;
                        }
                        iB = i2 + 1;
                    }
                }
            }
            this.d = null;
            super.c(obj);
            return this;
        }

        public a i(Object... objArr) {
            if (this.d == null) {
                d(objArr.length, objArr);
                return this;
            }
            for (Object obj : objArr) {
                a(obj);
            }
            return this;
        }

        public a j(Iterable iterable) {
            iterable.getClass();
            if (this.d == null) {
                e(iterable);
                return this;
            }
            Iterator it = iterable.iterator();
            while (it.hasNext()) {
                a(it.next());
            }
            return this;
        }

        public ck4 k() {
            ck4 ck4VarJ;
            int i = this.b;
            if (i == 0) {
                int i2 = ck4.c;
                return rx7.l;
            }
            if (i == 1) {
                Object obj = this.a[0];
                Objects.requireNonNull(obj);
                int i3 = ck4.c;
                return new kv8(obj);
            }
            if (this.d == null || ck4.i(i) != this.d.length) {
                ck4VarJ = ck4.j(this.b, this.a);
                this.b = ck4VarJ.size();
            } else {
                int i4 = this.b;
                Object[] objArrCopyOf = this.a;
                int length = objArrCopyOf.length;
                if (i4 < (length >> 1) + (length >> 2)) {
                    objArrCopyOf = Arrays.copyOf(objArrCopyOf, i4);
                }
                ck4VarJ = new rx7(objArrCopyOf, this.e, this.d, r6.length - 1, this.b);
            }
            this.c = true;
            this.d = null;
            return ck4VarJ;
        }

        public a l(a aVar) {
            if (this.d == null) {
                d(aVar.b, aVar.a);
                return this;
            }
            for (int i = 0; i < aVar.b; i++) {
                Object obj = aVar.a[i];
                Objects.requireNonNull(obj);
                a(obj);
            }
            return this;
        }
    }

    @sw4
    public static class b implements Serializable {
    }

    public static a h() {
        return new a(4);
    }

    public static int i(int i) {
        int iMax = Math.max(i, 2);
        if (iMax >= 751619276) {
            if7.f(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 ck4 j(int i, Object... objArr) {
        if (i == 0) {
            return rx7.l;
        }
        if (i == 1) {
            Object obj = objArr[0];
            Objects.requireNonNull(obj);
            return new kv8(obj);
        }
        int i2 = i(i);
        Object[] objArr2 = new Object[i2];
        int i3 = i2 - 1;
        int i4 = 0;
        int i5 = 0;
        for (int i6 = 0; i6 < i; i6++) {
            Object obj2 = objArr[i6];
            if (obj2 == null) {
                throw new NullPointerException(n41.k("at index ", i6));
            }
            int iHashCode = obj2.hashCode();
            int iB = v04.b(iHashCode);
            while (true) {
                int i7 = iB & i3;
                Object obj3 = objArr2[i7];
                if (obj3 == null) {
                    objArr[i5] = obj2;
                    objArr2[i7] = obj2;
                    i4 += iHashCode;
                    i5++;
                    break;
                }
                if (obj3.equals(obj2)) {
                    break;
                }
                iB++;
            }
        }
        Arrays.fill(objArr, i5, i, (Object) null);
        if (i5 == 1) {
            Object obj4 = objArr[0];
            Objects.requireNonNull(obj4);
            return new kv8(obj4);
        }
        if (i(i5) < i2 / 2) {
            return j(i5, objArr);
        }
        int length = objArr.length;
        if (i5 < (length >> 1) + (length >> 2)) {
            objArr = Arrays.copyOf(objArr, i5);
        }
        return new rx7(objArr, i4, objArr2, i3, i5);
    }

    public static ck4 k(Collection collection) {
        if ((collection instanceof ck4) && !(collection instanceof SortedSet)) {
            ck4 ck4Var = (ck4) collection;
            if (!ck4Var.f()) {
                return ck4Var;
            }
        }
        Object[] array = collection.toArray();
        return j(array.length, array);
    }

    public static ck4 l(Object[] objArr) {
        int length = objArr.length;
        return length != 0 ? length != 1 ? j(objArr.length, (Object[]) objArr.clone()) : new kv8(objArr[0]) : rx7.l;
    }

    public static ck4 p() {
        return rx7.l;
    }

    public static ck4 q(Integer num) {
        return new kv8(num);
    }

    public static ck4 r(String str, String str2, String str3, String str4, String str5, String str6, Object... objArr) {
        if7.f(objArr.length <= 2147483641, "the total number of elements must fit in an int");
        int length = objArr.length + 6;
        Object[] objArr2 = new Object[length];
        objArr2[0] = str;
        objArr2[1] = str2;
        objArr2[2] = str3;
        objArr2[3] = str4;
        objArr2[4] = str5;
        objArr2[5] = str6;
        System.arraycopy(objArr, 0, objArr2, 6, objArr.length);
        return j(length, objArr2);
    }

    @Override // defpackage.ui4
    public bj4 a() {
        bj4 bj4Var = this.b;
        if (bj4Var != null) {
            return bj4Var;
        }
        bj4 bj4VarM = m();
        this.b = bj4VarM;
        return bj4VarM;
    }

    @Override // java.util.Collection, java.util.Set
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if ((obj instanceof ck4) && o() && ((ck4) obj).o() && hashCode() != obj.hashCode()) {
            return false;
        }
        return hm8.b(this, obj);
    }

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

    @Override // defpackage.ui4, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.List
    public /* bridge */ /* synthetic */ Iterator iterator() {
        return iterator();
    }

    public bj4 m() {
        Object[] array = toArray();
        t7a t7aVar = bj4.b;
        return bj4.h(array.length, array);
    }

    public boolean o() {
        return this instanceof zj2;
    }
}
