Skip to content

Commit

Permalink
Fix DynamicBitSet.setAll bug with padding bits
Browse files Browse the repository at this point in the history
  • Loading branch information
nurpax committed Dec 22, 2024
1 parent 595ec94 commit 7d162c2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/std/bit_set.zig
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,13 @@ pub const DynamicBitSetUnmanaged = struct {

/// Set all bits to 1.
pub fn setAll(self: *Self) void {
const masks_len = numMasks(self.bit_length);
// TODO doesn't seem like this keeps the last bits zero??
@memset(self.masks[0..masks_len], std.math.maxInt(MaskInt));
const num_masks = numMasks(self.bit_length);
@memset(self.masks[0..num_masks], std.math.maxInt(MaskInt));
if (num_masks > 0) {
const padding_bits = num_masks * @bitSizeOf(MaskInt) - self.bit_length;
const last_item_mask = (~@as(MaskInt, 0)) >> @as(ShiftInt, @intCast(padding_bits));
self.masks[num_masks - 1] = last_item_mask;
}
}

/// Flips a specific bit in the bit set
Expand Down

0 comments on commit 7d162c2

Please sign in to comment.