# ArrayLinkedVariables

Artifact: [androidx.constraintlayout:constraintlayout-core](https://developer.android.com/jetpack/androidx/releases/constraintlayout) [View Source](https://cs.android.com/search?q=file:androidx/constraintlayout/core/ArrayLinkedVariables.java+class:androidx.constraintlayout.core.ArrayLinkedVariables) Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

*** ** * ** ***


```
public class ArrayLinkedVariables implements ArrayRow.ArrayRowVariables
```

<br />

*** ** * ** ***

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.

## Summary

| ### Protected fields |
|---|---|
| `final https://developer.android.com/reference/androidx/constraintlayout/core/Cache` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#mCache()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#add(androidx.constraintlayout.core.SolverVariable,float,boolean)(https://developer.android.com/reference/androidx/constraintlayout/core/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 |
| `final void` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#clear()()` Clear the list of variables |
| `boolean` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#contains(androidx.constraintlayout.core.SolverVariable)(https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable)` Returns true if the variable is contained in the list |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#display()()` print out the variables and their values |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#divideByAmount(float)(float amount)` Divide the values of all the variables in the list by the given amount |
| `final float` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#get(androidx.constraintlayout.core.SolverVariable)(https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable v)` Return the value of a variable, 0 if not found |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getCurrentSize()()` |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getHead()()` |
| `final int` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getId(int)(int index)` get Id in mCache.mIndexedVariables given the index |
| `final int` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getNextIndice(int)(int index)` Get the next index in mArrayIndices given the current one |
| `final float` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getValue(int)(int index)` get value in mArrayValues given the index |
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getVariable(int)(int index)` Return a variable from its position in the linked list |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#getVariableValue(int)(int index)` Return the value of a variable from its position in the linked list |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#indexOf(androidx.constraintlayout.core.SolverVariable)(https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable)` |
| `void` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#invert()()` Invert the values of all the variables in the list |
| `final void` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#put(androidx.constraintlayout.core.SolverVariable,float)(https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable, float value)` Insert a variable with a given value in the linked list |
| `final float` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#remove(androidx.constraintlayout.core.SolverVariable,boolean)(https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable, boolean removeFromDefinition)` Remove a variable from the list |
| `int` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#sizeInBytes()()` Show size in bytes |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#toString()()` Returns a string representation of the list |
| `float` | `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayLinkedVariables#use(androidx.constraintlayout.core.ArrayRow,boolean)(https://developer.android.com/reference/androidx/constraintlayout/core/ArrayRow definition, boolean removeFromDefinition)` Update the current list with a new definition |

## Protected fields

### mCache

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
protected final Cache mCache
```

## Public methods

### add

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable` | the variable we want to add |
| `float value` | its value |

### clear

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final void clear()
```

Clear the list of variables

### contains

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public boolean contains(SolverVariable variable)
```

Returns true if the variable is contained in the list

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable` | the variable we are looking for |

| Returns |
|---|---|
| `boolean` | return true if we found the variable |

### display

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void display()
```

print out the variables and their values

### divideByAmount

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void divideByAmount(float amount)
```

Divide the values of all the variables in the list by the given amount

| Parameters |
|---|---|
| `float amount` | amount to divide by |

### get

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final float get(SolverVariable v)
```

Return the value of a variable, 0 if not found

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable v` | the variable we are looking up |

| Returns |
|---|---|
| `float` | the value of the found variable, or 0 if not found |

### getCurrentSize

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int getCurrentSize()
```

### getHead

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int getHead()
```

### getId

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final int getId(int index)
```

get Id in mCache.mIndexedVariables given the index

### getNextIndice

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final int getNextIndice(int index)
```

Get the next index in mArrayIndices given the current one

### getValue

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final float getValue(int index)
```

get value in mArrayValues given the index

### getVariable

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public SolverVariable getVariable(int index)
```

Return a variable from its position in the linked list

| Parameters |
|---|---|
| `int index` | the index of the variable we want to return |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable` | the variable found, or null |

### getVariableValue

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public float getVariableValue(int index)
```

Return the value of a variable from its position in the linked list

| Parameters |
|---|---|
| `int index` | the index of the variable we want to look up |

| Returns |
|---|---|
| `float` | the value of the found variable, or 0 if not found |

### indexOf

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int indexOf(SolverVariable variable)
```

### invert

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public void invert()
```

Invert the values of all the variables in the list

### put

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final void put(SolverVariable variable, float value)
```

Insert a variable with a given value in the linked list

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable` | the variable to add in the list |
| `float value` | the value of the variable |

### remove

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public final float remove(SolverVariable variable, boolean removeFromDefinition)
```

Remove a variable from the list

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/SolverVariable variable` | the variable we want to remove |

| Returns |
|---|---|
| `float` | the value of the removed variable |

### sizeInBytes

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public int sizeInBytes()
```

Show size in bytes

| Returns |
|---|---|
| `int` | size in bytes |

### toString

```
public String toString()
```

Returns a string representation of the list

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | a string containing a representation of the list |

### use

Added in [1.1.2](https://developer.android.com/jetpack/androidx/releases/constraintlayout#1.1.2)

```
public float use(ArrayRow definition, boolean removeFromDefinition)
```

Update the current list with a new definition

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/constraintlayout/core/ArrayRow definition` | the row containing the definition |