std.BitSet: add setAll and unsetAll methods

This commit is contained in:
Andrew Kelley 2023-11-03 19:49:39 -07:00
parent 815b85d8a2
commit 09d13104be

View File

@ -859,6 +859,18 @@ pub const DynamicBitSetUnmanaged = struct {
self.masks[maskIndex(index)] &= ~maskBit(index);
}
/// Set all bits to 0.
pub fn unsetAll(self: *Self) void {
const masks_len = numMasks(self.bit_length);
@memset(self.masks[0..masks_len], 0);
}
/// Set all bits to 1.
pub fn setAll(self: *Self) void {
const masks_len = numMasks(self.bit_length);
@memset(self.masks[0..masks_len], std.math.maxInt(MaskInt));
}
/// Flips a specific bit in the bit set
pub fn toggle(self: *Self, index: usize) void {
assert(index < self.bit_length);