package pp;

import java.util.AbstractSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v0;
import sm.p;
import sm.x0;

/* loaded from: classes3.dex */
public final class g extends AbstractSet {

    /* renamed from: r, reason: collision with root package name */
    public static final b f33039r = new b(null);

    /* renamed from: p, reason: collision with root package name */
    private Object f33040p;

    /* renamed from: q, reason: collision with root package name */
    private int f33041q;

    /* loaded from: classes3.dex */
    private static final class a implements Iterator, en.a {

        /* renamed from: p, reason: collision with root package name */
        private final Iterator f33042p;

        public a(Object[] array) {
            t.g(array, "array");
            this.f33042p = kotlin.jvm.internal.c.a(array);
        }

        @Override // java.util.Iterator
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public Void remove() {
            throw new UnsupportedOperationException();
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.f33042p.hasNext();
        }

        @Override // java.util.Iterator
        public Object next() {
            return this.f33042p.next();
        }
    }

    /* loaded from: classes3.dex */
    public static final class b {
        private b() {
        }

        public /* synthetic */ b(k kVar) {
            this();
        }

        public final g a() {
            return new g(null);
        }

        public final g b(Collection set) {
            t.g(set, "set");
            g gVar = new g(null);
            gVar.addAll(set);
            return gVar;
        }
    }

    /* loaded from: classes3.dex */
    private static final class c implements Iterator, en.a {

        /* renamed from: p, reason: collision with root package name */
        private final Object f33043p;

        /* renamed from: q, reason: collision with root package name */
        private boolean f33044q = true;

        public c(Object obj) {
            this.f33043p = obj;
        }

        @Override // java.util.Iterator
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public Void remove() {
            throw new UnsupportedOperationException();
        }

        @Override // java.util.Iterator
        public boolean hasNext() {
            return this.f33044q;
        }

        @Override // java.util.Iterator
        public Object next() {
            if (!this.f33044q) {
                throw new NoSuchElementException();
            }
            this.f33044q = false;
            return this.f33043p;
        }
    }

    public /* synthetic */ g(k kVar) {
        this();
    }

    public static final g e() {
        return f33039r.a();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v10, types: [java.util.AbstractCollection, java.util.LinkedHashSet] */
    @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
    public boolean add(Object obj) {
        boolean N;
        Object[] objArr;
        ?? e10;
        if (size() == 0) {
            this.f33040p = obj;
        } else if (size() == 1) {
            if (t.b(this.f33040p, obj)) {
                return false;
            }
            this.f33040p = new Object[]{this.f33040p, obj};
        } else if (size() < 5) {
            Object obj2 = this.f33040p;
            t.e(obj2, "null cannot be cast to non-null type kotlin.Array<T of org.jetbrains.kotlin.utils.SmartSet>");
            Object[] objArr2 = (Object[]) obj2;
            N = p.N(objArr2, obj);
            if (N) {
                return false;
            }
            if (size() == 4) {
                e10 = x0.e(Arrays.copyOf(objArr2, objArr2.length));
                e10.add(obj);
                objArr = e10;
            } else {
                Object[] copyOf = Arrays.copyOf(objArr2, size() + 1);
                t.f(copyOf, "copyOf(...)");
                copyOf[copyOf.length - 1] = obj;
                objArr = copyOf;
            }
            this.f33040p = objArr;
        } else {
            Object obj3 = this.f33040p;
            t.e(obj3, "null cannot be cast to non-null type kotlin.collections.MutableSet<T of org.jetbrains.kotlin.utils.SmartSet>");
            if (!v0.d(obj3).add(obj)) {
                return false;
            }
        }
        i(size() + 1);
        return true;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
    public void clear() {
        this.f33040p = null;
        i(0);
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
    public boolean contains(Object obj) {
        boolean N;
        if (size() == 0) {
            return false;
        }
        if (size() == 1) {
            return t.b(this.f33040p, obj);
        }
        if (size() >= 5) {
            Object obj2 = this.f33040p;
            t.e(obj2, "null cannot be cast to non-null type kotlin.collections.Set<T of org.jetbrains.kotlin.utils.SmartSet>");
            return ((Set) obj2).contains(obj);
        }
        Object obj3 = this.f33040p;
        t.e(obj3, "null cannot be cast to non-null type kotlin.Array<T of org.jetbrains.kotlin.utils.SmartSet>");
        N = p.N((Object[]) obj3, obj);
        return N;
    }

    public int g() {
        return this.f33041q;
    }

    public void i(int i10) {
        this.f33041q = i10;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
    public Iterator iterator() {
        Iterator aVar;
        if (size() == 0) {
            return Collections.emptySet().iterator();
        }
        if (size() == 1) {
            aVar = new c(this.f33040p);
        } else {
            if (size() >= 5) {
                Object obj = this.f33040p;
                t.e(obj, "null cannot be cast to non-null type kotlin.collections.MutableSet<T of org.jetbrains.kotlin.utils.SmartSet>");
                return v0.d(obj).iterator();
            }
            Object obj2 = this.f33040p;
            t.e(obj2, "null cannot be cast to non-null type kotlin.Array<T of org.jetbrains.kotlin.utils.SmartSet>");
            aVar = new a((Object[]) obj2);
        }
        return aVar;
    }

    @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
    public final /* bridge */ int size() {
        return g();
    }

    private g() {
    }
}
