BitSet

@Serializable(with = BitSetSerializer::class)
class BitSet : Iterable<Boolean> (source)

Pure Kotlin Bit Set created by throwing a bunch of extension functions at a MutableList<Byte>. As a mental model: this BitSet grows from left to right, just like writing a text.

Note: The in-byte bit index vs. the global index (for iterating over the bytes contained in the list) run in opposing directions!

The toBitStringView function print our the bits as they are accessible, disregarding byte-alignment and memory layout:

val bitSet = BitSet()
bitSet[0] = true //1 (ByteArray representation: [1])
bitSet[2] = true //101 (ByteArray representation: [5])
bitSet[8] = true //10100000 1 (ByteArray representation: [5,1])

To inspect the actual memory layout of the underlying bytes (i.e. the result of calling toByteArray), use memDumpView.

Implements Iterable over bits. Use bytes to iterate over bytes

Constructors

Link copied to clipboard
constructor(nBits: Long = 0)

Preallocates a buffer capable of holding nBits many bits

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

List view on the bytes backing this bit set. Changes to the bytes directly affect this bitset.

Functions

Link copied to clipboard
fun BitSet.clear(index: Int)
fun BitSet.clear(longRange: LongRange)
fun BitSet.clear(fromIndex: Long, toIndex: Long)

fun BitSet.clear(index: Long)

shorthand for set(index, false)

Link copied to clipboard
fun copyOf(): BitSet

Creates a deep copy of the current BitSet instance.

Link copied to clipboard
@JvmName(name = "encodeAllPemBlocksToPem")
fun Iterable<PemBlock>.encodeAllToPem(): String
@JvmName(name = "encodeAllPemEncodablesToPem")
fun Iterable<PemEncodable>.encodeAllToPem(): String
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun BitSet.flip(index: Int)
fun BitSet.flip(index: Long)
fun BitSet.flip(indexes: LongRange)
fun BitSet.flip(fromIndex: Long, toIndex: Long)
Link copied to clipboard
inline fun forEachIndexed(action: (i: Long, it: Boolean) -> Unit)

Iterates over each bit in the BitSet and invokes the provided action for every index and corresponding bit value.

Link copied to clipboard
operator fun get(index: Long): Boolean

Returns the bit at index. Never throws an exception when index>=0, as getting a bit outside the underlying bytes' bounds returns false.

Link copied to clipboard
operator fun BitSet.get(index: Int): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open operator override fun iterator(): Iterator<Boolean>

returns an iterator over bits. use bytes.iterator() to iterate over bytes

Link copied to clipboard
fun length(): Long

Current length of the bitset.

Link copied to clipboard

Returns a binary representation of this bit set's memory layout, when packed into a byte array Bytes are separated by a single space. An empty byte array results in an empty string.

Link copied to clipboard
fun nextSetBit(fromIndex: Long): Long

Returns the first bit set to true from fromIndex (= inclusive).

Link copied to clipboard

Returns the first bit set to true after index (= exclusive).

Link copied to clipboard
operator fun set(index: Long, value: Boolean)

Sets the bit at index to value

Link copied to clipboard
fun BitSet.set(index: Int)
fun BitSet.set(indexes: LongRange)
operator fun BitSet.set(index: Int, value: Boolean)
fun BitSet.set(fromIndex: Long, toIndex: Long)

fun BitSet.set(index: Long)

shorthand for set(index, true)

Link copied to clipboard

Returns all bits as they are accessible by the global bit index

Link copied to clipboard

Allocates a fresh byte array and writes the values of this bitset's underlying bytes to it