package p040n;

import java.util.Arrays;
import p040n.C1479b;

/* renamed from: n.a */
/* loaded from: classes.dex */
public class C1478a implements C1479b.InterfaceC1480a {

    /* renamed from: l */
    public static float f3228l = 0.001f;

    /* renamed from: b */
    public final C1479b f3230b;

    /* renamed from: c */
    public final C1481c f3231c;

    /* renamed from: a */
    public int f3229a = 0;

    /* renamed from: d */
    public int f3232d = 8;

    /* renamed from: e */
    public C1491i f3233e = null;

    /* renamed from: f */
    public int[] f3234f = new int[8];

    /* renamed from: g */
    public int[] f3235g = new int[8];

    /* renamed from: h */
    public float[] f3236h = new float[8];

    /* renamed from: i */
    public int f3237i = -1;

    /* renamed from: j */
    public int f3238j = -1;

    /* renamed from: k */
    public boolean f3239k = false;

    public C1478a(C1479b c1479b, C1481c c1481c) {
        this.f3230b = c1479b;
        this.f3231c = c1481c;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: a */
    public float mo1189a(int i) {
        int i2 = this.f3237i;
        for (int i3 = 0; i2 != -1 && i3 < this.f3229a; i3++) {
            if (i3 == i) {
                return this.f3236h[i2];
            }
            i2 = this.f3235g[i2];
        }
        return 0.0f;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: b */
    public final float mo1188b(C1491i c1491i) {
        int i = this.f3237i;
        for (int i2 = 0; i != -1 && i2 < this.f3229a; i2++) {
            if (this.f3234f[i] == c1491i.f3291f) {
                return this.f3236h[i];
            }
            i = this.f3235g[i];
        }
        return 0.0f;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: c */
    public void mo1187c(C1491i c1491i, float f, boolean z) {
        float f2 = f3228l;
        if (f <= (-f2) || f >= f2) {
            int i = this.f3237i;
            if (i == -1) {
                this.f3237i = 0;
                this.f3236h[0] = f;
                this.f3234f[0] = c1491i.f3291f;
                this.f3235g[0] = -1;
                c1491i.f3301p++;
                c1491i.m1197a(this.f3230b);
                this.f3229a++;
                if (this.f3239k) {
                    return;
                }
                int i2 = this.f3238j + 1;
                this.f3238j = i2;
                int[] iArr = this.f3234f;
                if (i2 >= iArr.length) {
                    this.f3239k = true;
                    this.f3238j = iArr.length - 1;
                    return;
                }
                return;
            }
            int i3 = -1;
            for (int i4 = 0; i != -1 && i4 < this.f3229a; i4++) {
                int i5 = this.f3234f[i];
                int i6 = c1491i.f3291f;
                if (i5 == i6) {
                    float[] fArr = this.f3236h;
                    float f3 = fArr[i] + f;
                    float f4 = f3228l;
                    if (f3 > (-f4) && f3 < f4) {
                        f3 = 0.0f;
                    }
                    fArr[i] = f3;
                    if (f3 == 0.0f) {
                        if (i == this.f3237i) {
                            this.f3237i = this.f3235g[i];
                        } else {
                            int[] iArr2 = this.f3235g;
                            iArr2[i3] = iArr2[i];
                        }
                        if (z) {
                            c1491i.m1194d(this.f3230b);
                        }
                        if (this.f3239k) {
                            this.f3238j = i;
                        }
                        c1491i.f3301p--;
                        this.f3229a--;
                        return;
                    }
                    return;
                }
                if (i5 < i6) {
                    i3 = i;
                }
                i = this.f3235g[i];
            }
            int i7 = this.f3238j;
            int i8 = i7 + 1;
            if (this.f3239k) {
                int[] iArr3 = this.f3234f;
                if (iArr3[i7] != -1) {
                    i7 = iArr3.length;
                }
            } else {
                i7 = i8;
            }
            int[] iArr4 = this.f3234f;
            if (i7 >= iArr4.length && this.f3229a < iArr4.length) {
                int i9 = 0;
                while (true) {
                    int[] iArr5 = this.f3234f;
                    if (i9 >= iArr5.length) {
                        break;
                    } else if (iArr5[i9] == -1) {
                        i7 = i9;
                        break;
                    } else {
                        i9++;
                    }
                }
            }
            int[] iArr6 = this.f3234f;
            if (i7 >= iArr6.length) {
                i7 = iArr6.length;
                int i10 = this.f3232d * 2;
                this.f3232d = i10;
                this.f3239k = false;
                this.f3238j = i7 - 1;
                this.f3236h = Arrays.copyOf(this.f3236h, i10);
                this.f3234f = Arrays.copyOf(this.f3234f, this.f3232d);
                this.f3235g = Arrays.copyOf(this.f3235g, this.f3232d);
            }
            this.f3234f[i7] = c1491i.f3291f;
            this.f3236h[i7] = f;
            int[] iArr7 = this.f3235g;
            if (i3 != -1) {
                iArr7[i7] = iArr7[i3];
                iArr7[i3] = i7;
            } else {
                iArr7[i7] = this.f3237i;
                this.f3237i = i7;
            }
            c1491i.f3301p++;
            c1491i.m1197a(this.f3230b);
            this.f3229a++;
            if (!this.f3239k) {
                this.f3238j++;
            }
            int i11 = this.f3238j;
            int[] iArr8 = this.f3234f;
            if (i11 >= iArr8.length) {
                this.f3239k = true;
                this.f3238j = iArr8.length - 1;
            }
        }
    }

    @Override // p040n.C1479b.InterfaceC1480a
    public final void clear() {
        int i = this.f3237i;
        for (int i2 = 0; i != -1 && i2 < this.f3229a; i2++) {
            C1491i c1491i = this.f3231c.f3249d[this.f3234f[i]];
            if (c1491i != null) {
                c1491i.m1194d(this.f3230b);
            }
            i = this.f3235g[i];
        }
        this.f3237i = -1;
        this.f3238j = -1;
        this.f3239k = false;
        this.f3229a = 0;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: d */
    public float mo1186d(C1479b c1479b, boolean z) {
        float mo1188b = mo1188b(c1479b.f3240a);
        mo1181i(c1479b.f3240a, z);
        C1479b.InterfaceC1480a interfaceC1480a = c1479b.f3244e;
        int mo1179k = interfaceC1480a.mo1179k();
        for (int i = 0; i < mo1179k; i++) {
            C1491i mo1184f = interfaceC1480a.mo1184f(i);
            mo1187c(mo1184f, interfaceC1480a.mo1188b(mo1184f) * mo1188b, z);
        }
        return mo1188b;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: e */
    public boolean mo1185e(C1491i c1491i) {
        int i = this.f3237i;
        if (i == -1) {
            return false;
        }
        for (int i2 = 0; i != -1 && i2 < this.f3229a; i2++) {
            if (this.f3234f[i] == c1491i.f3291f) {
                return true;
            }
            i = this.f3235g[i];
        }
        return false;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: f */
    public C1491i mo1184f(int i) {
        int i2 = this.f3237i;
        for (int i3 = 0; i2 != -1 && i3 < this.f3229a; i3++) {
            if (i3 == i) {
                return this.f3231c.f3249d[this.f3234f[i2]];
            }
            i2 = this.f3235g[i2];
        }
        return null;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: g */
    public final void mo1183g(C1491i c1491i, float f) {
        if (f == 0.0f) {
            mo1181i(c1491i, true);
            return;
        }
        int i = this.f3237i;
        if (i == -1) {
            this.f3237i = 0;
            this.f3236h[0] = f;
            this.f3234f[0] = c1491i.f3291f;
            this.f3235g[0] = -1;
            c1491i.f3301p++;
            c1491i.m1197a(this.f3230b);
            this.f3229a++;
            if (this.f3239k) {
                return;
            }
            int i2 = this.f3238j + 1;
            this.f3238j = i2;
            int[] iArr = this.f3234f;
            if (i2 >= iArr.length) {
                this.f3239k = true;
                this.f3238j = iArr.length - 1;
                return;
            }
            return;
        }
        int i3 = -1;
        for (int i4 = 0; i != -1 && i4 < this.f3229a; i4++) {
            int i5 = this.f3234f[i];
            int i6 = c1491i.f3291f;
            if (i5 == i6) {
                this.f3236h[i] = f;
                return;
            }
            if (i5 < i6) {
                i3 = i;
            }
            i = this.f3235g[i];
        }
        int i7 = this.f3238j;
        int i8 = i7 + 1;
        if (this.f3239k) {
            int[] iArr2 = this.f3234f;
            if (iArr2[i7] != -1) {
                i7 = iArr2.length;
            }
        } else {
            i7 = i8;
        }
        int[] iArr3 = this.f3234f;
        if (i7 >= iArr3.length && this.f3229a < iArr3.length) {
            int i9 = 0;
            while (true) {
                int[] iArr4 = this.f3234f;
                if (i9 >= iArr4.length) {
                    break;
                } else if (iArr4[i9] == -1) {
                    i7 = i9;
                    break;
                } else {
                    i9++;
                }
            }
        }
        int[] iArr5 = this.f3234f;
        if (i7 >= iArr5.length) {
            i7 = iArr5.length;
            int i10 = this.f3232d * 2;
            this.f3232d = i10;
            this.f3239k = false;
            this.f3238j = i7 - 1;
            this.f3236h = Arrays.copyOf(this.f3236h, i10);
            this.f3234f = Arrays.copyOf(this.f3234f, this.f3232d);
            this.f3235g = Arrays.copyOf(this.f3235g, this.f3232d);
        }
        this.f3234f[i7] = c1491i.f3291f;
        this.f3236h[i7] = f;
        int[] iArr6 = this.f3235g;
        if (i3 != -1) {
            iArr6[i7] = iArr6[i3];
            iArr6[i3] = i7;
        } else {
            iArr6[i7] = this.f3237i;
            this.f3237i = i7;
        }
        c1491i.f3301p++;
        c1491i.m1197a(this.f3230b);
        int i11 = this.f3229a + 1;
        this.f3229a = i11;
        if (!this.f3239k) {
            this.f3238j++;
        }
        int[] iArr7 = this.f3234f;
        if (i11 >= iArr7.length) {
            this.f3239k = true;
        }
        if (this.f3238j >= iArr7.length) {
            this.f3239k = true;
            this.f3238j = iArr7.length - 1;
        }
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: h */
    public void mo1182h(float f) {
        int i = this.f3237i;
        for (int i2 = 0; i != -1 && i2 < this.f3229a; i2++) {
            float[] fArr = this.f3236h;
            fArr[i] = fArr[i] / f;
            i = this.f3235g[i];
        }
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: i */
    public final float mo1181i(C1491i c1491i, boolean z) {
        if (this.f3233e == c1491i) {
            this.f3233e = null;
        }
        int i = this.f3237i;
        if (i == -1) {
            return 0.0f;
        }
        int i2 = 0;
        int i3 = -1;
        while (i != -1 && i2 < this.f3229a) {
            if (this.f3234f[i] == c1491i.f3291f) {
                if (i == this.f3237i) {
                    this.f3237i = this.f3235g[i];
                } else {
                    int[] iArr = this.f3235g;
                    iArr[i3] = iArr[i];
                }
                if (z) {
                    c1491i.m1194d(this.f3230b);
                }
                c1491i.f3301p--;
                this.f3229a--;
                this.f3234f[i] = -1;
                if (this.f3239k) {
                    this.f3238j = i;
                }
                return this.f3236h[i];
            }
            i2++;
            i3 = i;
            i = this.f3235g[i];
        }
        return 0.0f;
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: j */
    public void mo1180j() {
        int i = this.f3237i;
        for (int i2 = 0; i != -1 && i2 < this.f3229a; i2++) {
            float[] fArr = this.f3236h;
            fArr[i] = fArr[i] * (-1.0f);
            i = this.f3235g[i];
        }
    }

    @Override // p040n.C1479b.InterfaceC1480a
    /* renamed from: k */
    public int mo1179k() {
        return this.f3229a;
    }

    public String toString() {
        int i = this.f3237i;
        String str = "";
        for (int i2 = 0; i != -1 && i2 < this.f3229a; i2++) {
            str = ((str + " -> ") + this.f3236h[i] + " : ") + this.f3231c.f3249d[this.f3234f[i]];
            i = this.f3235g[i];
        }
        return str;
    }
}