package p040n;

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

/* renamed from: n.h */
/* loaded from: classes.dex */
public class C1488h extends C1479b {

    /* renamed from: g */
    public int f3278g;

    /* renamed from: h */
    public C1491i[] f3279h;

    /* renamed from: i */
    public C1491i[] f3280i;

    /* renamed from: j */
    public int f3281j;

    /* renamed from: k */
    public C1490b f3282k;

    /* renamed from: l */
    public C1481c f3283l;

    /* renamed from: n.h$a */
    /* loaded from: classes.dex */
    public class C1489a implements Comparator<C1491i> {
        public C1489a() {
        }

        @Override // java.util.Comparator
        /* renamed from: a */
        public int compare(C1491i c1491i, C1491i c1491i2) {
            return c1491i.f3291f - c1491i2.f3291f;
        }
    }

    /* renamed from: n.h$b */
    /* loaded from: classes.dex */
    public class C1490b {

        /* renamed from: a */
        public C1491i f3285a;

        /* renamed from: b */
        public C1488h f3286b;

        public C1490b(C1488h c1488h) {
            this.f3286b = c1488h;
        }

        /* renamed from: a */
        public boolean m1202a(C1491i c1491i, float f) {
            boolean z = true;
            if (!this.f3285a.f3289d) {
                for (int i = 0; i < 9; i++) {
                    float f2 = c1491i.f3297l[i];
                    if (f2 != 0.0f) {
                        float f3 = f2 * f;
                        if (Math.abs(f3) < 1.0E-4f) {
                            f3 = 0.0f;
                        }
                        this.f3285a.f3297l[i] = f3;
                    } else {
                        this.f3285a.f3297l[i] = 0.0f;
                    }
                }
                return true;
            }
            for (int i2 = 0; i2 < 9; i2++) {
                float[] fArr = this.f3285a.f3297l;
                float f4 = fArr[i2] + (c1491i.f3297l[i2] * f);
                fArr[i2] = f4;
                if (Math.abs(f4) < 1.0E-4f) {
                    this.f3285a.f3297l[i2] = 0.0f;
                } else {
                    z = false;
                }
            }
            if (z) {
                C1488h.this.m1206G(this.f3285a);
            }
            return false;
        }

        /* renamed from: b */
        public void m1201b(C1491i c1491i) {
            this.f3285a = c1491i;
        }

        /* renamed from: c */
        public final boolean m1200c() {
            for (int i = 8; i >= 0; i--) {
                float f = this.f3285a.f3297l[i];
                if (f > 0.0f) {
                    return false;
                }
                if (f < 0.0f) {
                    return true;
                }
            }
            return false;
        }

        /* renamed from: d */
        public final boolean m1199d(C1491i c1491i) {
            int i = 8;
            while (true) {
                if (i < 0) {
                    break;
                }
                float f = c1491i.f3297l[i];
                float f2 = this.f3285a.f3297l[i];
                if (f2 == f) {
                    i--;
                } else if (f2 < f) {
                    return true;
                }
            }
            return false;
        }

        /* renamed from: e */
        public void m1198e() {
            Arrays.fill(this.f3285a.f3297l, 0.0f);
        }

        public String toString() {
            String str = "[ ";
            if (this.f3285a != null) {
                for (int i = 0; i < 9; i++) {
                    str = str + this.f3285a.f3297l[i] + " ";
                }
            }
            return str + "] " + this.f3285a;
        }
    }

    public C1488h(C1481c c1481c) {
        super(c1481c);
        this.f3278g = 128;
        this.f3279h = new C1491i[128];
        this.f3280i = new C1491i[128];
        this.f3281j = 0;
        this.f3282k = new C1490b(this);
        this.f3283l = c1481c;
    }

    @Override // p040n.C1479b
    /* renamed from: B */
    public void mo1209B(C1482d c1482d, C1479b c1479b, boolean z) {
        C1491i c1491i = c1479b.f3240a;
        if (c1491i == null) {
            return;
        }
        C1479b.InterfaceC1480a interfaceC1480a = c1479b.f3244e;
        int mo1179k = interfaceC1480a.mo1179k();
        for (int i = 0; i < mo1179k; i++) {
            C1491i mo1184f = interfaceC1480a.mo1184f(i);
            float mo1189a = interfaceC1480a.mo1189a(i);
            this.f3282k.m1201b(mo1184f);
            if (this.f3282k.m1202a(c1491i, mo1189a)) {
                m1207F(mo1184f);
            }
            this.f3241b += c1479b.f3241b * mo1189a;
        }
        m1206G(c1491i);
    }

    /* renamed from: F */
    public final void m1207F(C1491i c1491i) {
        int i;
        int i2 = this.f3281j + 1;
        C1491i[] c1491iArr = this.f3279h;
        if (i2 > c1491iArr.length) {
            C1491i[] c1491iArr2 = (C1491i[]) Arrays.copyOf(c1491iArr, c1491iArr.length * 2);
            this.f3279h = c1491iArr2;
            this.f3280i = (C1491i[]) Arrays.copyOf(c1491iArr2, c1491iArr2.length * 2);
        }
        C1491i[] c1491iArr3 = this.f3279h;
        int i3 = this.f3281j;
        c1491iArr3[i3] = c1491i;
        int i4 = i3 + 1;
        this.f3281j = i4;
        if (i4 > 1 && c1491iArr3[i4 - 1].f3291f > c1491i.f3291f) {
            int i5 = 0;
            while (true) {
                i = this.f3281j;
                if (i5 >= i) {
                    break;
                }
                this.f3280i[i5] = this.f3279h[i5];
                i5++;
            }
            Arrays.sort(this.f3280i, 0, i, new C1489a());
            for (int i6 = 0; i6 < this.f3281j; i6++) {
                this.f3279h[i6] = this.f3280i[i6];
            }
        }
        c1491i.f3289d = true;
        c1491i.m1197a(this);
    }

    /* renamed from: G */
    public final void m1206G(C1491i c1491i) {
        int i = 0;
        while (i < this.f3281j) {
            if (this.f3279h[i] == c1491i) {
                while (true) {
                    int i2 = this.f3281j;
                    if (i >= i2 - 1) {
                        this.f3281j = i2 - 1;
                        c1491i.f3289d = false;
                        return;
                    }
                    C1491i[] c1491iArr = this.f3279h;
                    int i3 = i + 1;
                    c1491iArr[i] = c1491iArr[i3];
                    i = i3;
                }
            } else {
                i++;
            }
        }
    }

    @Override // p040n.C1479b, p040n.C1482d.InterfaceC1483a
    /* renamed from: a */
    public C1491i mo1205a(C1482d c1482d, boolean[] zArr) {
        int i = -1;
        for (int i2 = 0; i2 < this.f3281j; i2++) {
            C1491i c1491i = this.f3279h[i2];
            if (!zArr[c1491i.f3291f]) {
                this.f3282k.m1201b(c1491i);
                C1490b c1490b = this.f3282k;
                if (i == -1) {
                    if (!c1490b.m1200c()) {
                    }
                    i = i2;
                } else {
                    if (!c1490b.m1199d(this.f3279h[i])) {
                    }
                    i = i2;
                }
            }
        }
        if (i == -1) {
            return null;
        }
        return this.f3279h[i];
    }

    @Override // p040n.C1479b, p040n.C1482d.InterfaceC1483a
    /* renamed from: b */
    public void mo1204b(C1491i c1491i) {
        this.f3282k.m1201b(c1491i);
        this.f3282k.m1198e();
        c1491i.f3297l[c1491i.f3293h] = 1.0f;
        m1207F(c1491i);
    }

    @Override // p040n.C1479b, p040n.C1482d.InterfaceC1483a
    public void clear() {
        this.f3281j = 0;
        this.f3241b = 0.0f;
    }

    @Override // p040n.C1479b, p040n.C1482d.InterfaceC1483a
    public boolean isEmpty() {
        return this.f3281j == 0;
    }

    @Override // p040n.C1479b
    public String toString() {
        String str = " goal -> (" + this.f3241b + ") : ";
        for (int i = 0; i < this.f3281j; i++) {
            this.f3282k.m1201b(this.f3279h[i]);
            str = str + this.f3282k + " ";
        }
        return str;
    }
}