Package tech.tablesaw.columns.booleans
Class BitSetBooleanData
- java.lang.Object
-
- tech.tablesaw.columns.booleans.BitSetBooleanData
-
- All Implemented Interfaces:
it.unimi.dsi.fastutil.bytes.ByteIterable
,Iterable<Byte>
,BooleanData
public class BitSetBooleanData extends Object implements BooleanData
An implementation of BooleanData where the underlying representation uses the Java BitSet class
-
-
Constructor Summary
Constructors Constructor Description BitSetBooleanData()
BitSetBooleanData(it.unimi.dsi.fastutil.bytes.ByteArrayList values)
Constructs a BitSetBoolean data from the given ByteArrayListBitSetBooleanData(BitSet trueValues, BitSet falseValues, BitSet missingValues)
Constructs a BitSetBoolean data from three BitSets, one for each possible value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(byte b)
Adds a boolean value represented as a byte, where 0=false, 1=true, and -1=missingSelection
asSelection()
Returns a selection matching all the true values in the datavoid
clear()
Removes all data valuesboolean
contains(byte b)
Returns true if the value at b is true.BooleanData
copy()
Returns a copy of this BooleanData objectint
countFalse()
Returns the number of false values in the data *int
countMissing()
Returns the number of missing values in the data *int
countTrue()
Returns the number of true values in the data *int
countUnique()
Returns the number of unique values in the data.byte[]
falseBytes()
Returns a byte representation of the true values, encoded in the format specified inBitSet.toByteArray()
byte
getByte(int i)
Returns the value at i as a byte, where -1 represents missing valuesboolean
isEmpty()
Returns true if the data is empty, and false otherwise.Selection
isFalse()
Returns a selection matching all the false values in the dataSelection
isMissing()
Returns a selection matching all the missing values in the dataSelection
isTrue()
Returns a selection matching all the true values in the datait.unimi.dsi.fastutil.bytes.ByteIterator
iterator()
byte[]
missingBytes()
Returns a byte representation of the missing values, encoded in the format specified inBitSet.toByteArray()
void
set(int i, byte b)
Sets the value at position i to byte bvoid
setFalseBytes(byte[] bytes)
Sets the false values in the data from a byte[] encodingvoid
setMissingBytes(byte[] bytes)
Sets the missing values in the data from a byte[] encodingvoid
setTrueBytes(byte[] bytes)
Sets the true values in the data from a byte[] encodingint
size()
Returns the number of values in the data, including missing valuesvoid
sortAscending()
Sorts the data in-place in ascending order, with missing values firstvoid
sortDescending()
Sorts the data in-place in descending order, with missing values lastbyte[]
toByteArray()
Returns the data as a byte[] containing 0 and 1, with any missing values encoded as -128it.unimi.dsi.fastutil.bytes.ByteArrayList
toByteArrayList()
Returns the data as a ByteArrayList containing 0 and 1, with any missing values encoded as -128String
toString()
byte[]
trueBytes()
Returns a byte representation of the false values, encoded in the format specified inBitSet.toByteArray()
-
-
-
Constructor Detail
-
BitSetBooleanData
public BitSetBooleanData(BitSet trueValues, BitSet falseValues, BitSet missingValues)
Constructs a BitSetBoolean data from three BitSets, one for each possible value
-
BitSetBooleanData
public BitSetBooleanData(it.unimi.dsi.fastutil.bytes.ByteArrayList values)
Constructs a BitSetBoolean data from the given ByteArrayList- Parameters:
values
- The values must be encoded as 0, 1, or -128 (for missing)
-
BitSetBooleanData
public BitSetBooleanData()
-
-
Method Detail
-
size
public int size()
Returns the number of values in the data, including missing values- Specified by:
size
in interfaceBooleanData
-
add
public void add(byte b)
Adds a boolean value represented as a byte, where 0=false, 1=true, and -1=missing- Specified by:
add
in interfaceBooleanData
-
clear
public void clear()
Removes all data values- Specified by:
clear
in interfaceBooleanData
-
sortAscending
public void sortAscending()
Sorts the data in-place in ascending order, with missing values first- Specified by:
sortAscending
in interfaceBooleanData
-
sortDescending
public void sortDescending()
Sorts the data in-place in descending order, with missing values last- Specified by:
sortDescending
in interfaceBooleanData
-
copy
public BooleanData copy()
Returns a copy of this BooleanData object- Specified by:
copy
in interfaceBooleanData
-
getByte
public byte getByte(int i)
Returns the value at i as a byte, where -1 represents missing values- Specified by:
getByte
in interfaceBooleanData
-
countFalse
public int countFalse()
Returns the number of false values in the data *- Specified by:
countFalse
in interfaceBooleanData
-
countTrue
public int countTrue()
Returns the number of true values in the data *- Specified by:
countTrue
in interfaceBooleanData
-
countMissing
public int countMissing()
Returns the number of missing values in the data *- Specified by:
countMissing
in interfaceBooleanData
-
countUnique
public int countUnique()
Returns the number of unique values in the data. There can only be 3 (true, false, and missing) *- Specified by:
countUnique
in interfaceBooleanData
-
toByteArray
public byte[] toByteArray()
Returns the data as a byte[] containing 0 and 1, with any missing values encoded as -128- Specified by:
toByteArray
in interfaceBooleanData
-
toByteArrayList
public it.unimi.dsi.fastutil.bytes.ByteArrayList toByteArrayList()
Description copied from interface:BooleanData
Returns the data as a ByteArrayList containing 0 and 1, with any missing values encoded as -128- Specified by:
toByteArrayList
in interfaceBooleanData
-
set
public void set(int i, byte b)
Sets the value at position i to byte b- Specified by:
set
in interfaceBooleanData
- Parameters:
i
- the 0-based index of the element in the datab
- the value to set, should be 0, 1, or -128 only
-
isEmpty
public boolean isEmpty()
Returns true if the data is empty, and false otherwise. Empty here means only missing values- Specified by:
isEmpty
in interfaceBooleanData
-
contains
public boolean contains(byte b)
Returns true if the value at b is true.- Specified by:
contains
in interfaceBooleanData
-
asSelection
public Selection asSelection()
Returns a selection matching all the true values in the data- Specified by:
asSelection
in interfaceBooleanData
-
isFalse
public Selection isFalse()
Returns a selection matching all the false values in the data- Specified by:
isFalse
in interfaceBooleanData
-
isTrue
public Selection isTrue()
Returns a selection matching all the true values in the data- Specified by:
isTrue
in interfaceBooleanData
-
isMissing
public Selection isMissing()
Returns a selection matching all the missing values in the data- Specified by:
isMissing
in interfaceBooleanData
-
falseBytes
public byte[] falseBytes()
Returns a byte representation of the true values, encoded in the format specified inBitSet.toByteArray()
- Specified by:
falseBytes
in interfaceBooleanData
-
trueBytes
public byte[] trueBytes()
Returns a byte representation of the false values, encoded in the format specified inBitSet.toByteArray()
- Specified by:
trueBytes
in interfaceBooleanData
-
missingBytes
public byte[] missingBytes()
Returns a byte representation of the missing values, encoded in the format specified inBitSet.toByteArray()
- Specified by:
missingBytes
in interfaceBooleanData
-
setTrueBytes
public void setTrueBytes(byte[] bytes)
Sets the true values in the data from a byte[] encoding- Specified by:
setTrueBytes
in interfaceBooleanData
- Parameters:
bytes
- The true values encoded in the format specified inBitSet
-
setFalseBytes
public void setFalseBytes(byte[] bytes)
Sets the false values in the data from a byte[] encoding- Specified by:
setFalseBytes
in interfaceBooleanData
- Parameters:
bytes
- The false values encoded in the format specified inBitSet
-
setMissingBytes
public void setMissingBytes(byte[] bytes)
Sets the missing values in the data from a byte[] encoding- Specified by:
setMissingBytes
in interfaceBooleanData
- Parameters:
bytes
- The missing values encoded in the format specified inBitSet
-
-