BitArray

A class representing a bit array where each bit is stored as a boolean value in a compact, memory-efficient manner. The boolean values are packed into integers, with each integer representing 32 bits. This class provides methods to set and get the boolean values at specific indices, as well as perform various operations on the array.

This class is NOT synchronized. Simultaneous modifications and reads from multiple threads may lead to unpredictable behavior.

Constructors

Link copied to clipboard
constructor(size: Int)

Constructs a BitArray of the given size.

Properties

Link copied to clipboard

Returns the range of valid indices for the array.

Link copied to clipboard
val size: Int

The size of the bit array, specifying the number of individual boolean values it can hold.

Functions

Link copied to clipboard

Returns true if all elements are false, false otherwise.

Link copied to clipboard

Returns true if all elements are true, false otherwise.

Link copied to clipboard
infix fun and(other: BitArray): BitArray

Returns a new BitArray which is the bitwise AND of this and other.

Link copied to clipboard
infix fun andInPlace(other: BitArray)

Performs a bitwise AND with other in place, modifying this array.

Link copied to clipboard

Returns true if any element is false, false otherwise.

Link copied to clipboard

Returns true if any element is true, false otherwise.

Link copied to clipboard
fun clear()

Sets all elements in the array to false.

Link copied to clipboard
operator fun contains(value: Boolean): Boolean

Returns true if any element matches the given boolean value.

Link copied to clipboard

Returns true if this BitArray is equal to the specified other.

Link copied to clipboard

Returns a copy of this BitArray.

Link copied to clipboard
fun count(value: Boolean): Int

Counts the number of occurrences of the specified boolean value in the BitArray.

Link copied to clipboard
fun fill(element: Boolean, fromIndex: Int = 0, toIndex: Int = size)

Fills the specified range of this BitArray with the given boolean value.

Link copied to clipboard
inline fun forEach(action: (Boolean) -> Unit)

Performs the given action on each element in the array.

Link copied to clipboard
inline fun forEachIndexed(action: (Int, Boolean) -> Unit)

Performs the given action on each element in the array, providing the index of the element.

Link copied to clipboard
operator fun get(i: Int): Boolean

Gets the boolean value at the specified index.

Link copied to clipboard
infix fun intersects(other: BitArray): Boolean

Returns true if any bit set in other is also set in this array (intersection).

Link copied to clipboard

Returns true if the array is empty (has a size of 0), false otherwise.

Link copied to clipboard
infix fun isSubsetOf(other: BitArray): Boolean

Returns true if every true bit in this array is also true in other (subset test).

Link copied to clipboard
infix fun isSupersetOf(other: BitArray): Boolean

Returns true if every true bit in other is also true in this array (superset test).

Link copied to clipboard
infix fun nand(other: BitArray): BitArray

Returns a new BitArray which is the bitwise NAND of this and other.

Link copied to clipboard
infix fun nandInPlace(other: BitArray)

Performs a bitwise NAND with other in place, modifying this array.

Link copied to clipboard

Returns true if no element in the array is false.

Link copied to clipboard

Returns true if no element in the array is true.

Link copied to clipboard
infix fun nor(other: BitArray): BitArray

Returns a new BitArray which is the bitwise NOR of this and other.

Link copied to clipboard
infix fun norInPlace(other: BitArray)

Performs a bitwise NOR with other in place, modifying this array.

Link copied to clipboard
infix fun or(other: BitArray): BitArray

Returns a new BitArray which is the bitwise OR of this and other.

Link copied to clipboard
infix fun orInPlace(other: BitArray)

Performs a bitwise OR with other in place, modifying this array.

Link copied to clipboard
operator fun set(i: Int, value: Boolean)

Sets the boolean value at the specified index.

fun set(range: IntRange, value: Boolean)

Sets all bits in the given inclusive range to value.

fun set(from: Int, to: Int, value: Boolean)

Sets all bits in the inclusive range [from, to] to value.

Link copied to clipboard
fun setFalse(i: Int)

Sets the value at the specified index to false.

Link copied to clipboard
fun setTrue(i: Int)

Sets the value at the specified index to true.

Link copied to clipboard

Returns A BooleanArray representation of this BitArray.

Link copied to clipboard
infix fun xor(other: BitArray): BitArray

Returns a new BitArray which is the bitwise XOR of this and other.

Link copied to clipboard
infix fun xorInPlace(other: BitArray)

Performs a bitwise XOR with other in place, modifying this array.