package u;

import d5.AbstractC0844a;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class j implements InterfaceC1557b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f17088a = 16;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int[] f17089b = new int[16];

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int[] f17090c = new int[16];

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int[] f17091d = new int[16];

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public float[] f17092e = new float[16];

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int[] f17093f = new int[16];

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int[] f17094g = new int[16];

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f17095h = 0;
    public int i = -1;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final C1559d f17096j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final C2.a f17097k;

    public j(C1559d c1559d, C2.a aVar) {
        this.f17096j = c1559d;
        this.f17097k = aVar;
        clear();
    }

    @Override // u.InterfaceC1557b
    public final float a(int i) {
        int i5 = this.f17095h;
        int i8 = this.i;
        for (int i9 = 0; i9 < i5; i9++) {
            if (i9 == i) {
                return this.f17092e[i8];
            }
            i8 = this.f17094g[i8];
            if (i8 == -1) {
                return 0.0f;
            }
        }
        return 0.0f;
    }

    @Override // u.InterfaceC1557b
    public final boolean b(i iVar) {
        return n(iVar) != -1;
    }

    @Override // u.InterfaceC1557b
    public final void c(i iVar, float f3, boolean z8) {
        if (f3 <= -0.001f || f3 >= 0.001f) {
            int iN = n(iVar);
            if (iN == -1) {
                e(iVar, f3);
                return;
            }
            float[] fArr = this.f17092e;
            float f7 = fArr[iN] + f3;
            fArr[iN] = f7;
            if (f7 <= -0.001f || f7 >= 0.001f) {
                return;
            }
            fArr[iN] = 0.0f;
            g(iVar, z8);
        }
    }

    @Override // u.InterfaceC1557b
    public final void clear() {
        int i = this.f17095h;
        for (int i5 = 0; i5 < i; i5++) {
            i iVarF = f(i5);
            if (iVarF != null) {
                iVarF.b(this.f17096j);
            }
        }
        for (int i8 = 0; i8 < this.f17088a; i8++) {
            this.f17091d[i8] = -1;
            this.f17090c[i8] = -1;
        }
        for (int i9 = 0; i9 < 16; i9++) {
            this.f17089b[i9] = -1;
        }
        this.f17095h = 0;
        this.i = -1;
    }

    @Override // u.InterfaceC1557b
    public final float d(i iVar) {
        int iN = n(iVar);
        if (iN != -1) {
            return this.f17092e[iN];
        }
        return 0.0f;
    }

    @Override // u.InterfaceC1557b
    public final void e(i iVar, float f3) {
        if (f3 > -0.001f && f3 < 0.001f) {
            g(iVar, true);
            return;
        }
        int i = 0;
        if (this.f17095h == 0) {
            m(0, iVar, f3);
            l(iVar, 0);
            this.i = 0;
            return;
        }
        int iN = n(iVar);
        if (iN != -1) {
            this.f17092e[iN] = f3;
            return;
        }
        int i5 = this.f17095h + 1;
        int i8 = this.f17088a;
        if (i5 >= i8) {
            int i9 = i8 * 2;
            this.f17091d = Arrays.copyOf(this.f17091d, i9);
            this.f17092e = Arrays.copyOf(this.f17092e, i9);
            this.f17093f = Arrays.copyOf(this.f17093f, i9);
            this.f17094g = Arrays.copyOf(this.f17094g, i9);
            this.f17090c = Arrays.copyOf(this.f17090c, i9);
            for (int i10 = this.f17088a; i10 < i9; i10++) {
                this.f17091d[i10] = -1;
                this.f17090c[i10] = -1;
            }
            this.f17088a = i9;
        }
        int i11 = this.f17095h;
        int i12 = this.i;
        int i13 = -1;
        for (int i14 = 0; i14 < i11; i14++) {
            int i15 = this.f17091d[i12];
            int i16 = iVar.f17078b;
            if (i15 == i16) {
                this.f17092e[i12] = f3;
                return;
            }
            if (i15 < i16) {
                i13 = i12;
            }
            i12 = this.f17094g[i12];
            if (i12 == -1) {
                break;
            }
        }
        while (true) {
            if (i >= this.f17088a) {
                i = -1;
                break;
            } else if (this.f17091d[i] == -1) {
                break;
            } else {
                i++;
            }
        }
        m(i, iVar, f3);
        if (i13 != -1) {
            this.f17093f[i] = i13;
            int[] iArr = this.f17094g;
            iArr[i] = iArr[i13];
            iArr[i13] = i;
        } else {
            this.f17093f[i] = -1;
            if (this.f17095h > 0) {
                this.f17094g[i] = this.i;
                this.i = i;
            } else {
                this.f17094g[i] = -1;
            }
        }
        int i17 = this.f17094g[i];
        if (i17 != -1) {
            this.f17093f[i17] = i;
        }
        l(iVar, i);
    }

    @Override // u.InterfaceC1557b
    public final i f(int i) {
        int i5 = this.f17095h;
        if (i5 == 0) {
            return null;
        }
        int i8 = this.i;
        for (int i9 = 0; i9 < i5; i9++) {
            if (i9 == i && i8 != -1) {
                return ((i[]) this.f17097k.f1160u)[this.f17091d[i8]];
            }
            i8 = this.f17094g[i8];
            if (i8 == -1) {
                break;
            }
        }
        return null;
    }

    @Override // u.InterfaceC1557b
    public final float g(i iVar, boolean z8) {
        int[] iArr;
        int i;
        int iN = n(iVar);
        if (iN == -1) {
            return 0.0f;
        }
        int i5 = iVar.f17078b;
        int i8 = i5 % 16;
        int[] iArr2 = this.f17089b;
        int i9 = iArr2[i8];
        if (i9 != -1) {
            if (this.f17091d[i9] == i5) {
                int[] iArr3 = this.f17090c;
                iArr2[i8] = iArr3[i9];
                iArr3[i9] = -1;
            } else {
                while (true) {
                    iArr = this.f17090c;
                    i = iArr[i9];
                    if (i == -1 || this.f17091d[i] == i5) {
                        break;
                    }
                    i9 = i;
                }
                if (i != -1 && this.f17091d[i] == i5) {
                    iArr[i9] = iArr[i];
                    iArr[i] = -1;
                }
            }
        }
        float f3 = this.f17092e[iN];
        if (this.i == iN) {
            this.i = this.f17094g[iN];
        }
        this.f17091d[iN] = -1;
        int[] iArr4 = this.f17093f;
        int i10 = iArr4[iN];
        if (i10 != -1) {
            int[] iArr5 = this.f17094g;
            iArr5[i10] = iArr5[iN];
        }
        int i11 = this.f17094g[iN];
        if (i11 != -1) {
            iArr4[i11] = iArr4[iN];
        }
        this.f17095h--;
        iVar.f17086k--;
        if (z8) {
            iVar.b(this.f17096j);
        }
        return f3;
    }

    @Override // u.InterfaceC1557b
    public final void h(float f3) {
        int i = this.f17095h;
        int i5 = this.i;
        for (int i8 = 0; i8 < i; i8++) {
            float[] fArr = this.f17092e;
            fArr[i5] = fArr[i5] / f3;
            i5 = this.f17094g[i5];
            if (i5 == -1) {
                return;
            }
        }
    }

    @Override // u.InterfaceC1557b
    public final float i(C1558c c1558c, boolean z8) {
        float fD = d(c1558c.f17051a);
        g(c1558c.f17051a, z8);
        j jVar = (j) c1558c.f17054d;
        int i = jVar.f17095h;
        int i5 = 0;
        int i8 = 0;
        while (i5 < i) {
            int i9 = jVar.f17091d[i8];
            if (i9 != -1) {
                c(((i[]) this.f17097k.f1160u)[i9], jVar.f17092e[i8] * fD, z8);
                i5++;
            }
            i8++;
        }
        return fD;
    }

    @Override // u.InterfaceC1557b
    public final void j() {
        int i = this.f17095h;
        int i5 = this.i;
        for (int i8 = 0; i8 < i; i8++) {
            float[] fArr = this.f17092e;
            fArr[i5] = fArr[i5] * (-1.0f);
            i5 = this.f17094g[i5];
            if (i5 == -1) {
                return;
            }
        }
    }

    @Override // u.InterfaceC1557b
    public final int k() {
        return this.f17095h;
    }

    public final void l(i iVar, int i) {
        int[] iArr;
        int i5 = iVar.f17078b % 16;
        int[] iArr2 = this.f17089b;
        int i8 = iArr2[i5];
        if (i8 == -1) {
            iArr2[i5] = i;
        } else {
            while (true) {
                iArr = this.f17090c;
                int i9 = iArr[i8];
                if (i9 == -1) {
                    break;
                } else {
                    i8 = i9;
                }
            }
            iArr[i8] = i;
        }
        this.f17090c[i] = -1;
    }

    public final void m(int i, i iVar, float f3) {
        this.f17091d[i] = iVar.f17078b;
        this.f17092e[i] = f3;
        this.f17093f[i] = -1;
        this.f17094g[i] = -1;
        iVar.a(this.f17096j);
        iVar.f17086k++;
        this.f17095h++;
    }

    public final int n(i iVar) {
        if (this.f17095h == 0) {
            return -1;
        }
        int i = iVar.f17078b;
        int i5 = this.f17089b[i % 16];
        if (i5 == -1) {
            return -1;
        }
        if (this.f17091d[i5] == i) {
            return i5;
        }
        do {
            i5 = this.f17090c[i5];
            if (i5 == -1) {
                break;
            }
        } while (this.f17091d[i5] != i);
        if (i5 != -1 && this.f17091d[i5] == i) {
            return i5;
        }
        return -1;
    }

    public final String toString() {
        String strL;
        String strL2;
        String strL3 = hashCode() + " { ";
        int i = this.f17095h;
        for (int i5 = 0; i5 < i; i5++) {
            i iVarF = f(i5);
            if (iVarF != null) {
                String str = strL3 + iVarF + " = " + a(i5) + " ";
                int iN = n(iVarF);
                String strL4 = AbstractC0844a.l(str, "[p: ");
                int i8 = this.f17093f[iN];
                C2.a aVar = this.f17097k;
                if (i8 != -1) {
                    StringBuilder sbB = AbstractC1563h.b(strL4);
                    sbB.append(((i[]) aVar.f1160u)[this.f17091d[this.f17093f[iN]]]);
                    strL = sbB.toString();
                } else {
                    strL = AbstractC0844a.l(strL4, "none");
                }
                String strL5 = AbstractC0844a.l(strL, ", n: ");
                if (this.f17094g[iN] != -1) {
                    StringBuilder sbB2 = AbstractC1563h.b(strL5);
                    sbB2.append(((i[]) aVar.f1160u)[this.f17091d[this.f17094g[iN]]]);
                    strL2 = sbB2.toString();
                } else {
                    strL2 = AbstractC0844a.l(strL5, "none");
                }
                strL3 = AbstractC0844a.l(strL2, "]");
            }
        }
        return AbstractC0844a.l(strL3, " }");
    }
}
