A bit set with runtime-known size, backed by an allocated slice of usize. Thin wrapper around DynamicBitSetUnmanaged which keeps track of the allocator instance.

Fields

allocator: Allocator,

The allocator used by this bit set

unmanaged: DynamicBitSetUnmanaged = .{ },

The number of valid items in this bit set

Functions

inline fn capacity(self: Self) usize

Returns the number of bits in this bit set

fn clone(self: *const Self, new_allocator: Allocator) !Self

Creates a duplicate of this bit set, using the new allocator.

fn count(self: Self) usize

Returns the total number of set bits in this bit set.

fn deinit(self: *Self) void

deinitializes the array and releases its memory. The passed allocator must be t…

deinitializes the array and releases its memory. The passed allocator must be the same one used for init* or resize in the past.

fn eql(self: Self, other: Self) bool

Returns true iff every corresponding bit in both bit sets are the same.

fn findFirstSet(self: Self) ?usize

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

fn initEmpty(allocator: Allocator, bit_length: usize) !Self

Creates a bit set with no elements present.

fn initFull(allocator: Allocator, bit_length: usize) !Self

Creates a bit set with all elements present.

fn isSet(self: Self, index: usize) bool

Returns true if the bit at the specified index is present in the set, false oth…

Returns true if the bit at the specified index is present in the set, false otherwise.

fn iterator(self: *const Self, comptime options: IteratorOptions) Iterator(options)

Iterates through the items in the set, according to the options. The default op…

Iterates through the items in the set, according to the options. The default options (.{}) will iterate indices of set bits in ascending order. Modifications to the underlying bit set may or may not be observed by the iterator. Resizing the underlying bit set invalidates the iterator.

fn resize(self: *@This(), new_len: usize, fill: bool) !void

Resizes to a new length. If the new length is larger than the old length, fill…

Resizes to a new length. If the new length is larger than the old length, fills any added bits with fill.

fn set(self: *Self, index: usize) void

Adds a specific bit to the bit set

fn setIntersection(self: *Self, other: Self) void

Performs an intersection of two bit sets, and stores the result in the first on…

Performs an intersection of two bit sets, and stores the result in the first one. Bits in the result are set if the corresponding bits were set in both inputs. The two sets must both be the same bit_length.

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

Changes the value of all bits in the specified range to match the passed boolea…

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

fn setUnion(self: *Self, other: Self) void

Performs a union of two bit sets, and stores the result in the first one. Bits…

Performs a union of two bit sets, and stores the result in the first one. Bits in the result are set if the corresponding bits were set in either input. The two sets must both be the same bit_length.

fn setValue(self: *Self, index: usize, value: bool) void

Changes the value of the specified bit of the bit set to match the passed boole…

Changes the value of the specified bit of the bit set to match the passed boolean.

fn toggle(self: *Self, index: usize) void

Flips a specific bit in the bit set

fn toggleAll(self: *Self) void

Flips every bit in the bit set.

fn toggleFirstSet(self: *Self) ?usize

Finds the index of the first set bit, and unsets it. If no bits are set, return…

Finds the index of the first set bit, and unsets it. If no bits are set, returns null.

fn toggleSet(self: *Self, toggles: Self) void

Flips all bits in this bit set which are present in the toggles bit set. Both …

Flips all bits in this bit set which are present in the toggles bit set. Both sets must have the same bit_length.

fn unset(self: *Self, index: usize) void

Removes a specific bit from the bit set

Values

ShiftInt
undefined

The integer type used to shift a mask in this bit set