package androidx.collection;

import java.util.Arrays;

/* loaded from: classes.dex */
public class s implements Cloneable {

    /* renamed from: p, reason: collision with root package name */
    public /* synthetic */ boolean f1385p;

    /* renamed from: q, reason: collision with root package name */
    public /* synthetic */ long[] f1386q;

    /* renamed from: r, reason: collision with root package name */
    public /* synthetic */ Object[] f1387r;

    /* renamed from: s, reason: collision with root package name */
    public /* synthetic */ int f1388s;

    public s() {
        this(0, 1, null);
    }

    public void a() {
        int i10 = this.f1388s;
        Object[] objArr = this.f1387r;
        for (int i11 = 0; i11 < i10; i11++) {
            objArr[i11] = null;
        }
        this.f1388s = 0;
        this.f1385p = false;
    }

    /* renamed from: b, reason: merged with bridge method [inline-methods] */
    public s clone() {
        Object clone = super.clone();
        kotlin.jvm.internal.t.e(clone, "null cannot be cast to non-null type androidx.collection.LongSparseArray<E of androidx.collection.LongSparseArray>");
        s sVar = (s) clone;
        sVar.f1386q = (long[]) this.f1386q.clone();
        sVar.f1387r = (Object[]) this.f1387r.clone();
        return sVar;
    }

    public boolean c(long j10) {
        return f(j10) >= 0;
    }

    public Object d(long j10) {
        Object obj;
        int b10 = w.a.b(this.f1386q, this.f1388s, j10);
        if (b10 >= 0) {
            Object obj2 = this.f1387r[b10];
            obj = t.f1390a;
            if (obj2 != obj) {
                return this.f1387r[b10];
            }
        }
        return null;
    }

    public int f(long j10) {
        Object obj;
        if (this.f1385p) {
            int i10 = this.f1388s;
            long[] jArr = this.f1386q;
            Object[] objArr = this.f1387r;
            int i11 = 0;
            for (int i12 = 0; i12 < i10; i12++) {
                Object obj2 = objArr[i12];
                obj = t.f1390a;
                if (obj2 != obj) {
                    if (i12 != i11) {
                        jArr[i11] = jArr[i12];
                        objArr[i11] = obj2;
                        objArr[i12] = null;
                    }
                    i11++;
                }
            }
            this.f1385p = false;
            this.f1388s = i11;
        }
        return w.a.b(this.f1386q, this.f1388s, j10);
    }

    public boolean h() {
        return n() == 0;
    }

    public long i(int i10) {
        Object obj;
        if (!(i10 >= 0 && i10 < this.f1388s)) {
            w.d.a("Expected index to be within 0..size()-1, but was " + i10);
        }
        if (this.f1385p) {
            int i11 = this.f1388s;
            long[] jArr = this.f1386q;
            Object[] objArr = this.f1387r;
            int i12 = 0;
            for (int i13 = 0; i13 < i11; i13++) {
                Object obj2 = objArr[i13];
                obj = t.f1390a;
                if (obj2 != obj) {
                    if (i13 != i12) {
                        jArr[i12] = jArr[i13];
                        objArr[i12] = obj2;
                        objArr[i13] = null;
                    }
                    i12++;
                }
            }
            this.f1385p = false;
            this.f1388s = i12;
        }
        return this.f1386q[i10];
    }

    public void j(long j10, Object obj) {
        Object obj2;
        Object obj3;
        int b10 = w.a.b(this.f1386q, this.f1388s, j10);
        if (b10 >= 0) {
            this.f1387r[b10] = obj;
            return;
        }
        int i10 = ~b10;
        if (i10 < this.f1388s) {
            Object obj4 = this.f1387r[i10];
            obj3 = t.f1390a;
            if (obj4 == obj3) {
                this.f1386q[i10] = j10;
                this.f1387r[i10] = obj;
                return;
            }
        }
        if (this.f1385p) {
            int i11 = this.f1388s;
            long[] jArr = this.f1386q;
            if (i11 >= jArr.length) {
                Object[] objArr = this.f1387r;
                int i12 = 0;
                for (int i13 = 0; i13 < i11; i13++) {
                    Object obj5 = objArr[i13];
                    obj2 = t.f1390a;
                    if (obj5 != obj2) {
                        if (i13 != i12) {
                            jArr[i12] = jArr[i13];
                            objArr[i12] = obj5;
                            objArr[i13] = null;
                        }
                        i12++;
                    }
                }
                this.f1385p = false;
                this.f1388s = i12;
                i10 = ~w.a.b(this.f1386q, i12, j10);
            }
        }
        int i14 = this.f1388s;
        if (i14 >= this.f1386q.length) {
            int f10 = w.a.f(i14 + 1);
            long[] copyOf = Arrays.copyOf(this.f1386q, f10);
            kotlin.jvm.internal.t.f(copyOf, "copyOf(this, newSize)");
            this.f1386q = copyOf;
            Object[] copyOf2 = Arrays.copyOf(this.f1387r, f10);
            kotlin.jvm.internal.t.f(copyOf2, "copyOf(this, newSize)");
            this.f1387r = copyOf2;
        }
        int i15 = this.f1388s;
        if (i15 - i10 != 0) {
            long[] jArr2 = this.f1386q;
            int i16 = i10 + 1;
            sm.o.k(jArr2, jArr2, i16, i10, i15);
            Object[] objArr2 = this.f1387r;
            sm.o.l(objArr2, objArr2, i16, i10, this.f1388s);
        }
        this.f1386q[i10] = j10;
        this.f1387r[i10] = obj;
        this.f1388s++;
    }

    public void k(long j10) {
        Object obj;
        Object obj2;
        int b10 = w.a.b(this.f1386q, this.f1388s, j10);
        if (b10 >= 0) {
            Object obj3 = this.f1387r[b10];
            obj = t.f1390a;
            if (obj3 != obj) {
                Object[] objArr = this.f1387r;
                obj2 = t.f1390a;
                objArr[b10] = obj2;
                this.f1385p = true;
            }
        }
    }

    public void l(int i10) {
        Object obj;
        Object obj2;
        Object obj3 = this.f1387r[i10];
        obj = t.f1390a;
        if (obj3 != obj) {
            Object[] objArr = this.f1387r;
            obj2 = t.f1390a;
            objArr[i10] = obj2;
            this.f1385p = true;
        }
    }

    public int n() {
        Object obj;
        if (this.f1385p) {
            int i10 = this.f1388s;
            long[] jArr = this.f1386q;
            Object[] objArr = this.f1387r;
            int i11 = 0;
            for (int i12 = 0; i12 < i10; i12++) {
                Object obj2 = objArr[i12];
                obj = t.f1390a;
                if (obj2 != obj) {
                    if (i12 != i11) {
                        jArr[i11] = jArr[i12];
                        objArr[i11] = obj2;
                        objArr[i12] = null;
                    }
                    i11++;
                }
            }
            this.f1385p = false;
            this.f1388s = i11;
        }
        return this.f1388s;
    }

    public Object o(int i10) {
        Object obj;
        if (!(i10 >= 0 && i10 < this.f1388s)) {
            w.d.a("Expected index to be within 0..size()-1, but was " + i10);
        }
        if (this.f1385p) {
            int i11 = this.f1388s;
            long[] jArr = this.f1386q;
            Object[] objArr = this.f1387r;
            int i12 = 0;
            for (int i13 = 0; i13 < i11; i13++) {
                Object obj2 = objArr[i13];
                obj = t.f1390a;
                if (obj2 != obj) {
                    if (i13 != i12) {
                        jArr[i12] = jArr[i13];
                        objArr[i12] = obj2;
                        objArr[i13] = null;
                    }
                    i12++;
                }
            }
            this.f1385p = false;
            this.f1388s = i12;
        }
        return this.f1387r[i10];
    }

    public String toString() {
        if (n() <= 0) {
            return "{}";
        }
        StringBuilder sb2 = new StringBuilder(this.f1388s * 28);
        sb2.append('{');
        int i10 = this.f1388s;
        for (int i11 = 0; i11 < i10; i11++) {
            if (i11 > 0) {
                sb2.append(", ");
            }
            sb2.append(i(i11));
            sb2.append('=');
            Object o10 = o(i11);
            if (o10 != sb2) {
                sb2.append(o10);
            } else {
                sb2.append("(this Map)");
            }
        }
        sb2.append('}');
        String sb3 = sb2.toString();
        kotlin.jvm.internal.t.f(sb3, "StringBuilder(capacity).…builderAction).toString()");
        return sb3;
    }

    public s(int i10) {
        if (i10 == 0) {
            this.f1386q = w.a.f40529b;
            this.f1387r = w.a.f40530c;
        } else {
            int f10 = w.a.f(i10);
            this.f1386q = new long[f10];
            this.f1387r = new Object[f10];
        }
    }

    public /* synthetic */ s(int i10, int i11, kotlin.jvm.internal.k kVar) {
        this((i11 & 1) != 0 ? 10 : i10);
    }
}
