Function setRangeValue [src]

Changes the value of all bits in the specified range to match the passed boolean.

Prototype

pub fn setRangeValue(self: *Self, range: Range, value: bool) void

Parameters

self: *Selfrange: Rangevalue: bool

Source

pub fn setRangeValue(self: *Self, range: Range, value: bool) void { assert(range.end <= self.bit_length); assert(range.start <= range.end); if (range.start == range.end) return; const start_mask_index = maskIndex(range.start); const start_bit = @as(ShiftInt, @truncate(range.start)); const end_mask_index = maskIndex(range.end); const end_bit = @as(ShiftInt, @truncate(range.end)); if (start_mask_index == end_mask_index) { var mask1 = std.math.boolMask(MaskInt, true) << start_bit; var mask2 = std.math.boolMask(MaskInt, true) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1); self.masks[start_mask_index] &= ~(mask1 & mask2); mask1 = std.math.boolMask(MaskInt, value) << start_bit; mask2 = std.math.boolMask(MaskInt, value) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1); self.masks[start_mask_index] |= mask1 & mask2; } else { var bulk_mask_index: usize = undefined; if (start_bit > 0) { self.masks[start_mask_index] = (self.masks[start_mask_index] & ~(std.math.boolMask(MaskInt, true) << start_bit)) | (std.math.boolMask(MaskInt, value) << start_bit); bulk_mask_index = start_mask_index + 1; } else { bulk_mask_index = start_mask_index; } while (bulk_mask_index < end_mask_index) : (bulk_mask_index += 1) { self.masks[bulk_mask_index] = std.math.boolMask(MaskInt, value); } if (end_bit > 0) { self.masks[end_mask_index] = (self.masks[end_mask_index] & (std.math.boolMask(MaskInt, true) << end_bit)) | (std.math.boolMask(MaskInt, value) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1))); } } }