# 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)

*** ** * ** ***


```
class ArrayLinkedVariables : 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

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

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

## Public functions

### add

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

```
fun add(variable: SolverVariable!, value: Float, removeFromDefinition: Boolean): Unit
```

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 |
|---|---|
| `variable: https://developer.android.com/reference/kotlin/androidx/constraintlayout/core/SolverVariable!` | the variable we want to add |
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | its value |

### clear

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

```
fun clear(): Unit
```

Clear the list of variables

### contains

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

```
fun contains(variable: SolverVariable!): Boolean
```

Returns true if the variable is contained in the list

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | return true if we found the variable |

### display

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

```
fun display(): Unit
```

print out the variables and their values

### divideByAmount

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

```
fun divideByAmount(amount: Float): Unit
```

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

| Parameters |
|---|---|
| `amount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | amount to divide by |

### get

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

```
fun get(v: SolverVariable!): Float
```

Return the value of a variable, 0 if not found

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | 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)

```
fun getCurrentSize(): Int
```

### getHead

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

```
fun getHead(): Int
```

### getId

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

```
fun getId(index: Int): Int
```

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)

```
fun getNextIndice(index: Int): Int
```

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)

```
fun getValue(index: Int): Float
```

get value in mArrayValues given the index

### getVariable

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

```
fun getVariable(index: Int): SolverVariable!
```

Return a variable from its position in the linked list

| Parameters |
|---|---|
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the index of the variable we want to return |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/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)

```
fun getVariableValue(index: Int): Float
```

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

| Parameters |
|---|---|
| `index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the index of the variable we want to look up |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | 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)

```
fun indexOf(variable: SolverVariable!): Int
```

### invert

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

```
fun invert(): Unit
```

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)

```
fun put(variable: SolverVariable!, value: Float): Unit
```

Insert a variable with a given value in the linked list

| Parameters |
|---|---|
| `variable: https://developer.android.com/reference/kotlin/androidx/constraintlayout/core/SolverVariable!` | the variable to add in the list |
| `value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the value of the variable |

### remove

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

```
fun remove(variable: SolverVariable!, removeFromDefinition: Boolean): Float
```

Remove a variable from the list

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the value of the removed variable |

### sizeInBytes

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

```
fun sizeInBytes(): Int
```

Show size in bytes

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | size in bytes |

### toString

```
fun toString(): String!
```

Returns a string representation of the list

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.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)

```
fun use(definition: ArrayRow!, removeFromDefinition: Boolean): Float
```

Update the current list with a new definition

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

## Protected properties

### mCache

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

```
protected val mCache: Cache!
```