package androidx.constraintlayout.solver; import androidx.constraintlayout.solver.ArrayRow; import c.d.b.a.a; import java.io.PrintStream; import java.util.Arrays; public class SolverVariableValues implements ArrayRow.ArrayRowVariables { private static final boolean DEBUG = false; private static final boolean HASH = true; private static float epsilon = 0.001f; private int HASH_SIZE = 16; private final int NONE = -1; private int SIZE = 16; public int head = -1; public int[] keys = new int[16]; public final Cache mCache; public int mCount = 0; private final ArrayRow mRow; public int[] next = new int[16]; public int[] nextKeys = new int[16]; public int[] previous = new int[16]; public float[] values = new float[16]; public int[] variables = new int[16]; public SolverVariableValues(ArrayRow arrayRow, Cache cache) { this.mRow = arrayRow; this.mCache = cache; clear(); } private void addToHashMap(SolverVariable solverVariable, int i) { int[] iArr; int i2 = solverVariable.f21id % this.HASH_SIZE; int[] iArr2 = this.keys; int i3 = iArr2[i2]; if (i3 == -1) { iArr2[i2] = i; } else { while (true) { iArr = this.nextKeys; if (iArr[i3] == -1) { break; } i3 = iArr[i3]; } iArr[i3] = i; } this.nextKeys[i] = -1; } private void addVariable(int i, SolverVariable solverVariable, float f) { this.variables[i] = solverVariable.f21id; this.values[i] = f; this.previous[i] = -1; this.next[i] = -1; solverVariable.addToRow(this.mRow); solverVariable.usageInRowCount++; this.mCount++; } private void displayHash() { for (int i = 0; i < this.HASH_SIZE; i++) { if (this.keys[i] != -1) { String str = hashCode() + " hash [" + i + "] => "; int i2 = this.keys[i]; boolean z2 = false; while (!z2) { StringBuilder P = a.P(str, " "); P.append(this.variables[i2]); str = P.toString(); int[] iArr = this.nextKeys; if (iArr[i2] != -1) { i2 = iArr[i2]; } else { z2 = true; } } System.out.println(str); } } } private int findEmptySlot() { for (int i = 0; i < this.SIZE; i++) { if (this.variables[i] == -1) { return i; } } return -1; } private void increaseSize() { int i = this.SIZE * 2; this.variables = Arrays.copyOf(this.variables, i); this.values = Arrays.copyOf(this.values, i); this.previous = Arrays.copyOf(this.previous, i); this.next = Arrays.copyOf(this.next, i); this.nextKeys = Arrays.copyOf(this.nextKeys, i); for (int i2 = this.SIZE; i2 < i; i2++) { this.variables[i2] = -1; this.nextKeys[i2] = -1; } this.SIZE = i; } private void insertVariable(int i, SolverVariable solverVariable, float f) { int findEmptySlot = findEmptySlot(); addVariable(findEmptySlot, solverVariable, f); if (i != -1) { this.previous[findEmptySlot] = i; int[] iArr = this.next; iArr[findEmptySlot] = iArr[i]; iArr[i] = findEmptySlot; } else { this.previous[findEmptySlot] = -1; if (this.mCount > 0) { this.next[findEmptySlot] = this.head; this.head = findEmptySlot; } else { this.next[findEmptySlot] = -1; } } int[] iArr2 = this.next; if (iArr2[findEmptySlot] != -1) { this.previous[iArr2[findEmptySlot]] = findEmptySlot; } addToHashMap(solverVariable, findEmptySlot); } private void removeFromHashMap(SolverVariable solverVariable) { int[] iArr; int i = solverVariable.f21id; int i2 = i % this.HASH_SIZE; int[] iArr2 = this.keys; int i3 = iArr2[i2]; if (i3 != -1) { if (this.variables[i3] == i) { int[] iArr3 = this.nextKeys; iArr2[i2] = iArr3[i3]; iArr3[i3] = -1; return; } while (true) { iArr = this.nextKeys; if (iArr[i3] == -1 || this.variables[iArr[i3]] == i) { break; } i3 = iArr[i3]; } int i4 = iArr[i3]; if (i4 != -1 && this.variables[i4] == i) { iArr[i3] = iArr[i4]; iArr[i4] = -1; } } } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public void add(SolverVariable solverVariable, float f, boolean z2) { float f2 = epsilon; if (f <= (-f2) || f >= f2) { int indexOf = indexOf(solverVariable); if (indexOf == -1) { put(solverVariable, f); return; } float[] fArr = this.values; fArr[indexOf] = fArr[indexOf] + f; float f3 = fArr[indexOf]; float f4 = epsilon; if (f3 > (-f4) && fArr[indexOf] < f4) { fArr[indexOf] = 0.0f; remove(solverVariable, z2); } } } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public void clear() { int i = this.mCount; for (int i2 = 0; i2 < i; i2++) { SolverVariable variable = getVariable(i2); if (variable != null) { variable.removeFromRow(this.mRow); } } for (int i3 = 0; i3 < this.SIZE; i3++) { this.variables[i3] = -1; this.nextKeys[i3] = -1; } for (int i4 = 0; i4 < this.HASH_SIZE; i4++) { this.keys[i4] = -1; } this.mCount = 0; this.head = -1; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public boolean contains(SolverVariable solverVariable) { return indexOf(solverVariable) != -1; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public void display() { int i = this.mCount; System.out.print("{ "); for (int i2 = 0; i2 < i; i2++) { SolverVariable variable = getVariable(i2); if (variable != null) { PrintStream printStream = System.out; printStream.print(variable + " = " + getVariableValue(i2) + " "); } } System.out.println(" }"); } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public void divideByAmount(float f) { int i = this.mCount; int i2 = this.head; for (int i3 = 0; i3 < i; i3++) { float[] fArr = this.values; fArr[i2] = fArr[i2] / f; i2 = this.next[i2]; if (i2 == -1) { return; } } } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public float get(SolverVariable solverVariable) { int indexOf = indexOf(solverVariable); if (indexOf != -1) { return this.values[indexOf]; } return 0.0f; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public int getCurrentSize() { return this.mCount; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public SolverVariable getVariable(int i) { int i2 = this.mCount; if (i2 == 0) { return null; } int i3 = this.head; for (int i4 = 0; i4 < i2; i4++) { if (i4 == i && i3 != -1) { return this.mCache.mIndexedVariables[this.variables[i3]]; } i3 = this.next[i3]; if (i3 == -1) { break; } } return null; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public float getVariableValue(int i) { int i2 = this.mCount; int i3 = this.head; for (int i4 = 0; i4 < i2; i4++) { if (i4 == i) { return this.values[i3]; } i3 = this.next[i3]; if (i3 == -1) { return 0.0f; } } return 0.0f; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public int indexOf(SolverVariable solverVariable) { int[] iArr; if (!(this.mCount == 0 || solverVariable == null)) { int i = solverVariable.f21id; int i2 = this.keys[i % this.HASH_SIZE]; if (i2 == -1) { return -1; } if (this.variables[i2] == i) { return i2; } while (true) { iArr = this.nextKeys; if (iArr[i2] == -1 || this.variables[iArr[i2]] == i) { break; } i2 = iArr[i2]; } if (iArr[i2] != -1 && this.variables[iArr[i2]] == i) { return iArr[i2]; } } return -1; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public void invert() { int i = this.mCount; int i2 = this.head; for (int i3 = 0; i3 < i; i3++) { float[] fArr = this.values; fArr[i2] = fArr[i2] * -1.0f; i2 = this.next[i2]; if (i2 == -1) { return; } } } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public void put(SolverVariable solverVariable, float f) { float f2 = epsilon; if (f <= (-f2) || f >= f2) { if (this.mCount == 0) { addVariable(0, solverVariable, f); addToHashMap(solverVariable, 0); this.head = 0; return; } int indexOf = indexOf(solverVariable); if (indexOf != -1) { this.values[indexOf] = f; return; } if (this.mCount + 1 >= this.SIZE) { increaseSize(); } int i = this.mCount; int i2 = this.head; int i3 = -1; for (int i4 = 0; i4 < i; i4++) { int[] iArr = this.variables; int i5 = iArr[i2]; int i6 = solverVariable.f21id; if (i5 == i6) { this.values[i2] = f; return; } if (iArr[i2] < i6) { i3 = i2; } i2 = this.next[i2]; if (i2 == -1) { break; } } insertVariable(i3, solverVariable, f); return; } remove(solverVariable, true); } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public float remove(SolverVariable solverVariable, boolean z2) { int indexOf = indexOf(solverVariable); if (indexOf == -1) { return 0.0f; } removeFromHashMap(solverVariable); float f = this.values[indexOf]; if (this.head == indexOf) { this.head = this.next[indexOf]; } this.variables[indexOf] = -1; int[] iArr = this.previous; if (iArr[indexOf] != -1) { int[] iArr2 = this.next; iArr2[iArr[indexOf]] = iArr2[indexOf]; } int[] iArr3 = this.next; if (iArr3[indexOf] != -1) { iArr[iArr3[indexOf]] = iArr[indexOf]; } this.mCount--; solverVariable.usageInRowCount--; if (z2) { solverVariable.removeFromRow(this.mRow); } return f; } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public int sizeInBytes() { return 0; } public String toString() { String str; String str2; String str3 = hashCode() + " { "; int i = this.mCount; for (int i2 = 0; i2 < i; i2++) { SolverVariable variable = getVariable(i2); if (variable != null) { String str4 = str3 + variable + " = " + getVariableValue(i2) + " "; int indexOf = indexOf(variable); String s2 = a.s(str4, "[p: "); if (this.previous[indexOf] != -1) { StringBuilder L = a.L(s2); L.append(this.mCache.mIndexedVariables[this.variables[this.previous[indexOf]]]); str = L.toString(); } else { str = a.s(s2, "none"); } String s3 = a.s(str, ", n: "); if (this.next[indexOf] != -1) { StringBuilder L2 = a.L(s3); L2.append(this.mCache.mIndexedVariables[this.variables[this.next[indexOf]]]); str2 = L2.toString(); } else { str2 = a.s(s3, "none"); } str3 = a.s(str2, "]"); } } return a.s(str3, " }"); } @Override // androidx.constraintlayout.solver.ArrayRow.ArrayRowVariables public float use(ArrayRow arrayRow, boolean z2) { float f = get(arrayRow.variable); remove(arrayRow.variable, z2); SolverVariableValues solverVariableValues = (SolverVariableValues) arrayRow.variables; int currentSize = solverVariableValues.getCurrentSize(); int i = 0; int i2 = 0; while (i < currentSize) { int[] iArr = solverVariableValues.variables; if (iArr[i2] != -1) { add(this.mCache.mIndexedVariables[iArr[i2]], solverVariableValues.values[i2] * f, z2); i++; } i2++; } return f; } }