package android.support.constraint.i;

import android.support.constraint.i.i;
import java.util.Arrays;

/* JADX INFO: compiled from: ArrayLinkedVariables.java */
/* JADX INFO: loaded from: classes.dex */
public class a {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final b f409b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final c f410c;

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private i f412e = null;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private int[] f413f = new int[8];
    private int[] g = new int[8];
    private float[] h = new float[8];
    private int i = -1;
    private int j = -1;
    private boolean k = false;

    a(b bVar, c cVar) {
        this.f409b = bVar;
        this.f410c = cVar;
    }

    private boolean k(i iVar, e eVar) {
        return iVar.j <= 1;
    }

    final void a(i iVar, float f2, boolean z) {
        if (f2 == 0.0f) {
            return;
        }
        int i = this.i;
        if (i == -1) {
            this.i = 0;
            this.h[0] = f2;
            this.f413f[0] = iVar.f437b;
            this.g[0] = -1;
            iVar.j++;
            iVar.a(this.f409b);
            this.f408a++;
            if (this.k) {
                return;
            }
            int i2 = this.j + 1;
            this.j = i2;
            int[] iArr = this.f413f;
            if (i2 >= iArr.length) {
                this.k = true;
                this.j = iArr.length - 1;
                return;
            }
            return;
        }
        int i3 = -1;
        for (int i4 = 0; i != -1 && i4 < this.f408a; i4++) {
            int[] iArr2 = this.f413f;
            int i5 = iArr2[i];
            int i6 = iVar.f437b;
            if (i5 == i6) {
                float[] fArr = this.h;
                fArr[i] = fArr[i] + f2;
                if (fArr[i] == 0.0f) {
                    if (i == this.i) {
                        this.i = this.g[i];
                    } else {
                        int[] iArr3 = this.g;
                        iArr3[i3] = iArr3[i];
                    }
                    if (z) {
                        iVar.c(this.f409b);
                    }
                    if (this.k) {
                        this.j = i;
                    }
                    iVar.j--;
                    this.f408a--;
                    return;
                }
                return;
            }
            if (iArr2[i] < i6) {
                i3 = i;
            }
            i = this.g[i];
        }
        int length = this.j;
        int i7 = length + 1;
        if (this.k) {
            int[] iArr4 = this.f413f;
            if (iArr4[length] != -1) {
                length = iArr4.length;
            }
        } else {
            length = i7;
        }
        int[] iArr5 = this.f413f;
        if (length >= iArr5.length && this.f408a < iArr5.length) {
            int i8 = 0;
            while (true) {
                int[] iArr6 = this.f413f;
                if (i8 >= iArr6.length) {
                    break;
                }
                if (iArr6[i8] == -1) {
                    length = i8;
                    break;
                }
                i8++;
            }
        }
        int[] iArr7 = this.f413f;
        if (length >= iArr7.length) {
            length = iArr7.length;
            int i9 = this.f411d * 2;
            this.f411d = i9;
            this.k = false;
            this.j = length - 1;
            this.h = Arrays.copyOf(this.h, i9);
            this.f413f = Arrays.copyOf(this.f413f, this.f411d);
            this.g = Arrays.copyOf(this.g, this.f411d);
        }
        this.f413f[length] = iVar.f437b;
        this.h[length] = f2;
        if (i3 != -1) {
            int[] iArr8 = this.g;
            iArr8[length] = iArr8[i3];
            iArr8[i3] = length;
        } else {
            this.g[length] = this.i;
            this.i = length;
        }
        iVar.j++;
        iVar.a(this.f409b);
        this.f408a++;
        if (!this.k) {
            this.j++;
        }
        int i10 = this.j;
        int[] iArr9 = this.f413f;
        if (i10 >= iArr9.length) {
            this.k = true;
            this.j = iArr9.length - 1;
        }
    }

    i b(e eVar) {
        int i = this.i;
        i iVar = null;
        boolean z = false;
        boolean z2 = false;
        float f2 = 0.0f;
        float f3 = 0.0f;
        i iVar2 = null;
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            float[] fArr = this.h;
            float f4 = fArr[i];
            i iVar3 = this.f410c.f421c[this.f413f[i]];
            if (f4 < 0.0f) {
                if (f4 > -0.001f) {
                    fArr[i] = 0.0f;
                    iVar3.c(this.f409b);
                    f4 = 0.0f;
                }
            } else if (f4 < 0.001f) {
                fArr[i] = 0.0f;
                iVar3.c(this.f409b);
                f4 = 0.0f;
            }
            if (f4 != 0.0f) {
                if (iVar3.g == i.a.UNRESTRICTED) {
                    if (iVar2 == null || f2 > f4) {
                        boolean zK = k(iVar3, eVar);
                        z = zK;
                        f2 = f4;
                        iVar2 = iVar3;
                    } else if (!z && k(iVar3, eVar)) {
                        f2 = f4;
                        z = true;
                        iVar2 = iVar3;
                    }
                } else if (iVar2 == null && f4 < 0.0f) {
                    if (iVar == null || f3 > f4) {
                        boolean zK2 = k(iVar3, eVar);
                        z2 = zK2;
                        f3 = f4;
                        iVar = iVar3;
                    } else if (!z2 && k(iVar3, eVar)) {
                        f3 = f4;
                        z2 = true;
                        iVar = iVar3;
                    }
                }
            }
            i = this.g[i];
        }
        return iVar2 != null ? iVar2 : iVar;
    }

    public final void c() {
        int i = this.i;
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            i iVar = this.f410c.f421c[this.f413f[i]];
            if (iVar != null) {
                iVar.c(this.f409b);
            }
            i = this.g[i];
        }
        this.i = -1;
        this.j = -1;
        this.k = false;
        this.f408a = 0;
    }

    final boolean d(i iVar) {
        int i = this.i;
        if (i == -1) {
            return false;
        }
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            if (this.f413f[i] == iVar.f437b) {
                return true;
            }
            i = this.g[i];
        }
        return false;
    }

    void e(float f2) {
        int i = this.i;
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            float[] fArr = this.h;
            fArr[i] = fArr[i] / f2;
            i = this.g[i];
        }
    }

    public final float f(i iVar) {
        int i = this.i;
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            if (this.f413f[i] == iVar.f437b) {
                return this.h[i];
            }
            i = this.g[i];
        }
        return 0.0f;
    }

    i g(boolean[] zArr, i iVar) {
        i.a aVar;
        int i = this.i;
        i iVar2 = null;
        float f2 = 0.0f;
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            if (this.h[i] < 0.0f) {
                i iVar3 = this.f410c.f421c[this.f413f[i]];
                if ((zArr == null || !zArr[iVar3.f437b]) && iVar3 != iVar && ((aVar = iVar3.g) == i.a.SLACK || aVar == i.a.ERROR)) {
                    float f3 = this.h[i];
                    if (f3 < f2) {
                        iVar2 = iVar3;
                        f2 = f3;
                    }
                }
            }
            i = this.g[i];
        }
        return iVar2;
    }

    final i h(int i) {
        int i2 = this.i;
        for (int i3 = 0; i2 != -1 && i3 < this.f408a; i3++) {
            if (i3 == i) {
                return this.f410c.f421c[this.f413f[i2]];
            }
            i2 = this.g[i2];
        }
        return null;
    }

    final float i(int i) {
        int i2 = this.i;
        for (int i3 = 0; i2 != -1 && i3 < this.f408a; i3++) {
            if (i3 == i) {
                return this.h[i2];
            }
            i2 = this.g[i2];
        }
        return 0.0f;
    }

    void j() {
        int i = this.i;
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            float[] fArr = this.h;
            fArr[i] = fArr[i] * (-1.0f);
            i = this.g[i];
        }
    }

    public final void l(i iVar, float f2) {
        if (f2 == 0.0f) {
            m(iVar, true);
            return;
        }
        int i = this.i;
        if (i == -1) {
            this.i = 0;
            this.h[0] = f2;
            this.f413f[0] = iVar.f437b;
            this.g[0] = -1;
            iVar.j++;
            iVar.a(this.f409b);
            this.f408a++;
            if (this.k) {
                return;
            }
            int i2 = this.j + 1;
            this.j = i2;
            int[] iArr = this.f413f;
            if (i2 >= iArr.length) {
                this.k = true;
                this.j = iArr.length - 1;
                return;
            }
            return;
        }
        int i3 = -1;
        for (int i4 = 0; i != -1 && i4 < this.f408a; i4++) {
            int[] iArr2 = this.f413f;
            int i5 = iArr2[i];
            int i6 = iVar.f437b;
            if (i5 == i6) {
                this.h[i] = f2;
                return;
            }
            if (iArr2[i] < i6) {
                i3 = i;
            }
            i = this.g[i];
        }
        int length = this.j;
        int i7 = length + 1;
        if (this.k) {
            int[] iArr3 = this.f413f;
            if (iArr3[length] != -1) {
                length = iArr3.length;
            }
        } else {
            length = i7;
        }
        int[] iArr4 = this.f413f;
        if (length >= iArr4.length && this.f408a < iArr4.length) {
            int i8 = 0;
            while (true) {
                int[] iArr5 = this.f413f;
                if (i8 >= iArr5.length) {
                    break;
                }
                if (iArr5[i8] == -1) {
                    length = i8;
                    break;
                }
                i8++;
            }
        }
        int[] iArr6 = this.f413f;
        if (length >= iArr6.length) {
            length = iArr6.length;
            int i9 = this.f411d * 2;
            this.f411d = i9;
            this.k = false;
            this.j = length - 1;
            this.h = Arrays.copyOf(this.h, i9);
            this.f413f = Arrays.copyOf(this.f413f, this.f411d);
            this.g = Arrays.copyOf(this.g, this.f411d);
        }
        this.f413f[length] = iVar.f437b;
        this.h[length] = f2;
        if (i3 != -1) {
            int[] iArr7 = this.g;
            iArr7[length] = iArr7[i3];
            iArr7[i3] = length;
        } else {
            this.g[length] = this.i;
            this.i = length;
        }
        iVar.j++;
        iVar.a(this.f409b);
        this.f408a++;
        if (!this.k) {
            this.j++;
        }
        if (this.f408a >= this.f413f.length) {
            this.k = true;
        }
        int i10 = this.j;
        int[] iArr8 = this.f413f;
        if (i10 >= iArr8.length) {
            this.k = true;
            this.j = iArr8.length - 1;
        }
    }

    public final float m(i iVar, boolean z) {
        if (this.f412e == iVar) {
            this.f412e = null;
        }
        int i = this.i;
        if (i == -1) {
            return 0.0f;
        }
        int i2 = 0;
        int i3 = -1;
        while (i != -1 && i2 < this.f408a) {
            if (this.f413f[i] == iVar.f437b) {
                if (i == this.i) {
                    this.i = this.g[i];
                } else {
                    int[] iArr = this.g;
                    iArr[i3] = iArr[i];
                }
                if (z) {
                    iVar.c(this.f409b);
                }
                iVar.j--;
                this.f408a--;
                this.f413f[i] = -1;
                if (this.k) {
                    this.j = i;
                }
                return this.h[i];
            }
            i2++;
            i3 = i;
            i = this.g[i];
        }
        return 0.0f;
    }

    final void n(b bVar, b bVar2, boolean z) {
        int i = this.i;
        while (true) {
            for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
                int i3 = this.f413f[i];
                i iVar = bVar2.f414a;
                if (i3 == iVar.f437b) {
                    float f2 = this.h[i];
                    m(iVar, z);
                    a aVar = bVar2.f417d;
                    int i4 = aVar.i;
                    for (int i5 = 0; i4 != -1 && i5 < aVar.f408a; i5++) {
                        a(this.f410c.f421c[aVar.f413f[i4]], aVar.h[i4] * f2, z);
                        i4 = aVar.g[i4];
                    }
                    bVar.f415b += bVar2.f415b * f2;
                    if (z) {
                        bVar2.f414a.c(bVar);
                    }
                    i = this.i;
                } else {
                    i = this.g[i];
                }
            }
            return;
        }
    }

    void o(b bVar, b[] bVarArr) {
        int i = this.i;
        while (true) {
            for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
                i iVar = this.f410c.f421c[this.f413f[i]];
                if (iVar.f438c != -1) {
                    float f2 = this.h[i];
                    m(iVar, true);
                    b bVar2 = bVarArr[iVar.f438c];
                    if (!bVar2.f418e) {
                        a aVar = bVar2.f417d;
                        int i3 = aVar.i;
                        for (int i4 = 0; i3 != -1 && i4 < aVar.f408a; i4++) {
                            a(this.f410c.f421c[aVar.f413f[i3]], aVar.h[i3] * f2, true);
                            i3 = aVar.g[i3];
                        }
                    }
                    bVar.f415b += bVar2.f415b * f2;
                    bVar2.f414a.c(bVar);
                    i = this.i;
                } else {
                    i = this.g[i];
                }
            }
            return;
        }
    }

    public String toString() {
        int i = this.i;
        String str = "";
        for (int i2 = 0; i != -1 && i2 < this.f408a; i2++) {
            str = ((str + " -> ") + this.h[i] + " : ") + this.f410c.f421c[this.f413f[i]];
            i = this.g[i];
        }
        return str;
    }
}
