Package androidx.constraintlayout.core
Class ArrayLinkedVariables
- java.lang.Object
-
- androidx.constraintlayout.core.ArrayLinkedVariables
-
- All Implemented Interfaces:
ArrayRow.ArrayRowVariables
public class ArrayLinkedVariables extends java.lang.Object implements ArrayRow.ArrayRowVariables
Store a set of variables and their values in an array-based linked list. The general idea is that we want to store a list of variables that need to be ordered, space efficient, and relatively fast to maintain (add/remove). ArrayBackedVariables implements a sparse array, so is rather space efficient, but maintaining the array sorted is costly, as we spend quite a bit of time recopying parts of the array on element deletion. LinkedVariables implements a standard linked list structure, and is able to be faster than ArrayBackedVariables even though it's more costly to set up (pool of objects...), as the elements removal and maintenance of the structure is a lot more efficient. This ArrayLinkedVariables class takes inspiration from both of the above, and implement a linked list stored in several arrays. This allows us to be a lot more efficient in terms of setup (no need to deal with pool of objects...), resetting the structure, and insertion/deletion of elements.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(SolverVariable variable, float value, boolean removeFromDefinition)Add value to an existing variable The code is broadly identical to the put() method, only differing in in-line deletion, and of course doing an add rather than a putvoidclear()Clear the list of variablesbooleancontains(SolverVariable variable)Returns true if the variable is contained in the listvoiddisplay()print out the variables and their valuesvoiddivideByAmount(float amount)Divide the values of all the variables in the list by the given amountfloatget(SolverVariable v)Return the value of a variable, 0 if not foundintgetCurrentSize()intgetHead()intgetId(int index)get Id in mCache.mIndexedVariables given the indexintgetNextIndice(int index)Get the next index in mArrayIndices given the current onefloatgetValue(int index)get value in mArrayValues given the indexSolverVariablegetVariable(int index)Return a variable from its position in the linked listfloatgetVariableValue(int index)Return the value of a variable from its position in the linked listintindexOf(SolverVariable variable)voidinvert()Invert the values of all the variables in the listvoidput(SolverVariable variable, float value)Insert a variable with a given value in the linked listfloatremove(SolverVariable variable, boolean removeFromDefinition)Remove a variable from the listintsizeInBytes()Show size in bytesjava.lang.StringtoString()Returns a string representation of the listfloatuse(ArrayRow definition, boolean removeFromDefinition)Update the current list with a new definition
-
-
-
Field Detail
-
mCache
protected final Cache mCache
-
-
Method Detail
-
put
public final void put(SolverVariable variable, float value)
Insert a variable with a given value in the linked list- Specified by:
putin interfaceArrayRow.ArrayRowVariables- Parameters:
variable- the variable to add in the listvalue- the value of the variable
-
add
public void add(SolverVariable variable, float value, boolean removeFromDefinition)
Add value to an existing variable The code is broadly identical to the put() method, only differing in in-line deletion, and of course doing an add rather than a put- Specified by:
addin interfaceArrayRow.ArrayRowVariables- Parameters:
variable- the variable we want to addvalue- its value
-
use
public float use(ArrayRow definition, boolean removeFromDefinition)
Update the current list with a new definition- Specified by:
usein interfaceArrayRow.ArrayRowVariables- Parameters:
definition- the row containing the definition
-
remove
public final float remove(SolverVariable variable, boolean removeFromDefinition)
Remove a variable from the list- Specified by:
removein interfaceArrayRow.ArrayRowVariables- Parameters:
variable- the variable we want to remove- Returns:
- the value of the removed variable
-
clear
public final void clear()
Clear the list of variables- Specified by:
clearin interfaceArrayRow.ArrayRowVariables
-
contains
public boolean contains(SolverVariable variable)
Returns true if the variable is contained in the list- Specified by:
containsin interfaceArrayRow.ArrayRowVariables- Parameters:
variable- the variable we are looking for- Returns:
- return true if we found the variable
-
indexOf
public int indexOf(SolverVariable variable)
- Specified by:
indexOfin interfaceArrayRow.ArrayRowVariables
-
invert
public void invert()
Invert the values of all the variables in the list- Specified by:
invertin interfaceArrayRow.ArrayRowVariables
-
divideByAmount
public void divideByAmount(float amount)
Divide the values of all the variables in the list by the given amount- Specified by:
divideByAmountin interfaceArrayRow.ArrayRowVariables- Parameters:
amount- amount to divide by
-
getHead
public int getHead()
-
getCurrentSize
public int getCurrentSize()
- Specified by:
getCurrentSizein interfaceArrayRow.ArrayRowVariables
-
getId
public final int getId(int index)
get Id in mCache.mIndexedVariables given the index
-
getValue
public final float getValue(int index)
get value in mArrayValues given the index
-
getNextIndice
public final int getNextIndice(int index)
Get the next index in mArrayIndices given the current one
-
getVariable
public SolverVariable getVariable(int index)
Return a variable from its position in the linked list- Specified by:
getVariablein interfaceArrayRow.ArrayRowVariables- Parameters:
index- the index of the variable we want to return- Returns:
- the variable found, or null
-
getVariableValue
public float getVariableValue(int index)
Return the value of a variable from its position in the linked list- Specified by:
getVariableValuein interfaceArrayRow.ArrayRowVariables- Parameters:
index- the index of the variable we want to look up- Returns:
- the value of the found variable, or 0 if not found
-
get
public final float get(SolverVariable v)
Return the value of a variable, 0 if not found- Specified by:
getin interfaceArrayRow.ArrayRowVariables- Parameters:
v- the variable we are looking up- Returns:
- the value of the found variable, or 0 if not found
-
sizeInBytes
public int sizeInBytes()
Show size in bytes- Specified by:
sizeInBytesin interfaceArrayRow.ArrayRowVariables- Returns:
- size in bytes
-
display
public void display()
print out the variables and their values- Specified by:
displayin interfaceArrayRow.ArrayRowVariables
-
toString
public java.lang.String toString()
Returns a string representation of the list- Overrides:
toStringin classjava.lang.Object- Returns:
- a string containing a representation of the list
-
-