Compression.BooleanCompression
Description
Used to compress an array of boolean values into a single integer
Example of using BooleanCompression
private void Function()
{
// Replace with your boolean array of values
// These values are used for this example
bool[] valuesToCompress = {
true,
false,
false,
true
};
// This will return the values in a compressed form in an integer
// In this example compression returns "9" using this specific layout of values
// Values can be retrieved using BooleanCompression.GetValues/GetValue
int compressedValues = BooleanCompression.CompressValues(valuesToCompress);
// Example of retrieving the values into an array
// Using the previous array length as the total count
bool[] retrievedValues = BooleanCompression.GetValues(compressedValues, valuesToCompress.Length);
// Example of retrieving the values individually
bool value1 = BooleanCompression.GetValue(compressedValues, 0);
bool value2 = BooleanCompression.GetValue(compressedValues, 1);
bool value3 = BooleanCompression.GetValue(compressedValues, 2);
bool value4 = BooleanCompression.GetValue(compressedValues, 3);
}
CompressValues
Declaration
public static int CompressValues(params bool[] values)
Parameters
Parameter | Description |
---|---|
values | Bools that will be compressed |
Returns
Compressed int of bools
Description
Compresses the input array of bools into an int. Values can be retrieved using GetValues and GetValue
private void Function()
{
// Replace with your boolean array of values
// These values are used for this example
bool[] valuesToCompress = {
true,
false,
false,
true
};
// This will return the values in a compressed form in an integer
// In this example compression returns "9" using this specific layout of values
// Values can be retrieved using GetValues/GetValue
int compressedValues = BooleanCompression.CompressValues(valuesToCompress);
}
GetValues
Declaration
public static bool[] GetValues(int compressedValues, int valueCount)
Parameters
Parameter | Description |
---|---|
compressedValues | Compressed int of bool values |
valueCount | The total amount of values stored in the compressedValues |
Returns
Array of all the values stored in the input comrpressedValues
Description
Retrieves all the boolean values stored in a compressed int created through CompressValues
private void Function()
{
// Replace with your compressed values
// Compressed values can be retrieved through CompressValues
int compressedValues;
// Retrieves the values from the integer into an array
// Using 4 for this example but the valueCount should be the amount of values stored in the compressedValues
bool[] retrievedValues = BooleanCompression.GetValues(compressedValues, 4);
// If you have the original array you can use its length for the valueCount
// bool[] retrievedValues = BooleanCompression.GetValues(compressedValues, valuesArray.Length);
}
AddValue
Declaration
public static int AddValue(int compressedValues, int index, bool value)
Parameters
Parameter | Description |
---|---|
compressedValues | Compressed int of bool values |
index | Index that the input value will overwrite |
value | Value inserted into the compressedValue |
Returns
New compressed integer with the added value
Description
Overwrites a value at a given index into the inputted compressedValues created through CompressValues
private void Function()
{
// Replace with your compressed values
// Compressed values can be retrieved through CompressValues
int compressedValues;
// Add a value at a specific index into the compressedValues
// In this example add the value "true" to index 5
// This will overwrite the previous value at this index
// The index can also be larger than the current value amount in the compressedValues, it will be expanded accordingly
compressedValues = BooleanCompression.AddValue(compressedValues, 5, true);
}
GetValue
Declaration
public static bool GetValue(int compressedValues, int index)
Parameters
Parameter | Description |
---|---|
compressedValues | Compressed int of bool values |
index | Index of which bool value will be returned |
Returns
Value at the given index
Description
Gets a compressed value at a given index from the inputted compressedValues created through CompressValues
private void Function()
{
// Replace with your compressed values
// Compressed values can be retrieved through CompressValues
int compressedValues;
// Retrieve a value at a specific index from the compressedValues
// In this example retrieve the value at index 2
bool value3 = BooleanCompression.GetValue(compressedValues, 2);
}