package k;

import java.util.Arrays;
import java.util.Comparator;
import k.b;

/* JADX INFO: compiled from: PriorityGoalRow.java */
/* JADX INFO: loaded from: classes.dex */
public class h extends k.b {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f5126g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private i[] f5127h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private i[] f5128i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private int f5129j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    b f5130k;

    /* JADX INFO: compiled from: PriorityGoalRow.java */
    class a implements Comparator<i> {
        a(h hVar) {
        }

        @Override // java.util.Comparator
        /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
        public int compare(i iVar, i iVar2) {
            return iVar.f5136g - iVar2.f5136g;
        }
    }

    /* JADX INFO: compiled from: PriorityGoalRow.java */
    class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        i f5131a;

        public b(h hVar) {
        }

        public boolean a(i iVar, float f3) {
            boolean z2 = true;
            if (!this.f5131a.f5134e) {
                for (int i3 = 0; i3 < 9; i3++) {
                    float f4 = iVar.f5142m[i3];
                    if (f4 != 0.0f) {
                        float f5 = f4 * f3;
                        if (Math.abs(f5) < 1.0E-4f) {
                            f5 = 0.0f;
                        }
                        this.f5131a.f5142m[i3] = f5;
                    } else {
                        this.f5131a.f5142m[i3] = 0.0f;
                    }
                }
                return true;
            }
            for (int i4 = 0; i4 < 9; i4++) {
                float[] fArr = this.f5131a.f5142m;
                fArr[i4] = fArr[i4] + (iVar.f5142m[i4] * f3);
                if (Math.abs(fArr[i4]) < 1.0E-4f) {
                    this.f5131a.f5142m[i4] = 0.0f;
                } else {
                    z2 = false;
                }
            }
            if (z2) {
                h.this.G(this.f5131a);
            }
            return false;
        }

        public void b(i iVar) {
            this.f5131a = iVar;
        }

        public final boolean c() {
            for (int i3 = 8; i3 >= 0; i3--) {
                float f3 = this.f5131a.f5142m[i3];
                if (f3 > 0.0f) {
                    return false;
                }
                if (f3 < 0.0f) {
                    return true;
                }
            }
            return false;
        }

        public final boolean d(i iVar) {
            int i3 = 8;
            while (true) {
                if (i3 < 0) {
                    break;
                }
                float f3 = iVar.f5142m[i3];
                float f4 = this.f5131a.f5142m[i3];
                if (f4 == f3) {
                    i3--;
                } else if (f4 < f3) {
                    return true;
                }
            }
            return false;
        }

        public void e() {
            Arrays.fill(this.f5131a.f5142m, 0.0f);
        }

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

    public h(c cVar) {
        super(cVar);
        this.f5126g = 128;
        this.f5127h = new i[128];
        this.f5128i = new i[128];
        this.f5129j = 0;
        this.f5130k = new b(this);
    }

    private final void F(i iVar) {
        int i3;
        int i4 = this.f5129j + 1;
        i[] iVarArr = this.f5127h;
        if (i4 > iVarArr.length) {
            i[] iVarArr2 = (i[]) Arrays.copyOf(iVarArr, iVarArr.length * 2);
            this.f5127h = iVarArr2;
            this.f5128i = (i[]) Arrays.copyOf(iVarArr2, iVarArr2.length * 2);
        }
        i[] iVarArr3 = this.f5127h;
        int i5 = this.f5129j;
        iVarArr3[i5] = iVar;
        int i6 = i5 + 1;
        this.f5129j = i6;
        if (i6 > 1 && iVarArr3[i6 - 1].f5136g > iVar.f5136g) {
            int i7 = 0;
            while (true) {
                i3 = this.f5129j;
                if (i7 >= i3) {
                    break;
                }
                this.f5128i[i7] = this.f5127h[i7];
                i7++;
            }
            Arrays.sort(this.f5128i, 0, i3, new a(this));
            for (int i8 = 0; i8 < this.f5129j; i8++) {
                this.f5127h[i8] = this.f5128i[i8];
            }
        }
        iVar.f5134e = true;
        iVar.a(this);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void G(i iVar) {
        int i3 = 0;
        while (i3 < this.f5129j) {
            if (this.f5127h[i3] == iVar) {
                while (true) {
                    int i4 = this.f5129j;
                    if (i3 >= i4 - 1) {
                        this.f5129j = i4 - 1;
                        iVar.f5134e = false;
                        return;
                    } else {
                        i[] iVarArr = this.f5127h;
                        int i5 = i3 + 1;
                        iVarArr[i3] = iVarArr[i5];
                        i3 = i5;
                    }
                }
            } else {
                i3++;
            }
        }
    }

    @Override // k.b
    public void B(d dVar, k.b bVar, boolean z2) {
        i iVar = bVar.f5088a;
        if (iVar == null) {
            return;
        }
        b.a aVar = bVar.f5092e;
        int iK = aVar.k();
        for (int i3 = 0; i3 < iK; i3++) {
            i iVarE = aVar.e(i3);
            float fA = aVar.a(i3);
            this.f5130k.b(iVarE);
            if (this.f5130k.a(iVar, fA)) {
                F(iVarE);
            }
            this.f5089b += bVar.f5089b * fA;
        }
        G(iVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x002e  */
    @Override // k.b, k.d.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public k.i a(k.d r5, boolean[] r6) {
        /*
            r4 = this;
            r5 = -1
            r0 = 0
            r1 = r5
        L3:
            int r2 = r4.f5129j
            if (r0 >= r2) goto L32
            k.i[] r2 = r4.f5127h
            r2 = r2[r0]
            int r3 = r2.f5136g
            boolean r3 = r6[r3]
            if (r3 == 0) goto L12
            goto L2f
        L12:
            k.h$b r3 = r4.f5130k
            r3.b(r2)
            if (r1 != r5) goto L22
            k.h$b r2 = r4.f5130k
            boolean r2 = r2.c()
            if (r2 == 0) goto L2f
            goto L2e
        L22:
            k.h$b r2 = r4.f5130k
            k.i[] r3 = r4.f5127h
            r3 = r3[r1]
            boolean r2 = r2.d(r3)
            if (r2 == 0) goto L2f
        L2e:
            r1 = r0
        L2f:
            int r0 = r0 + 1
            goto L3
        L32:
            if (r1 != r5) goto L36
            r4 = 0
            return r4
        L36:
            k.i[] r4 = r4.f5127h
            r4 = r4[r1]
            return r4
        */
        throw new UnsupportedOperationException("Method not decompiled: k.h.a(k.d, boolean[]):k.i");
    }

    @Override // k.b, k.d.a
    public void c(i iVar) {
        this.f5130k.b(iVar);
        this.f5130k.e();
        iVar.f5142m[iVar.f5138i] = 1.0f;
        F(iVar);
    }

    @Override // k.b, k.d.a
    public void clear() {
        this.f5129j = 0;
        this.f5089b = 0.0f;
    }

    @Override // k.b, k.d.a
    public boolean isEmpty() {
        return this.f5129j == 0;
    }

    @Override // k.b
    public String toString() {
        String str = " goal -> (" + this.f5089b + ") : ";
        for (int i3 = 0; i3 < this.f5129j; i3++) {
            this.f5130k.b(this.f5127h[i3]);
            str = str + this.f5130k + " ";
        }
        return str;
    }
}
