tiny.simd.BitSet
Defined in bitset.
Source
Source: lib/simd/src/bitset.zig:67
zig
pub fn BitSet(comptime size: usize) type { requireCapacity(size); const word_count = wordsFor(size); return struct { words: [word_count]BitSet64 = @as([word_count]BitSet64, @splat(.{})), const Self = @This(); pub const capacity: usize = size; pub const max_size: usize = capacity; pub fn maxSize(_: *const Self) usize { return max_size; } pub fn set(self: *Self, index: usize) void { std.debug.assert(index < max_size); self.words[wordIndex(index)].set(bitIndex(index)); std.debug.assert(self.get(index)); } pub fn clear(self: *Self, index: usize) void { std.debug.assert(index < max_size); self.words[wordIndex(index)].clear(bitIndex(index)); std.debug.assert(!self.get(index)); } pub fn get(self: *const Self, index: usize) bool { std.debug.assert(index < max_size); return self.words[wordIndex(index)].get(bitIndex(index)); } pub fn any(self: *const Self) bool { for (&self.words) |*word| { if (word.any()) return true; } return false; } pub fn all(self: *const Self) bool { for (self.words[0 .. word_count - 1]) |word| { if (!word.all()) return false; } const remainder = max_size % 64; return if (remainder == 0) self.words[word_count - 1].all() else self.words[word_count - 1].count() == remainder; } pub fn first(self: *const Self) usize { std.debug.assert(self.any()); for (&self.words, 0..) |*word, word_index| { if (word.any()) return word_index * 64 + word.first(); } unreachable; } pub fn first0(self: *const Self) usize { std.debug.assert(!self.all()); for (&self.words, 0..) |*word, word_index| { if (!word.all()) { const index = word_index * 64 + word.first0(); std.debug.assert(index < max_size); return index; } } unreachable; } pub fn foreach(self: *const Self, function: anytype) void { for (&self.words, 0..) |*word, word_index| { visitWord(word.get64(), word_index * 64, function); } } pub fn count(self: *const Self) usize { var total: usize = 0; for (&self.words) |*word| total += word.count(); std.debug.assert(total <= max_size); return total; } };}Source: lib/simd/src/root.zig:539
zig
pub const BitSet = bitset.BitSet;Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |