ArrayLinkedVariables


public class ArrayLinkedVariables 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.

Summary

Protected fields

final Cache

Public methods

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

final void

Clear the list of variables

boolean

Returns true if the variable is contained in the list

void

print out the variables and their values

void
divideByAmount(float amount)

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

final float

Return the value of a variable, 0 if not found

int
int
final int
getId(int index)

get Id in mCache.mIndexedVariables given the index

final int
getNextIndice(int index)

Get the next index in mArrayIndices given the current one

final float
getValue(int index)

get value in mArrayValues given the index

SolverVariable
getVariable(int index)

Return a variable from its position in the linked list

float
getVariableValue(int index)

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

int
void

Invert the values of all the variables in the list

final void
put(SolverVariable variable, float value)

Insert a variable with a given value in the linked list

final float
remove(SolverVariable variable, boolean removeFromDefinition)

Remove a variable from the list

int

Show size in bytes

String

Returns a string representation of the list

float
use(ArrayRow definition, boolean removeFromDefinition)

Update the current list with a new definition

Protected fields

mCache

Added in 1.1.0
protected final Cache mCache

Public methods

add

Added in 1.1.0
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
SolverVariable variable

the variable we want to add

float value

its value

clear

Added in 1.1.0
public final void clear()

Clear the list of variables

contains

Added in 1.1.0
public boolean contains(SolverVariable variable)

Returns true if the variable is contained in the list

Parameters
SolverVariable variable

the variable we are looking for

Returns
boolean

return true if we found the variable

display

Added in 1.1.0
public void display()

print out the variables and their values

divideByAmount

Added in 1.1.0
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.0
public final float get(SolverVariable v)

Return the value of a variable, 0 if not found

Parameters
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.0
public int getCurrentSize()

getHead

Added in 1.1.0
public int getHead()

getId

Added in 1.1.0
public final int getId(int index)

get Id in mCache.mIndexedVariables given the index

getNextIndice

Added in 1.1.0
public final int getNextIndice(int index)

Get the next index in mArrayIndices given the current one

getValue

Added in 1.1.0
public final float getValue(int index)

get value in mArrayValues given the index

getVariable

Added in 1.1.0
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
SolverVariable

the variable found, or null

getVariableValue

Added in 1.1.0
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.0
public int indexOf(SolverVariable variable)

invert

Added in 1.1.0
public void invert()

Invert the values of all the variables in the list

put

Added in 1.1.0
public final void put(SolverVariable variable, float value)

Insert a variable with a given value in the linked list

Parameters
SolverVariable variable

the variable to add in the list

float value

the value of the variable

remove

Added in 1.1.0
public final float remove(SolverVariable variable, boolean removeFromDefinition)

Remove a variable from the list

Parameters
SolverVariable variable

the variable we want to remove

Returns
float

the value of the removed variable

sizeInBytes

Added in 1.1.0
public int sizeInBytes()

Show size in bytes

Returns
int

size in bytes

toString

public String toString()

Returns a string representation of the list

Returns
String

a string containing a representation of the list

use

Added in 1.1.0
public float use(ArrayRow definition, boolean removeFromDefinition)

Update the current list with a new definition

Parameters
ArrayRow definition

the row containing the definition