package o;

import java.util.Arrays;
import java.util.ListIterator;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class MW extends Y {
    public final Object[] l;
    public final Object[] m;
    public final int n;

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

    public MW(Object[] objArr, Object[] objArr2, int i, int i2) {
        this.l = objArr;
        this.m = objArr2;
        this.n = i;
        this.f234o = i2;
        if (!(a() > 32)) {
            AbstractC1102eY.a("Trie-based persistent vector should have at least 33 elements, got " + a());
        }
        int length = objArr2.length;
    }

    public static Object[] k(Object[] objArr, int i, int i2, Object obj, G0 g0) {
        int iD = F3.D(i2, i);
        if (i == 0) {
            Object[] objArrCopyOf = iD == 0 ? new Object[32] : Arrays.copyOf(objArr, 32);
            AbstractC2219q9.J(iD + 1, iD, 31, objArr, objArrCopyOf);
            g0.m = objArr[31];
            objArrCopyOf[iD] = obj;
            return objArrCopyOf;
        }
        Object[] objArrCopyOf2 = Arrays.copyOf(objArr, 32);
        int i3 = i - 5;
        objArrCopyOf2[iD] = k((Object[]) objArr[iD], i3, i2, obj, g0);
        while (true) {
            iD++;
            if (iD >= 32 || objArrCopyOf2[iD] == null) {
                break;
            }
            objArrCopyOf2[iD] = k((Object[]) objArr[iD], i3, 0, g0.m, g0);
        }
        return objArrCopyOf2;
    }

    public static Object[] m(Object[] objArr, int i, int i2, G0 g0) {
        Object[] objArrM;
        int iD = F3.D(i2, i);
        if (i == 5) {
            g0.m = objArr[iD];
            objArrM = null;
        } else {
            objArrM = m((Object[]) objArr[iD], i - 5, i2, g0);
        }
        if (objArrM == null && iD == 0) {
            return null;
        }
        Object[] objArrCopyOf = Arrays.copyOf(objArr, 32);
        objArrCopyOf[iD] = objArrM;
        return objArrCopyOf;
    }

    public static Object[] s(Object[] objArr, int i, int i2, Object obj) {
        int iD = F3.D(i2, i);
        Object[] objArrCopyOf = Arrays.copyOf(objArr, 32);
        if (i == 0) {
            objArrCopyOf[iD] = obj;
            return objArrCopyOf;
        }
        objArrCopyOf[iD] = s((Object[]) objArrCopyOf[iD], i - 5, i2, obj);
        return objArrCopyOf;
    }

    @Override // o.AbstractC2864x
    public final int a() {
        return this.n;
    }

    @Override // o.Y
    public final Y b(int i, Object obj) {
        int i2 = this.n;
        AbstractC2798wI.i(i, i2);
        if (i == i2) {
            return c(obj);
        }
        int iR = r();
        Object[] objArr = this.l;
        if (i >= iR) {
            return l(i - iR, obj, objArr);
        }
        G0 g0 = new G0(5, null);
        return l(0, g0.m, k(objArr, this.f234o, i, obj, g0));
    }

    @Override // o.Y
    public final Y c(Object obj) {
        int iR = r();
        int i = this.n;
        int i2 = i - iR;
        Object[] objArr = this.l;
        Object[] objArr2 = this.m;
        if (i2 < 32) {
            Object[] objArrCopyOf = Arrays.copyOf(objArr2, 32);
            objArrCopyOf[i2] = obj;
            return new MW(objArr, objArrCopyOf, i + 1, this.f234o);
        }
        Object[] objArr3 = new Object[32];
        objArr3[0] = obj;
        return n(objArr, objArr2, objArr3);
    }

    @Override // o.Y
    public final NW e() {
        return new NW(this, this.l, this.m, this.f234o);
    }

    @Override // o.Y
    public final Y f(X x) {
        NW nw = new NW(this, this.l, this.m, this.f234o);
        nw.z(x);
        return nw.c();
    }

    @Override // java.util.List
    public final Object get(int i) {
        Object[] objArr;
        AbstractC2798wI.h(i, a());
        if (r() <= i) {
            objArr = this.m;
        } else {
            objArr = this.l;
            for (int i2 = this.f234o; i2 > 0; i2 -= 5) {
                objArr = (Object[]) objArr[F3.D(i, i2)];
            }
        }
        return objArr[i & 31];
    }

    @Override // o.Y
    public final Y h(int i) {
        AbstractC2798wI.h(i, this.n);
        int iR = r();
        Object[] objArr = this.l;
        int i2 = this.f234o;
        return i >= iR ? q(objArr, iR, i2, i - iR) : q(p(objArr, i2, i, new G0(5, this.m[0])), iR, i2, 0);
    }

    @Override // o.Y
    public final Y i(int i, Object obj) {
        int i2 = this.n;
        AbstractC2798wI.h(i, i2);
        int iR = r();
        Object[] objArr = this.l;
        Object[] objArr2 = this.m;
        int i3 = this.f234o;
        if (iR > i) {
            return new MW(s(objArr, i3, i, obj), objArr2, i2, i3);
        }
        Object[] objArrCopyOf = Arrays.copyOf(objArr2, 32);
        objArrCopyOf[i & 31] = obj;
        return new MW(objArr, objArrCopyOf, i2, i3);
    }

    public final MW l(int i, Object obj, Object[] objArr) {
        int iR = r();
        int i2 = this.n;
        int i3 = i2 - iR;
        Object[] objArr2 = this.m;
        Object[] objArrCopyOf = Arrays.copyOf(objArr2, 32);
        if (i3 < 32) {
            AbstractC2219q9.J(i + 1, i, i3, objArr2, objArrCopyOf);
            objArrCopyOf[i] = obj;
            return new MW(objArr, objArrCopyOf, i2 + 1, this.f234o);
        }
        Object obj2 = objArr2[31];
        AbstractC2219q9.J(i + 1, i, i3 - 1, objArr2, objArrCopyOf);
        objArrCopyOf[i] = obj;
        Object[] objArr3 = new Object[32];
        objArr3[0] = obj2;
        return n(objArr, objArrCopyOf, objArr3);
    }

    @Override // o.Q, java.util.List
    public final ListIterator listIterator(int i) {
        AbstractC2798wI.i(i, this.n);
        return new OW(i, this.n, (this.f234o / 5) + 1, this.l, this.m);
    }

    public final MW n(Object[] objArr, Object[] objArr2, Object[] objArr3) {
        int i = this.n;
        int i2 = i >> 5;
        int i3 = this.f234o;
        if (i2 <= (1 << i3)) {
            return new MW(o(i3, objArr, objArr2), objArr3, i + 1, i3);
        }
        Object[] objArr4 = new Object[32];
        objArr4[0] = objArr;
        int i4 = i3 + 5;
        return new MW(o(i4, objArr4, objArr2), objArr3, i + 1, i4);
    }

    public final Object[] o(int i, Object[] objArr, Object[] objArr2) {
        int iD = F3.D(a() - 1, i);
        Object[] objArrCopyOf = objArr != null ? Arrays.copyOf(objArr, 32) : new Object[32];
        if (i == 5) {
            objArrCopyOf[iD] = objArr2;
            return objArrCopyOf;
        }
        objArrCopyOf[iD] = o(i - 5, (Object[]) objArrCopyOf[iD], objArr2);
        return objArrCopyOf;
    }

    public final Object[] p(Object[] objArr, int i, int i2, G0 g0) {
        int iD = F3.D(i2, i);
        if (i == 0) {
            Object[] objArrCopyOf = iD == 0 ? new Object[32] : Arrays.copyOf(objArr, 32);
            AbstractC2219q9.J(iD, iD + 1, 32, objArr, objArrCopyOf);
            objArrCopyOf[31] = g0.m;
            g0.m = objArr[iD];
            return objArrCopyOf;
        }
        int iD2 = objArr[31] == null ? F3.D(r() - 1, i) : 31;
        Object[] objArrCopyOf2 = Arrays.copyOf(objArr, 32);
        int i3 = i - 5;
        int i4 = iD + 1;
        if (i4 <= iD2) {
            while (true) {
                objArrCopyOf2[iD2] = p((Object[]) objArrCopyOf2[iD2], i3, 0, g0);
                if (iD2 == i4) {
                    break;
                }
                iD2--;
            }
        }
        objArrCopyOf2[iD] = p((Object[]) objArrCopyOf2[iD], i3, i2, g0);
        return objArrCopyOf2;
    }

    public final Y q(Object[] objArr, int i, int i2, int i3) {
        int i4 = this.n - i;
        if (i4 != 1) {
            Object[] objArr2 = this.m;
            Object[] objArrCopyOf = Arrays.copyOf(objArr2, 32);
            int i5 = i4 - 1;
            if (i3 < i5) {
                AbstractC2219q9.J(i3, i3 + 1, i4, objArr2, objArrCopyOf);
            }
            objArrCopyOf[i5] = null;
            return new MW(objArr, objArrCopyOf, (i + i4) - 1, i2);
        }
        if (i2 == 0) {
            if (objArr.length == 33) {
                objArr = Arrays.copyOf(objArr, 32);
            }
            return new C1555j90(objArr);
        }
        G0 g0 = new G0(5, null);
        Object[] objArrM = m(objArr, i2, i - 1, g0);
        Object[] objArr3 = (Object[]) g0.m;
        return objArrM[1] == null ? new MW((Object[]) objArrM[0], objArr3, i, i2 - 5) : new MW(objArrM, objArr3, i, i2);
    }

    public final int r() {
        return (this.n - 1) & (-32);
    }
}
