Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › bit_set › Dynamic › setRangeValue Public Function setRangeValue Doc Source Public Function std.bit_set.Dynamic.setRangeValue
pub fn setRangeValue (self : *Self , range : Range , value : bool ) void Params File bit_set.zig: 843
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883 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 )));
}
}
}
Changes the value of all bits in the specified range to match the passed boolean.