A bit set with runtime-known size, backed by an allocated slice of usize. The allocator must be tracked externally by the user.
Fields
bit_length: usize = 0,
The number of valid items in this bit set
masks: [*]MaskInt = empty_masks_ptr,
The bit masks, ordered with lower indices first. Padding bits at the end must be zeroed.
Functions
fn clone(self: *const Self, new_allocator: Allocator) !Self
Creates a duplicate of this bit set, using the new allocator.
fn deinit(self: *Self, allocator: Allocator) 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. If bit_length is not zero, deinit m…
Creates a bit set with no elements present. If bit_length is not zero, deinit must eventually be called.
fn initFull(allocator: Allocator, bit_length: usize) !Self
Creates a bit set with all elements present. If bit_length is not zero, deinit …
Creates a bit set with all elements present. If bit_length is not zero, deinit must eventually be called.
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(), allocator: Allocator, new_len: usize, fill: bool) !void
Resizes to a new bit_length. If the new length is larger than the old length, …
Resizes to a new bit_length. If the new length is larger than the old length, fills any added bits with
fill
. If new_len is not zero, deinit must eventually be called.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 subsetOf(self: Self, other: Self) bool
Returns true iff the first bit set is the subset of the second one.
fn supersetOf(self: Self, other: Self) bool
Returns true iff the first bit set is the superset of the second one.
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.