package j;

/* JADX INFO: compiled from: LongSparseArray.java */
/* JADX INFO: loaded from: classes.dex */
public class d<E> implements Cloneable {

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private static final Object f4879i = new Object();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private boolean f4880e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private long[] f4881f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private Object[] f4882g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private int f4883h;

    public d() {
        this(10);
    }

    private void d() {
        int i3 = this.f4883h;
        long[] jArr = this.f4881f;
        Object[] objArr = this.f4882g;
        int i4 = 0;
        for (int i5 = 0; i5 < i3; i5++) {
            Object obj = objArr[i5];
            if (obj != f4879i) {
                if (i5 != i4) {
                    jArr[i4] = jArr[i5];
                    objArr[i4] = obj;
                    objArr[i5] = null;
                }
                i4++;
            }
        }
        this.f4880e = false;
        this.f4883h = i4;
    }

    public void a(long j3, E e3) {
        int i3 = this.f4883h;
        if (i3 != 0 && j3 <= this.f4881f[i3 - 1]) {
            i(j3, e3);
            return;
        }
        if (this.f4880e && i3 >= this.f4881f.length) {
            d();
        }
        int i4 = this.f4883h;
        if (i4 >= this.f4881f.length) {
            int iF = c.f(i4 + 1);
            long[] jArr = new long[iF];
            Object[] objArr = new Object[iF];
            long[] jArr2 = this.f4881f;
            System.arraycopy(jArr2, 0, jArr, 0, jArr2.length);
            Object[] objArr2 = this.f4882g;
            System.arraycopy(objArr2, 0, objArr, 0, objArr2.length);
            this.f4881f = jArr;
            this.f4882g = objArr;
        }
        this.f4881f[i4] = j3;
        this.f4882g[i4] = e3;
        this.f4883h = i4 + 1;
    }

    public void b() {
        int i3 = this.f4883h;
        Object[] objArr = this.f4882g;
        for (int i4 = 0; i4 < i3; i4++) {
            objArr[i4] = null;
        }
        this.f4883h = 0;
        this.f4880e = false;
    }

    /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
    public d<E> clone() {
        try {
            d<E> dVar = (d) super.clone();
            dVar.f4881f = (long[]) this.f4881f.clone();
            dVar.f4882g = (Object[]) this.f4882g.clone();
            return dVar;
        } catch (CloneNotSupportedException e3) {
            throw new AssertionError(e3);
        }
    }

    public E e(long j3) {
        return f(j3, null);
    }

    public E f(long j3, E e3) {
        int iB = c.b(this.f4881f, this.f4883h, j3);
        if (iB >= 0) {
            Object[] objArr = this.f4882g;
            if (objArr[iB] != f4879i) {
                return (E) objArr[iB];
            }
        }
        return e3;
    }

    public int g(long j3) {
        if (this.f4880e) {
            d();
        }
        return c.b(this.f4881f, this.f4883h, j3);
    }

    public long h(int i3) {
        if (this.f4880e) {
            d();
        }
        return this.f4881f[i3];
    }

    public void i(long j3, E e3) {
        int iB = c.b(this.f4881f, this.f4883h, j3);
        if (iB >= 0) {
            this.f4882g[iB] = e3;
            return;
        }
        int i3 = ~iB;
        int i4 = this.f4883h;
        if (i3 < i4) {
            Object[] objArr = this.f4882g;
            if (objArr[i3] == f4879i) {
                this.f4881f[i3] = j3;
                objArr[i3] = e3;
                return;
            }
        }
        if (this.f4880e && i4 >= this.f4881f.length) {
            d();
            i3 = ~c.b(this.f4881f, this.f4883h, j3);
        }
        int i5 = this.f4883h;
        if (i5 >= this.f4881f.length) {
            int iF = c.f(i5 + 1);
            long[] jArr = new long[iF];
            Object[] objArr2 = new Object[iF];
            long[] jArr2 = this.f4881f;
            System.arraycopy(jArr2, 0, jArr, 0, jArr2.length);
            Object[] objArr3 = this.f4882g;
            System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length);
            this.f4881f = jArr;
            this.f4882g = objArr2;
        }
        int i6 = this.f4883h;
        if (i6 - i3 != 0) {
            long[] jArr3 = this.f4881f;
            int i7 = i3 + 1;
            System.arraycopy(jArr3, i3, jArr3, i7, i6 - i3);
            Object[] objArr4 = this.f4882g;
            System.arraycopy(objArr4, i3, objArr4, i7, this.f4883h - i3);
        }
        this.f4881f[i3] = j3;
        this.f4882g[i3] = e3;
        this.f4883h++;
    }

    public void j(long j3) {
        int iB = c.b(this.f4881f, this.f4883h, j3);
        if (iB >= 0) {
            Object[] objArr = this.f4882g;
            Object obj = objArr[iB];
            Object obj2 = f4879i;
            if (obj != obj2) {
                objArr[iB] = obj2;
                this.f4880e = true;
            }
        }
    }

    public void k(int i3) {
        Object[] objArr = this.f4882g;
        Object obj = objArr[i3];
        Object obj2 = f4879i;
        if (obj != obj2) {
            objArr[i3] = obj2;
            this.f4880e = true;
        }
    }

    public int l() {
        if (this.f4880e) {
            d();
        }
        return this.f4883h;
    }

    public E m(int i3) {
        if (this.f4880e) {
            d();
        }
        return (E) this.f4882g[i3];
    }

    public String toString() {
        if (l() <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f4883h * 28);
        sb.append('{');
        for (int i3 = 0; i3 < this.f4883h; i3++) {
            if (i3 > 0) {
                sb.append(", ");
            }
            sb.append(h(i3));
            sb.append('=');
            E eM = m(i3);
            if (eM != this) {
                sb.append(eM);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        return sb.toString();
    }

    public d(int i3) {
        this.f4880e = false;
        if (i3 == 0) {
            this.f4881f = c.f4877b;
            this.f4882g = c.f4878c;
        } else {
            int iF = c.f(i3);
            this.f4881f = new long[iF];
            this.f4882g = new Object[iF];
        }
    }
}
