DoxigAlpha

findLastSet

Finds the index of the last set bit. If no bits are set, returns null.

Function parameters

Parameters

#

A bit set with runtime-known size, backed by an allocated slice

Types

#
DynamicBitSetUnmanaged
A bit set with runtime-known size, backed by an allocated slice
DynamicBitSet
A bit set with runtime-known size, backed by an allocated slice
IteratorOptions
Options for configuring an iterator over a bit set
Range
A range of indices within a bitset.

Returns the optimal static bit set type for the specified number

Functions

#
StaticBitSet
Returns the optimal static bit set type for the specified number
IntegerBitSet
A bit set with static size, which is backed by a single integer.
ArrayBitSet
A bit set with static size, which is backed by an array of usize.

Source

Implementation

#
pub fn findLastSet(self: Self) ?usize {
    if (self.bit_length == 0) return null;
    const bs = @bitSizeOf(MaskInt);
    var len = self.bit_length / bs;
    if (self.bit_length % bs != 0) len += 1;
    var offset: usize = len * bs;
    var idx: usize = len - 1;
    while (self.masks[idx] == 0) : (idx -= 1) {
        offset -= bs;
        if (idx == 0) return null;
    }
    offset -= @clz(self.masks[idx]);
    offset -= 1;
    return offset;
}