BitSet
class BitSetA vector of bits growing if necessary and allowing one to set/clear/read bits from it by a bit index.
Constructors
<init>
Creates a bit set of given length filling elements using initializer
BitSet(length: Int, initializer: (Int) -> Boolean)creates an empty bit set with the specified size
BitSet(size: Int = ELEMENT_SIZE)Properties
isEmpty
True if this BitSet contains no bits set to true.
val isEmpty: BooleanlastTrueIndex
Returns an index of the last bit that has true value. Returns -1 if the set is empty.
val lastTrueIndex: Intsize
Actual number of bits available in the set. All bits with indices >= size assumed to be 0
var size: IntFunctions
clear
Clears the bits with indices between from (inclusive) and to (exclusive) to the specified value.
fun clear(from: Int, to: Int)Sets all bits in the BitSet to false.
fun clear()equals
Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:
fun equals(other: Any?): Booleanflip
Reverses the bit specified.
fun flip(index: Int)Reverses the bits with indices between from (inclusive) and to (exclusive).
fun flip(from: Int, to: Int)Reverses the bits from the range specified.
fun flip(range: IntRange)hashCode
Returns a hash code value for the object. The general contract of hashCode is:
fun hashCode(): Intintersects
Returns true if the specified BitSet has any bits set to true that are also set to true in this BitSet.
fun intersects(another: BitSet): BooleannextClearBit
Returns an index of a next bit which value is false after startIndex (inclusive).
Returns size if there is no such bits between startIndex and size - 1 assuming that the set has an infinite
sequence of false bits after (size - 1)-th.
fun nextClearBit(startIndex: Int = 0): IntnextSetBit
Returns an index of a next bit which value is true after startIndex (inclusive).
Returns -1 if there is no such bits after startIndex.
fun nextSetBit(startIndex: Int = 0): IntpreviousBit
Returns the biggest index of a bit which value is lookFor before startIndex (inclusive). Returns -1 if there is no such bits before startIndex. If startIndex >= size returns -1
fun previousBit(startIndex: Int, lookFor: Boolean): IntpreviousClearBit
Returns the biggest index of a bit which value is false before startIndex (inclusive).
Returns -1 if there is no such bits before startIndex or if startIndex == -1.
If startIndex >= size will return startIndex assuming that the set has an infinite
sequence of false bits after (size - 1)-th.
fun previousClearBit(startIndex: Int): IntpreviousSetBit
Returns the biggest index of a bit which value is true before startIndex (inclusive).
Returns -1 if there is no such bits before startIndex or if startIndex == -1.
If startIndex >= size will search from (size - 1)-th bit.
fun previousSetBit(startIndex: Int): Intset
Set the bit specified to the specified value.
fun set(index: Int, value: Boolean = true)Sets the bits with indices between from (inclusive) and to (exclusive) to the specified value.
fun set(from: Int, to: Int, value: Boolean = true)Sets the bits from the range specified to the specified value.
fun set(range: IntRange, value: Boolean = true)toString
Returns a string representation of the object.
fun toString(): String