package r;

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

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

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

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

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

    public k() {
        int i;
        int i5 = 4;
        while (true) {
            i = 40;
            if (i5 >= 32) {
                break;
            }
            int i6 = (1 << i5) - 12;
            if (40 <= i6) {
                i = i6;
                break;
            }
            i5++;
        }
        int i7 = i / 4;
        this.f9619k = new int[i7];
        this.f9620l = new Object[i7];
    }

    public final void a(int i, Object obj) {
        int i5 = this.f9621m;
        if (i5 != 0 && i <= this.f9619k[i5 - 1]) {
            c(i, obj);
            return;
        }
        if (i5 >= this.f9619k.length) {
            int i6 = (i5 + 1) * 4;
            int i7 = 4;
            while (true) {
                if (i7 >= 32) {
                    break;
                }
                int i8 = (1 << i7) - 12;
                if (i6 <= i8) {
                    i6 = i8;
                    break;
                }
                i7++;
            }
            int i9 = i6 / 4;
            int[] iArrCopyOf = Arrays.copyOf(this.f9619k, i9);
            AbstractC0983h.d("copyOf(this, newSize)", iArrCopyOf);
            this.f9619k = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f9620l, i9);
            AbstractC0983h.d("copyOf(this, newSize)", objArrCopyOf);
            this.f9620l = objArrCopyOf;
        }
        this.f9619k[i5] = i;
        this.f9620l[i5] = obj;
        this.f9621m = i5 + 1;
    }

    public final Object b(int i) {
        Object obj;
        int iA = AbstractC0996a.a(this.f9621m, i, this.f9619k);
        if (iA < 0 || (obj = this.f9620l[iA]) == AbstractC0969h.f9608b) {
            return null;
        }
        return obj;
    }

    public final void c(int i, Object obj) {
        int iA = AbstractC0996a.a(this.f9621m, i, this.f9619k);
        if (iA >= 0) {
            this.f9620l[iA] = obj;
            return;
        }
        int i5 = ~iA;
        int i6 = this.f9621m;
        if (i5 < i6) {
            Object[] objArr = this.f9620l;
            if (objArr[i5] == AbstractC0969h.f9608b) {
                this.f9619k[i5] = i;
                objArr[i5] = obj;
                return;
            }
        }
        if (i6 >= this.f9619k.length) {
            int i7 = (i6 + 1) * 4;
            int i8 = 4;
            while (true) {
                if (i8 >= 32) {
                    break;
                }
                int i9 = (1 << i8) - 12;
                if (i7 <= i9) {
                    i7 = i9;
                    break;
                }
                i8++;
            }
            int i10 = i7 / 4;
            int[] iArrCopyOf = Arrays.copyOf(this.f9619k, i10);
            AbstractC0983h.d("copyOf(this, newSize)", iArrCopyOf);
            this.f9619k = iArrCopyOf;
            Object[] objArrCopyOf = Arrays.copyOf(this.f9620l, i10);
            AbstractC0983h.d("copyOf(this, newSize)", objArrCopyOf);
            this.f9620l = objArrCopyOf;
        }
        int i11 = this.f9621m;
        if (i11 - i5 != 0) {
            int[] iArr = this.f9619k;
            int i12 = i5 + 1;
            AbstractC0564h.N(i12, i5, i11, iArr, iArr);
            Object[] objArr2 = this.f9620l;
            AbstractC0564h.O(i12, i5, this.f9621m, objArr2, objArr2);
        }
        this.f9619k[i5] = i;
        this.f9620l[i5] = obj;
        this.f9621m++;
    }

    public final Object clone() throws CloneNotSupportedException {
        Object objClone = super.clone();
        AbstractC0983h.c("null cannot be cast to non-null type androidx.collection.SparseArrayCompat<E of androidx.collection.SparseArrayCompat>", objClone);
        k kVar = (k) objClone;
        kVar.f9619k = (int[]) this.f9619k.clone();
        kVar.f9620l = (Object[]) this.f9620l.clone();
        return kVar;
    }

    public final String toString() {
        int i = this.f9621m;
        if (i <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(i * 28);
        sb.append('{');
        int i5 = this.f9621m;
        for (int i6 = 0; i6 < i5; i6++) {
            if (i6 > 0) {
                sb.append(", ");
            }
            sb.append(this.f9619k[i6]);
            sb.append('=');
            Object obj = this.f9620l[i6];
            if (obj != this) {
                sb.append(obj);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        String string = sb.toString();
        AbstractC0983h.d("buffer.toString()", string);
        return string;
    }
}
