package androidx.collection;

import com.google.android.gms.measurement.internal.u1;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class l implements Cloneable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public /* synthetic */ boolean f945a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public /* synthetic */ long[] f946b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public /* synthetic */ Object[] f947c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public /* synthetic */ int f948d;

    public l(int i10) {
        if (i10 == 0) {
            this.f946b = t.a.f32766b;
            this.f947c = t.a.f32767c;
            return;
        }
        int i11 = i10 * 8;
        int i12 = 4;
        while (true) {
            if (i12 >= 32) {
                break;
            }
            int i13 = (1 << i12) - 12;
            if (i11 <= i13) {
                i11 = i13;
                break;
            }
            i12++;
        }
        int i14 = i11 / 8;
        this.f946b = new long[i14];
        this.f947c = new Object[i14];
    }

    public final void a() {
        int i10 = this.f948d;
        Object[] objArr = this.f947c;
        for (int i11 = 0; i11 < i10; i11++) {
            objArr[i11] = null;
        }
        this.f948d = 0;
        this.f945a = false;
    }

    /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
    public final l clone() throws CloneNotSupportedException {
        Object objClone = super.clone();
        nb.g.g(objClone, "null cannot be cast to non-null type androidx.collection.LongSparseArray<E of androidx.collection.LongSparseArray>");
        l lVar = (l) objClone;
        lVar.f946b = (long[]) this.f946b.clone();
        lVar.f947c = (Object[]) this.f947c.clone();
        return lVar;
    }

    public final Object c(long j10) {
        Object obj;
        int iB = t.a.b(this.f946b, this.f948d, j10);
        if (iB < 0 || (obj = this.f947c[iB]) == m.f949a) {
            return null;
        }
        return obj;
    }

    public final long d(int i10) {
        int i11;
        if (i10 < 0 || i10 >= (i11 = this.f948d)) {
            throw new IllegalArgumentException(u1.g("Expected index to be within 0..size()-1, but was ", i10).toString());
        }
        if (this.f945a) {
            long[] jArr = this.f946b;
            Object[] objArr = this.f947c;
            int i12 = 0;
            for (int i13 = 0; i13 < i11; i13++) {
                Object obj = objArr[i13];
                if (obj != m.f949a) {
                    if (i13 != i12) {
                        jArr[i12] = jArr[i13];
                        objArr[i12] = obj;
                        objArr[i13] = null;
                    }
                    i12++;
                }
            }
            this.f945a = false;
            this.f948d = i12;
        }
        return this.f946b[i10];
    }

    public final void e(long j10, Object obj) {
        int iB = t.a.b(this.f946b, this.f948d, j10);
        if (iB >= 0) {
            this.f947c[iB] = obj;
            return;
        }
        int i10 = ~iB;
        int i11 = this.f948d;
        if (i10 < i11) {
            Object[] objArr = this.f947c;
            if (objArr[i10] == m.f949a) {
                this.f946b[i10] = j10;
                objArr[i10] = obj;
                return;
            }
        }
        if (this.f945a) {
            long[] jArr = this.f946b;
            if (i11 >= jArr.length) {
                Object[] objArr2 = this.f947c;
                int i12 = 0;
                for (int i13 = 0; i13 < i11; i13++) {
                    Object obj2 = objArr2[i13];
                    if (obj2 != m.f949a) {
                        if (i13 != i12) {
                            jArr[i12] = jArr[i13];
                            objArr2[i12] = obj2;
                            objArr2[i13] = null;
                        }
                        i12++;
                    }
                }
                this.f945a = false;
                this.f948d = i12;
                i10 = ~t.a.b(this.f946b, i12, j10);
            }
        }
        int i14 = this.f948d;
        if (i14 >= this.f946b.length) {
            int i15 = (i14 + 1) * 8;
            int i16 = 4;
            while (true) {
                if (i16 >= 32) {
                    break;
                }
                int i17 = (1 << i16) - 12;
                if (i15 <= i17) {
                    i15 = i17;
                    break;
                }
                i16++;
            }
            int i18 = i15 / 8;
            long[] jArrCopyOf = Arrays.copyOf(this.f946b, i18);
            nb.g.h(jArrCopyOf, "copyOf(this, newSize)");
            this.f946b = jArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f947c, i18);
            nb.g.h(objArrCopyOf, "copyOf(this, newSize)");
            this.f947c = objArrCopyOf;
        }
        int i19 = this.f948d - i10;
        if (i19 != 0) {
            long[] jArr2 = this.f946b;
            int i20 = i10 + 1;
            nb.g.i(jArr2, "<this>");
            System.arraycopy(jArr2, i10, jArr2, i20, i19);
            Object[] objArr3 = this.f947c;
            kotlin.collections.q.R(objArr3, i20, objArr3, i10, this.f948d);
        }
        this.f946b[i10] = j10;
        this.f947c[i10] = obj;
        this.f948d++;
    }

    public final int f() {
        if (this.f945a) {
            int i10 = this.f948d;
            long[] jArr = this.f946b;
            Object[] objArr = this.f947c;
            int i11 = 0;
            for (int i12 = 0; i12 < i10; i12++) {
                Object obj = objArr[i12];
                if (obj != m.f949a) {
                    if (i12 != i11) {
                        jArr[i11] = jArr[i12];
                        objArr[i11] = obj;
                        objArr[i12] = null;
                    }
                    i11++;
                }
            }
            this.f945a = false;
            this.f948d = i11;
        }
        return this.f948d;
    }

    public final Object g(int i10) {
        int i11;
        if (i10 < 0 || i10 >= (i11 = this.f948d)) {
            throw new IllegalArgumentException(u1.g("Expected index to be within 0..size()-1, but was ", i10).toString());
        }
        if (this.f945a) {
            long[] jArr = this.f946b;
            Object[] objArr = this.f947c;
            int i12 = 0;
            for (int i13 = 0; i13 < i11; i13++) {
                Object obj = objArr[i13];
                if (obj != m.f949a) {
                    if (i13 != i12) {
                        jArr[i12] = jArr[i13];
                        objArr[i12] = obj;
                        objArr[i13] = null;
                    }
                    i12++;
                }
            }
            this.f945a = false;
            this.f948d = i12;
        }
        return this.f947c[i10];
    }

    public final String toString() {
        if (f() <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f948d * 28);
        sb.append('{');
        int i10 = this.f948d;
        for (int i11 = 0; i11 < i10; i11++) {
            if (i11 > 0) {
                sb.append(", ");
            }
            sb.append(d(i11));
            sb.append('=');
            Object objG = g(i11);
            if (objG != sb) {
                sb.append(objG);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        nb.g.h(string, "StringBuilder(capacity).…builderAction).toString()");
        return string;
    }

    public l() {
        this(10);
    }
}
