package r;

import e4.AbstractC0564h;
import java.util.Arrays;
import p0.AbstractC0928a;
import r4.AbstractC0983h;
import s.AbstractC0996a;

/* JADX INFO: renamed from: r.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0968g implements Cloneable {

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

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

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

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

    public C0968g() {
        int i;
        int i5 = 4;
        while (true) {
            i = 80;
            if (i5 >= 32) {
                break;
            }
            int i6 = (1 << i5) - 12;
            if (80 <= i6) {
                i = i6;
                break;
            }
            i5++;
        }
        int i7 = i / 8;
        this.f9604l = new long[i7];
        this.f9605m = new Object[i7];
    }

    public final void a() {
        int i = this.f9606n;
        Object[] objArr = this.f9605m;
        for (int i5 = 0; i5 < i; i5++) {
            objArr[i5] = null;
        }
        this.f9606n = 0;
        this.f9603k = false;
    }

    public final Object b(long j5) {
        Object obj;
        int iB = AbstractC0996a.b(this.f9604l, this.f9606n, j5);
        if (iB < 0 || (obj = this.f9605m[iB]) == AbstractC0969h.f9607a) {
            return null;
        }
        return obj;
    }

    public final long c(int i) {
        int i5;
        if (i < 0 || i >= (i5 = this.f9606n)) {
            throw new IllegalArgumentException(AbstractC0928a.i(i, "Expected index to be within 0..size()-1, but was ").toString());
        }
        if (this.f9603k) {
            long[] jArr = this.f9604l;
            Object[] objArr = this.f9605m;
            int i6 = 0;
            for (int i7 = 0; i7 < i5; i7++) {
                Object obj = objArr[i7];
                if (obj != AbstractC0969h.f9607a) {
                    if (i7 != i6) {
                        jArr[i6] = jArr[i7];
                        objArr[i6] = obj;
                        objArr[i7] = null;
                    }
                    i6++;
                }
            }
            this.f9603k = false;
            this.f9606n = i6;
        }
        return this.f9604l[i];
    }

    public final Object clone() throws CloneNotSupportedException {
        Object objClone = super.clone();
        AbstractC0983h.c("null cannot be cast to non-null type androidx.collection.LongSparseArray<E of androidx.collection.LongSparseArray>", objClone);
        C0968g c0968g = (C0968g) objClone;
        c0968g.f9604l = (long[]) this.f9604l.clone();
        c0968g.f9605m = (Object[]) this.f9605m.clone();
        return c0968g;
    }

    public final void d(Object obj, long j5) {
        int iB = AbstractC0996a.b(this.f9604l, this.f9606n, j5);
        if (iB >= 0) {
            this.f9605m[iB] = obj;
            return;
        }
        int i = ~iB;
        int i5 = this.f9606n;
        Object obj2 = AbstractC0969h.f9607a;
        if (i < i5) {
            Object[] objArr = this.f9605m;
            if (objArr[i] == obj2) {
                this.f9604l[i] = j5;
                objArr[i] = obj;
                return;
            }
        }
        if (this.f9603k) {
            long[] jArr = this.f9604l;
            if (i5 >= jArr.length) {
                Object[] objArr2 = this.f9605m;
                int i6 = 0;
                for (int i7 = 0; i7 < i5; i7++) {
                    Object obj3 = objArr2[i7];
                    if (obj3 != obj2) {
                        if (i7 != i6) {
                            jArr[i6] = jArr[i7];
                            objArr2[i6] = obj3;
                            objArr2[i7] = null;
                        }
                        i6++;
                    }
                }
                this.f9603k = false;
                this.f9606n = i6;
                i = ~AbstractC0996a.b(this.f9604l, i6, j5);
            }
        }
        int i8 = this.f9606n;
        if (i8 >= this.f9604l.length) {
            int i9 = (i8 + 1) * 8;
            int i10 = 4;
            while (true) {
                if (i10 >= 32) {
                    break;
                }
                int i11 = (1 << i10) - 12;
                if (i9 <= i11) {
                    i9 = i11;
                    break;
                }
                i10++;
            }
            int i12 = i9 / 8;
            long[] jArrCopyOf = Arrays.copyOf(this.f9604l, i12);
            AbstractC0983h.d("copyOf(this, newSize)", jArrCopyOf);
            this.f9604l = jArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f9605m, i12);
            AbstractC0983h.d("copyOf(this, newSize)", objArrCopyOf);
            this.f9605m = objArrCopyOf;
        }
        int i13 = this.f9606n - i;
        if (i13 != 0) {
            long[] jArr2 = this.f9604l;
            int i14 = i + 1;
            AbstractC0983h.e("<this>", jArr2);
            System.arraycopy(jArr2, i, jArr2, i14, i13);
            Object[] objArr3 = this.f9605m;
            AbstractC0564h.O(i14, i, this.f9606n, objArr3, objArr3);
        }
        this.f9604l[i] = j5;
        this.f9605m[i] = obj;
        this.f9606n++;
    }

    public final int e() {
        if (this.f9603k) {
            int i = this.f9606n;
            long[] jArr = this.f9604l;
            Object[] objArr = this.f9605m;
            int i5 = 0;
            for (int i6 = 0; i6 < i; i6++) {
                Object obj = objArr[i6];
                if (obj != AbstractC0969h.f9607a) {
                    if (i6 != i5) {
                        jArr[i5] = jArr[i6];
                        objArr[i5] = obj;
                        objArr[i6] = null;
                    }
                    i5++;
                }
            }
            this.f9603k = false;
            this.f9606n = i5;
        }
        return this.f9606n;
    }

    public final Object f(int i) {
        int i5;
        if (i < 0 || i >= (i5 = this.f9606n)) {
            throw new IllegalArgumentException(AbstractC0928a.i(i, "Expected index to be within 0..size()-1, but was ").toString());
        }
        if (this.f9603k) {
            long[] jArr = this.f9604l;
            Object[] objArr = this.f9605m;
            int i6 = 0;
            for (int i7 = 0; i7 < i5; i7++) {
                Object obj = objArr[i7];
                if (obj != AbstractC0969h.f9607a) {
                    if (i7 != i6) {
                        jArr[i6] = jArr[i7];
                        objArr[i6] = obj;
                        objArr[i7] = null;
                    }
                    i6++;
                }
            }
            this.f9603k = false;
            this.f9606n = i6;
        }
        return this.f9605m[i];
    }

    public final String toString() {
        if (e() <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f9606n * 28);
        sb.append('{');
        int i = this.f9606n;
        for (int i5 = 0; i5 < i; i5++) {
            if (i5 > 0) {
                sb.append(", ");
            }
            sb.append(c(i5));
            sb.append('=');
            Object objF = f(i5);
            if (objF != sb) {
                sb.append(objF);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        AbstractC0983h.d("StringBuilder(capacity).…builderAction).toString()", string);
        return string;
    }
}
