package o;

import java.util.Arrays;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class UM implements Cloneable {
    public /* synthetic */ boolean l;
    public /* synthetic */ long[] m;
    public /* synthetic */ Object[] n;

    /* renamed from: o, reason: collision with root package name */
    public /* synthetic */ int f356o;

    public UM(int i) {
        if (i == 0) {
            this.m = AbstractC0940cn0.b;
            this.n = AbstractC0940cn0.c;
            return;
        }
        int i2 = i * 8;
        int i3 = 4;
        while (true) {
            if (i3 >= 32) {
                break;
            }
            int i4 = (1 << i3) - 12;
            if (i2 <= i4) {
                i2 = i4;
                break;
            }
            i3++;
        }
        int i5 = i2 / 8;
        this.m = new long[i5];
        this.n = new Object[i5];
    }

    public final void a() {
        int i = this.f356o;
        Object[] objArr = this.n;
        for (int i2 = 0; i2 < i; i2++) {
            objArr[i2] = null;
        }
        this.f356o = 0;
        this.l = false;
    }

    public final Object b(long j) {
        Object obj;
        int iD = AbstractC0940cn0.d(this.m, this.f356o, j);
        if (iD < 0 || (obj = this.n[iD]) == AbstractC1904ms0.c) {
            return null;
        }
        return obj;
    }

    public final int c(long j) {
        if (this.l) {
            int i = this.f356o;
            long[] jArr = this.m;
            Object[] objArr = this.n;
            int i2 = 0;
            for (int i3 = 0; i3 < i; i3++) {
                Object obj = objArr[i3];
                if (obj != AbstractC1904ms0.c) {
                    if (i3 != i2) {
                        jArr[i2] = jArr[i3];
                        objArr[i2] = obj;
                        objArr[i3] = null;
                    }
                    i2++;
                }
            }
            this.l = false;
            this.f356o = i2;
        }
        return AbstractC0940cn0.d(this.m, this.f356o, j);
    }

    public final Object clone() {
        UM um = (UM) super.clone();
        um.m = (long[]) this.m.clone();
        um.n = (Object[]) this.n.clone();
        return um;
    }

    public final long d(int i) {
        int i2;
        if (i < 0 || i >= (i2 = this.f356o)) {
            AbstractC2841wm0.I("Expected index to be within 0..size()-1, but was " + i);
            throw null;
        }
        if (this.l) {
            long[] jArr = this.m;
            Object[] objArr = this.n;
            int i3 = 0;
            for (int i4 = 0; i4 < i2; i4++) {
                Object obj = objArr[i4];
                if (obj != AbstractC1904ms0.c) {
                    if (i4 != i3) {
                        jArr[i3] = jArr[i4];
                        objArr[i3] = obj;
                        objArr[i4] = null;
                    }
                    i3++;
                }
            }
            this.l = false;
            this.f356o = i3;
        }
        return this.m[i];
    }

    public final void e(long j, Object obj) {
        Object obj2 = AbstractC1904ms0.c;
        int iD = AbstractC0940cn0.d(this.m, this.f356o, j);
        if (iD >= 0) {
            this.n[iD] = obj;
            return;
        }
        int i = ~iD;
        int i2 = this.f356o;
        if (i < i2) {
            Object[] objArr = this.n;
            if (objArr[i] == obj2) {
                this.m[i] = j;
                objArr[i] = obj;
                return;
            }
        }
        if (this.l) {
            long[] jArr = this.m;
            if (i2 >= jArr.length) {
                Object[] objArr2 = this.n;
                int i3 = 0;
                for (int i4 = 0; i4 < i2; i4++) {
                    Object obj3 = objArr2[i4];
                    if (obj3 != obj2) {
                        if (i4 != i3) {
                            jArr[i3] = jArr[i4];
                            objArr2[i3] = obj3;
                            objArr2[i4] = null;
                        }
                        i3++;
                    }
                }
                this.l = false;
                this.f356o = i3;
                i = ~AbstractC0940cn0.d(this.m, i3, j);
            }
        }
        int i5 = this.f356o;
        if (i5 >= this.m.length) {
            int i6 = (i5 + 1) * 8;
            int i7 = 4;
            while (true) {
                if (i7 >= 32) {
                    break;
                }
                int i8 = (1 << i7) - 12;
                if (i6 <= i8) {
                    i6 = i8;
                    break;
                }
                i7++;
            }
            int i9 = i6 / 8;
            this.m = Arrays.copyOf(this.m, i9);
            this.n = Arrays.copyOf(this.n, i9);
        }
        int i10 = this.f356o;
        if (i10 - i != 0) {
            long[] jArr2 = this.m;
            int i11 = i + 1;
            AbstractC2219q9.K(jArr2, jArr2, i11, i, i10);
            Object[] objArr3 = this.n;
            AbstractC2219q9.J(i11, i, this.f356o, objArr3, objArr3);
        }
        this.m[i] = j;
        this.n[i] = obj;
        this.f356o++;
    }

    public final void f(long j) {
        int iD = AbstractC0940cn0.d(this.m, this.f356o, j);
        if (iD >= 0) {
            Object[] objArr = this.n;
            Object obj = objArr[iD];
            Object obj2 = AbstractC1904ms0.c;
            if (obj != obj2) {
                objArr[iD] = obj2;
                this.l = true;
            }
        }
    }

    public final int g() {
        if (this.l) {
            int i = this.f356o;
            long[] jArr = this.m;
            Object[] objArr = this.n;
            int i2 = 0;
            for (int i3 = 0; i3 < i; i3++) {
                Object obj = objArr[i3];
                if (obj != AbstractC1904ms0.c) {
                    if (i3 != i2) {
                        jArr[i2] = jArr[i3];
                        objArr[i2] = obj;
                        objArr[i3] = null;
                    }
                    i2++;
                }
            }
            this.l = false;
            this.f356o = i2;
        }
        return this.f356o;
    }

    public final Object h(int i) {
        int i2;
        if (i < 0 || i >= (i2 = this.f356o)) {
            AbstractC2841wm0.I("Expected index to be within 0..size()-1, but was " + i);
            throw null;
        }
        if (this.l) {
            long[] jArr = this.m;
            Object[] objArr = this.n;
            int i3 = 0;
            for (int i4 = 0; i4 < i2; i4++) {
                Object obj = objArr[i4];
                if (obj != AbstractC1904ms0.c) {
                    if (i4 != i3) {
                        jArr[i3] = jArr[i4];
                        objArr[i3] = obj;
                        objArr[i4] = null;
                    }
                    i3++;
                }
            }
            this.l = false;
            this.f356o = i3;
        }
        return this.n[i];
    }

    public final String toString() {
        if (g() <= 0) {
            return "{}";
        }
        StringBuilder sb = new StringBuilder(this.f356o * 28);
        sb.append('{');
        int i = this.f356o;
        for (int i2 = 0; i2 < i; i2++) {
            if (i2 > 0) {
                sb.append(", ");
            }
            sb.append(d(i2));
            sb.append('=');
            Object objH = h(i2);
            if (objH != sb) {
                sb.append(objH);
            } else {
                sb.append("(this Map)");
            }
        }
        sb.append('}');
        return sb.toString();
    }

    public /* synthetic */ UM(Object obj) {
        this(10);
    }
}
