Function findLastSet [src]

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

Prototype

pub fn findLastSet(self: Self) ?usize

Parameters

self: Self

Source

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; }