ArrayLinkedVariables
class ArrayLinkedVariables : 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.
Summary
Public functions |
|
---|---|
Unit |
add(variable: SolverVariable!, value: Float, removeFromDefinition: Boolean) 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 |
Unit |
clear() Clear the list of variables |
Boolean |
contains(variable: SolverVariable!) Returns true if the variable is contained in the list |
Unit |
display() print out the variables and their values |
Unit |
divideByAmount(amount: Float) Divide the values of all the variables in the list by the given amount |
Float |
get(v: SolverVariable!) Return the value of a variable, 0 if not found |
Int |
|
Int |
getHead() |
Int |
get Id in mCache.mIndexedVariables given the index |
Int |
getNextIndice(index: Int) Get the next index in mArrayIndices given the current one |
Float |
get value in mArrayValues given the index |
SolverVariable! |
getVariable(index: Int) Return a variable from its position in the linked list |
Float |
getVariableValue(index: Int) Return the value of a variable from its position in the linked list |
Int |
indexOf(variable: SolverVariable!) |
Unit |
invert() Invert the values of all the variables in the list |
Unit |
put(variable: SolverVariable!, value: Float) Insert a variable with a given value in the linked list |
Float |
remove(variable: SolverVariable!, removeFromDefinition: Boolean) Remove a variable from the list |
Int |
Show size in bytes |
String! |
toString() Returns a string representation of the list |
Float |
Update the current list with a new definition |
Public functions
add
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: SolverVariable! |
the variable we want to add |
value: Float |
its value |
contains
fun contains(variable: SolverVariable!): Boolean
Returns true if the variable is contained in the list
Parameters | |
---|---|
variable: SolverVariable! |
the variable we are looking for |
Returns | |
---|---|
Boolean |
return true if we found the variable |
divideByAmount
fun divideByAmount(amount: Float): Unit
Divide the values of all the variables in the list by the given amount
Parameters | |
---|---|
amount: Float |
amount to divide by |
get
fun get(v: SolverVariable!): Float
Return the value of a variable, 0 if not found
Parameters | |
---|---|
v: SolverVariable! |
the variable we are looking up |
Returns | |
---|---|
Float |
the value of the found variable, or 0 if not found |
getNextIndice
fun getNextIndice(index: Int): Int
Get the next index in mArrayIndices given the current one
getVariable
fun getVariable(index: Int): SolverVariable!
Return a variable from its position in the linked list
Parameters | |
---|---|
index: Int |
the index of the variable we want to return |
Returns | |
---|---|
SolverVariable! |
the variable found, or null |
getVariableValue
fun getVariableValue(index: Int): Float
Return the value of a variable from its position in the linked list
Parameters | |
---|---|
index: Int |
the index of the variable we want to look up |
Returns | |
---|---|
Float |
the value of the found variable, or 0 if not found |
put
fun put(variable: SolverVariable!, value: Float): Unit
Insert a variable with a given value in the linked list
Parameters | |
---|---|
variable: SolverVariable! |
the variable to add in the list |
value: Float |
the value of the variable |
remove
fun remove(variable: SolverVariable!, removeFromDefinition: Boolean): Float
Remove a variable from the list
Parameters | |
---|---|
variable: SolverVariable! |
the variable we want to remove |
Returns | |
---|---|
Float |
the value of the removed variable |