package androidx.collection;

import java.util.Arrays;

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

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

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

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

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

    public t() {
        int i10;
        int i11 = 4;
        while (true) {
            i10 = 40;
            if (i11 >= 32) {
                break;
            }
            int i12 = (1 << i11) - 12;
            if (40 <= i12) {
                i10 = i12;
                break;
            }
            i11++;
        }
        int i13 = i10 / 4;
        this.f970b = new int[i13];
        this.f971c = new Object[i13];
    }

    public final void a(int i10, Object obj) {
        int i11 = this.f972d;
        if (i11 != 0 && i10 <= this.f970b[i11 - 1]) {
            d(i10, obj);
            return;
        }
        if (this.f969a && i11 >= this.f970b.length) {
            u.a(this);
        }
        int i12 = this.f972d;
        if (i12 >= this.f970b.length) {
            int i13 = (i12 + 1) * 4;
            int i14 = 4;
            while (true) {
                if (i14 >= 32) {
                    break;
                }
                int i15 = (1 << i14) - 12;
                if (i13 <= i15) {
                    i13 = i15;
                    break;
                }
                i14++;
            }
            int i16 = i13 / 4;
            int[] iArrCopyOf = Arrays.copyOf(this.f970b, i16);
            nb.g.h(iArrCopyOf, "copyOf(this, newSize)");
            this.f970b = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f971c, i16);
            nb.g.h(objArrCopyOf, "copyOf(this, newSize)");
            this.f971c = objArrCopyOf;
        }
        this.f970b[i12] = i10;
        this.f971c[i12] = obj;
        this.f972d = i12 + 1;
    }

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

    public final Object c(int i10) {
        Object obj;
        Object obj2 = u.f973a;
        int iA = t.a.a(this.f972d, i10, this.f970b);
        if (iA < 0 || (obj = this.f971c[iA]) == u.f973a) {
            return null;
        }
        return obj;
    }

    public final void d(int i10, Object obj) {
        int iA = t.a.a(this.f972d, i10, this.f970b);
        if (iA >= 0) {
            this.f971c[iA] = obj;
            return;
        }
        int i11 = ~iA;
        int i12 = this.f972d;
        if (i11 < i12) {
            Object[] objArr = this.f971c;
            if (objArr[i11] == u.f973a) {
                this.f970b[i11] = i10;
                objArr[i11] = obj;
                return;
            }
        }
        if (this.f969a && i12 >= this.f970b.length) {
            u.a(this);
            i11 = ~t.a.a(this.f972d, i10, this.f970b);
        }
        int i13 = this.f972d;
        if (i13 >= this.f970b.length) {
            int i14 = (i13 + 1) * 4;
            int i15 = 4;
            while (true) {
                if (i15 >= 32) {
                    break;
                }
                int i16 = (1 << i15) - 12;
                if (i14 <= i16) {
                    i14 = i16;
                    break;
                }
                i15++;
            }
            int i17 = i14 / 4;
            int[] iArrCopyOf = Arrays.copyOf(this.f970b, i17);
            nb.g.h(iArrCopyOf, "copyOf(this, newSize)");
            this.f970b = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f971c, i17);
            nb.g.h(objArrCopyOf, "copyOf(this, newSize)");
            this.f971c = objArrCopyOf;
        }
        int i18 = this.f972d;
        if (i18 - i11 != 0) {
            int[] iArr = this.f970b;
            int i19 = i11 + 1;
            kotlin.collections.q.P(i19, i11, iArr, iArr, i18);
            Object[] objArr2 = this.f971c;
            kotlin.collections.q.R(objArr2, i19, objArr2, i11, this.f972d);
        }
        this.f970b[i11] = i10;
        this.f971c[i11] = obj;
        this.f972d++;
    }

    public final int e() {
        if (this.f969a) {
            u.a(this);
        }
        return this.f972d;
    }

    public final Object f(int i10) {
        if (this.f969a) {
            u.a(this);
        }
        return this.f971c[i10];
    }

    public final String toString() {
        if (e() <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f972d * 28);
        sb.append('{');
        int i10 = this.f972d;
        for (int i11 = 0; i11 < i10; i11++) {
            if (i11 > 0) {
                sb.append(", ");
            }
            if (this.f969a) {
                u.a(this);
            }
            sb.append(this.f970b[i11]);
            sb.append('=');
            Object objF = f(i11);
            if (objF != this) {
                sb.append(objF);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        nb.g.h(string, "buffer.toString()");
        return string;
    }
}
