package n1;

import C4.f;
import Z0.o;
import java.util.Arrays;

/* JADX INFO: renamed from: n1.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2607a {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C2608b f21562b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final f f21563c;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f21564d = 8;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int[] f21565e = new int[8];

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public float[] f21567g = new float[8];

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f21570j = false;

    public C2607a(C2608b c2608b, f fVar) {
        this.f21562b = c2608b;
        this.f21563c = fVar;
    }

    public final void a(e eVar, float f6, boolean z6) {
        if (f6 <= -0.001f || f6 >= 0.001f) {
            int i6 = this.f21568h;
            C2608b c2608b = this.f21562b;
            if (i6 == -1) {
                this.f21568h = 0;
                this.f21567g[0] = f6;
                this.f21565e[0] = eVar.f21597b;
                this.f21566f[0] = -1;
                eVar.f21605n++;
                eVar.a(c2608b);
                this.f21561a++;
                if (this.f21570j) {
                    return;
                }
                int i7 = this.f21569i + 1;
                this.f21569i = i7;
                int[] iArr = this.f21565e;
                if (i7 >= iArr.length) {
                    this.f21570j = true;
                    this.f21569i = iArr.length - 1;
                    return;
                }
                return;
            }
            int i8 = -1;
            for (int i9 = 0; i6 != -1 && i9 < this.f21561a; i9++) {
                int i10 = this.f21565e[i6];
                int i11 = eVar.f21597b;
                if (i10 == i11) {
                    float[] fArr = this.f21567g;
                    float f7 = fArr[i6] + f6;
                    if (f7 > -0.001f && f7 < 0.001f) {
                        f7 = 0.0f;
                    }
                    fArr[i6] = f7;
                    if (f7 == 0.0f) {
                        if (i6 == this.f21568h) {
                            this.f21568h = this.f21566f[i6];
                        } else {
                            int[] iArr2 = this.f21566f;
                            iArr2[i8] = iArr2[i6];
                        }
                        if (z6) {
                            eVar.b(c2608b);
                        }
                        if (this.f21570j) {
                            this.f21569i = i6;
                        }
                        eVar.f21605n--;
                        this.f21561a--;
                        return;
                    }
                    return;
                }
                if (i10 < i11) {
                    i8 = i6;
                }
                i6 = this.f21566f[i6];
            }
            int length = this.f21569i;
            int i12 = length + 1;
            if (this.f21570j) {
                int[] iArr3 = this.f21565e;
                if (iArr3[length] != -1) {
                    length = iArr3.length;
                }
            } else {
                length = i12;
            }
            int[] iArr4 = this.f21565e;
            if (length >= iArr4.length && this.f21561a < iArr4.length) {
                int i13 = 0;
                while (true) {
                    int[] iArr5 = this.f21565e;
                    if (i13 >= iArr5.length) {
                        break;
                    }
                    if (iArr5[i13] == -1) {
                        length = i13;
                        break;
                    }
                    i13++;
                }
            }
            int[] iArr6 = this.f21565e;
            if (length >= iArr6.length) {
                length = iArr6.length;
                int i14 = this.f21564d * 2;
                this.f21564d = i14;
                this.f21570j = false;
                this.f21569i = length - 1;
                this.f21567g = Arrays.copyOf(this.f21567g, i14);
                this.f21565e = Arrays.copyOf(this.f21565e, this.f21564d);
                this.f21566f = Arrays.copyOf(this.f21566f, this.f21564d);
            }
            this.f21565e[length] = eVar.f21597b;
            this.f21567g[length] = f6;
            if (i8 != -1) {
                int[] iArr7 = this.f21566f;
                iArr7[length] = iArr7[i8];
                iArr7[i8] = length;
            } else {
                this.f21566f[length] = this.f21568h;
                this.f21568h = length;
            }
            eVar.f21605n++;
            eVar.a(c2608b);
            this.f21561a++;
            if (!this.f21570j) {
                this.f21569i++;
            }
            int i15 = this.f21569i;
            int[] iArr8 = this.f21565e;
            if (i15 >= iArr8.length) {
                this.f21570j = true;
                this.f21569i = iArr8.length - 1;
            }
        }
    }

    public final void b() {
        int i6 = this.f21568h;
        for (int i7 = 0; i6 != -1 && i7 < this.f21561a; i7++) {
            e eVar = ((e[]) this.f21563c.f743d)[this.f21565e[i6]];
            if (eVar != null) {
                eVar.b(this.f21562b);
            }
            i6 = this.f21566f[i6];
        }
        this.f21568h = -1;
        this.f21569i = -1;
        this.f21570j = false;
        this.f21561a = 0;
    }

    public final float c(e eVar) {
        int i6 = this.f21568h;
        for (int i7 = 0; i6 != -1 && i7 < this.f21561a; i7++) {
            if (this.f21565e[i6] == eVar.f21597b) {
                return this.f21567g[i6];
            }
            i6 = this.f21566f[i6];
        }
        return 0.0f;
    }

    public final int d() {
        return this.f21561a;
    }

    public final e e(int i6) {
        int i7 = this.f21568h;
        for (int i8 = 0; i7 != -1 && i8 < this.f21561a; i8++) {
            if (i8 == i6) {
                return ((e[]) this.f21563c.f743d)[this.f21565e[i7]];
            }
            i7 = this.f21566f[i7];
        }
        return null;
    }

    public final float f(int i6) {
        int i7 = this.f21568h;
        for (int i8 = 0; i7 != -1 && i8 < this.f21561a; i8++) {
            if (i8 == i6) {
                return this.f21567g[i7];
            }
            i7 = this.f21566f[i7];
        }
        return 0.0f;
    }

    public final void g(e eVar, float f6) {
        if (f6 == 0.0f) {
            h(eVar, true);
            return;
        }
        int i6 = this.f21568h;
        C2608b c2608b = this.f21562b;
        if (i6 == -1) {
            this.f21568h = 0;
            this.f21567g[0] = f6;
            this.f21565e[0] = eVar.f21597b;
            this.f21566f[0] = -1;
            eVar.f21605n++;
            eVar.a(c2608b);
            this.f21561a++;
            if (this.f21570j) {
                return;
            }
            int i7 = this.f21569i + 1;
            this.f21569i = i7;
            int[] iArr = this.f21565e;
            if (i7 >= iArr.length) {
                this.f21570j = true;
                this.f21569i = iArr.length - 1;
                return;
            }
            return;
        }
        int i8 = -1;
        for (int i9 = 0; i6 != -1 && i9 < this.f21561a; i9++) {
            int i10 = this.f21565e[i6];
            int i11 = eVar.f21597b;
            if (i10 == i11) {
                this.f21567g[i6] = f6;
                return;
            }
            if (i10 < i11) {
                i8 = i6;
            }
            i6 = this.f21566f[i6];
        }
        int length = this.f21569i;
        int i12 = length + 1;
        if (this.f21570j) {
            int[] iArr2 = this.f21565e;
            if (iArr2[length] != -1) {
                length = iArr2.length;
            }
        } else {
            length = i12;
        }
        int[] iArr3 = this.f21565e;
        if (length >= iArr3.length && this.f21561a < iArr3.length) {
            int i13 = 0;
            while (true) {
                int[] iArr4 = this.f21565e;
                if (i13 >= iArr4.length) {
                    break;
                }
                if (iArr4[i13] == -1) {
                    length = i13;
                    break;
                }
                i13++;
            }
        }
        int[] iArr5 = this.f21565e;
        if (length >= iArr5.length) {
            length = iArr5.length;
            int i14 = this.f21564d * 2;
            this.f21564d = i14;
            this.f21570j = false;
            this.f21569i = length - 1;
            this.f21567g = Arrays.copyOf(this.f21567g, i14);
            this.f21565e = Arrays.copyOf(this.f21565e, this.f21564d);
            this.f21566f = Arrays.copyOf(this.f21566f, this.f21564d);
        }
        this.f21565e[length] = eVar.f21597b;
        this.f21567g[length] = f6;
        if (i8 != -1) {
            int[] iArr6 = this.f21566f;
            iArr6[length] = iArr6[i8];
            iArr6[i8] = length;
        } else {
            this.f21566f[length] = this.f21568h;
            this.f21568h = length;
        }
        eVar.f21605n++;
        eVar.a(c2608b);
        int i15 = this.f21561a + 1;
        this.f21561a = i15;
        if (!this.f21570j) {
            this.f21569i++;
        }
        int[] iArr7 = this.f21565e;
        if (i15 >= iArr7.length) {
            this.f21570j = true;
        }
        if (this.f21569i >= iArr7.length) {
            this.f21570j = true;
            this.f21569i = iArr7.length - 1;
        }
    }

    public final float h(e eVar, boolean z6) {
        int i6 = this.f21568h;
        if (i6 == -1) {
            return 0.0f;
        }
        int i7 = 0;
        int i8 = -1;
        while (i6 != -1 && i7 < this.f21561a) {
            if (this.f21565e[i6] == eVar.f21597b) {
                if (i6 == this.f21568h) {
                    this.f21568h = this.f21566f[i6];
                } else {
                    int[] iArr = this.f21566f;
                    iArr[i8] = iArr[i6];
                }
                if (z6) {
                    eVar.b(this.f21562b);
                }
                eVar.f21605n--;
                this.f21561a--;
                this.f21565e[i6] = -1;
                if (this.f21570j) {
                    this.f21569i = i6;
                }
                return this.f21567g[i6];
            }
            i7++;
            i8 = i6;
            i6 = this.f21566f[i6];
        }
        return 0.0f;
    }

    public final String toString() {
        int i6 = this.f21568h;
        String string = "";
        for (int i7 = 0; i6 != -1 && i7 < this.f21561a; i7++) {
            StringBuilder sbT = o.t(o.n(string, " -> "));
            sbT.append(this.f21567g[i6]);
            sbT.append(" : ");
            StringBuilder sbT2 = o.t(sbT.toString());
            sbT2.append(((e[]) this.f21563c.f743d)[this.f21565e[i6]]);
            string = sbT2.toString();
            i6 = this.f21566f[i6];
        }
        return string;
    }
}
