package u;

import com.google.android.gms.measurement.internal.u1;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class b implements c {

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

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

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

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

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

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

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

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

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

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

    public b(d dVar, e eVar) {
        this.f33111b = dVar;
        this.f33112c = eVar;
    }

    @Override // u.c
    public final float a(d dVar, boolean z10) {
        float fI = i(dVar.f33120a);
        g(dVar.f33120a, z10);
        c cVar = dVar.f33123d;
        int iB = cVar.b();
        for (int i10 = 0; i10 < iB; i10++) {
            k kVarD = cVar.d(i10);
            h(kVarD, cVar.i(kVarD) * fI, z10);
        }
        return fI;
    }

    @Override // u.c
    public final int b() {
        return this.f33110a;
    }

    @Override // u.c
    public final boolean c(k kVar) {
        int i10 = this.f33117h;
        if (i10 == -1) {
            return false;
        }
        for (int i11 = 0; i10 != -1 && i11 < this.f33110a; i11++) {
            if (this.f33114e[i10] == kVar.f33156b) {
                return true;
            }
            i10 = this.f33115f[i10];
        }
        return false;
    }

    @Override // u.c
    public final void clear() {
        int i10 = this.f33117h;
        for (int i11 = 0; i10 != -1 && i11 < this.f33110a; i11++) {
            k kVar = ((k[]) this.f33112c.f33128d)[this.f33114e[i10]];
            if (kVar != null) {
                kVar.b(this.f33111b);
            }
            i10 = this.f33115f[i10];
        }
        this.f33117h = -1;
        this.f33118i = -1;
        this.f33119j = false;
        this.f33110a = 0;
    }

    @Override // u.c
    public final k d(int i10) {
        int i11 = this.f33117h;
        for (int i12 = 0; i11 != -1 && i12 < this.f33110a; i12++) {
            if (i12 == i10) {
                return ((k[]) this.f33112c.f33128d)[this.f33114e[i11]];
            }
            i11 = this.f33115f[i11];
        }
        return null;
    }

    @Override // u.c
    public final void e() {
        int i10 = this.f33117h;
        for (int i11 = 0; i10 != -1 && i11 < this.f33110a; i11++) {
            float[] fArr = this.f33116g;
            fArr[i10] = fArr[i10] * (-1.0f);
            i10 = this.f33115f[i10];
        }
    }

    @Override // u.c
    public final float f(int i10) {
        int i11 = this.f33117h;
        for (int i12 = 0; i11 != -1 && i12 < this.f33110a; i12++) {
            if (i12 == i10) {
                return this.f33116g[i11];
            }
            i11 = this.f33115f[i11];
        }
        return 0.0f;
    }

    @Override // u.c
    public final float g(k kVar, boolean z10) {
        int i10 = this.f33117h;
        if (i10 == -1) {
            return 0.0f;
        }
        int i11 = 0;
        int i12 = -1;
        while (i10 != -1 && i11 < this.f33110a) {
            if (this.f33114e[i10] == kVar.f33156b) {
                if (i10 == this.f33117h) {
                    this.f33117h = this.f33115f[i10];
                } else {
                    int[] iArr = this.f33115f;
                    iArr[i12] = iArr[i10];
                }
                if (z10) {
                    kVar.b(this.f33111b);
                }
                kVar.f33166l--;
                this.f33110a--;
                this.f33114e[i10] = -1;
                if (this.f33119j) {
                    this.f33118i = i10;
                }
                return this.f33116g[i10];
            }
            i11++;
            i12 = i10;
            i10 = this.f33115f[i10];
        }
        return 0.0f;
    }

    @Override // u.c
    public final void h(k kVar, float f10, boolean z10) {
        if (f10 <= -0.001f || f10 >= 0.001f) {
            int i10 = this.f33117h;
            d dVar = this.f33111b;
            if (i10 == -1) {
                this.f33117h = 0;
                this.f33116g[0] = f10;
                this.f33114e[0] = kVar.f33156b;
                this.f33115f[0] = -1;
                kVar.f33166l++;
                kVar.a(dVar);
                this.f33110a++;
                if (this.f33119j) {
                    return;
                }
                int i11 = this.f33118i + 1;
                this.f33118i = i11;
                int[] iArr = this.f33114e;
                if (i11 >= iArr.length) {
                    this.f33119j = true;
                    this.f33118i = iArr.length - 1;
                    return;
                }
                return;
            }
            int i12 = -1;
            for (int i13 = 0; i10 != -1 && i13 < this.f33110a; i13++) {
                int i14 = this.f33114e[i10];
                int i15 = kVar.f33156b;
                if (i14 == i15) {
                    float[] fArr = this.f33116g;
                    float f11 = fArr[i10] + f10;
                    if (f11 > -0.001f && f11 < 0.001f) {
                        f11 = 0.0f;
                    }
                    fArr[i10] = f11;
                    if (f11 == 0.0f) {
                        if (i10 == this.f33117h) {
                            this.f33117h = this.f33115f[i10];
                        } else {
                            int[] iArr2 = this.f33115f;
                            iArr2[i12] = iArr2[i10];
                        }
                        if (z10) {
                            kVar.b(dVar);
                        }
                        if (this.f33119j) {
                            this.f33118i = i10;
                        }
                        kVar.f33166l--;
                        this.f33110a--;
                        return;
                    }
                    return;
                }
                if (i14 < i15) {
                    i12 = i10;
                }
                i10 = this.f33115f[i10];
            }
            int length = this.f33118i;
            int i16 = length + 1;
            if (this.f33119j) {
                int[] iArr3 = this.f33114e;
                if (iArr3[length] != -1) {
                    length = iArr3.length;
                }
            } else {
                length = i16;
            }
            int[] iArr4 = this.f33114e;
            if (length >= iArr4.length && this.f33110a < iArr4.length) {
                int i17 = 0;
                while (true) {
                    int[] iArr5 = this.f33114e;
                    if (i17 >= iArr5.length) {
                        break;
                    }
                    if (iArr5[i17] == -1) {
                        length = i17;
                        break;
                    }
                    i17++;
                }
            }
            int[] iArr6 = this.f33114e;
            if (length >= iArr6.length) {
                length = iArr6.length;
                int i18 = this.f33113d * 2;
                this.f33113d = i18;
                this.f33119j = false;
                this.f33118i = length - 1;
                this.f33116g = Arrays.copyOf(this.f33116g, i18);
                this.f33114e = Arrays.copyOf(this.f33114e, this.f33113d);
                this.f33115f = Arrays.copyOf(this.f33115f, this.f33113d);
            }
            this.f33114e[length] = kVar.f33156b;
            this.f33116g[length] = f10;
            if (i12 != -1) {
                int[] iArr7 = this.f33115f;
                iArr7[length] = iArr7[i12];
                iArr7[i12] = length;
            } else {
                this.f33115f[length] = this.f33117h;
                this.f33117h = length;
            }
            kVar.f33166l++;
            kVar.a(dVar);
            this.f33110a++;
            if (!this.f33119j) {
                this.f33118i++;
            }
            int i19 = this.f33118i;
            int[] iArr8 = this.f33114e;
            if (i19 >= iArr8.length) {
                this.f33119j = true;
                this.f33118i = iArr8.length - 1;
            }
        }
    }

    @Override // u.c
    public final float i(k kVar) {
        int i10 = this.f33117h;
        for (int i11 = 0; i10 != -1 && i11 < this.f33110a; i11++) {
            if (this.f33114e[i10] == kVar.f33156b) {
                return this.f33116g[i10];
            }
            i10 = this.f33115f[i10];
        }
        return 0.0f;
    }

    @Override // u.c
    public final void j(k kVar, float f10) {
        if (f10 == 0.0f) {
            g(kVar, true);
            return;
        }
        int i10 = this.f33117h;
        d dVar = this.f33111b;
        if (i10 == -1) {
            this.f33117h = 0;
            this.f33116g[0] = f10;
            this.f33114e[0] = kVar.f33156b;
            this.f33115f[0] = -1;
            kVar.f33166l++;
            kVar.a(dVar);
            this.f33110a++;
            if (this.f33119j) {
                return;
            }
            int i11 = this.f33118i + 1;
            this.f33118i = i11;
            int[] iArr = this.f33114e;
            if (i11 >= iArr.length) {
                this.f33119j = true;
                this.f33118i = iArr.length - 1;
                return;
            }
            return;
        }
        int i12 = -1;
        for (int i13 = 0; i10 != -1 && i13 < this.f33110a; i13++) {
            int i14 = this.f33114e[i10];
            int i15 = kVar.f33156b;
            if (i14 == i15) {
                this.f33116g[i10] = f10;
                return;
            }
            if (i14 < i15) {
                i12 = i10;
            }
            i10 = this.f33115f[i10];
        }
        int length = this.f33118i;
        int i16 = length + 1;
        if (this.f33119j) {
            int[] iArr2 = this.f33114e;
            if (iArr2[length] != -1) {
                length = iArr2.length;
            }
        } else {
            length = i16;
        }
        int[] iArr3 = this.f33114e;
        if (length >= iArr3.length && this.f33110a < iArr3.length) {
            int i17 = 0;
            while (true) {
                int[] iArr4 = this.f33114e;
                if (i17 >= iArr4.length) {
                    break;
                }
                if (iArr4[i17] == -1) {
                    length = i17;
                    break;
                }
                i17++;
            }
        }
        int[] iArr5 = this.f33114e;
        if (length >= iArr5.length) {
            length = iArr5.length;
            int i18 = this.f33113d * 2;
            this.f33113d = i18;
            this.f33119j = false;
            this.f33118i = length - 1;
            this.f33116g = Arrays.copyOf(this.f33116g, i18);
            this.f33114e = Arrays.copyOf(this.f33114e, this.f33113d);
            this.f33115f = Arrays.copyOf(this.f33115f, this.f33113d);
        }
        this.f33114e[length] = kVar.f33156b;
        this.f33116g[length] = f10;
        if (i12 != -1) {
            int[] iArr6 = this.f33115f;
            iArr6[length] = iArr6[i12];
            iArr6[i12] = length;
        } else {
            this.f33115f[length] = this.f33117h;
            this.f33117h = length;
        }
        kVar.f33166l++;
        kVar.a(dVar);
        int i19 = this.f33110a + 1;
        this.f33110a = i19;
        if (!this.f33119j) {
            this.f33118i++;
        }
        int[] iArr7 = this.f33114e;
        if (i19 >= iArr7.length) {
            this.f33119j = true;
        }
        if (this.f33118i >= iArr7.length) {
            this.f33119j = true;
            this.f33118i = iArr7.length - 1;
        }
    }

    @Override // u.c
    public final void k(float f10) {
        int i10 = this.f33117h;
        for (int i11 = 0; i10 != -1 && i11 < this.f33110a; i11++) {
            float[] fArr = this.f33116g;
            fArr[i10] = fArr[i10] / f10;
            i10 = this.f33115f[i10];
        }
    }

    public final String toString() {
        int i10 = this.f33117h;
        String string = "";
        for (int i11 = 0; i10 != -1 && i11 < this.f33110a; i11++) {
            StringBuilder sbC = a.c(u1.j(string, " -> "));
            sbC.append(this.f33116g[i10]);
            sbC.append(" : ");
            StringBuilder sbC2 = a.c(sbC.toString());
            sbC2.append(((k[]) this.f33112c.f33128d)[this.f33114e[i10]]);
            string = sbC2.toString();
            i10 = this.f33115f[i10];
        }
        return string;
    }
}
