tiny.simd.BitSet4096
Defined in bitset.
Source
Source: lib/simd/src/bitset.zig:283
zig
pub fn BitSet4096(comptime size: usize) type { requireCapacity(size); if (size > 4096) @compileError("BitSet4096 supports at most 4096 bits"); const word_count = wordsFor(size); return struct { nonzero: BitSet64 = .{}, 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); const word_index = wordIndex(index); self.words[word_index].set(bitIndex(index)); self.nonzero.set(word_index); std.debug.assert(self.get(index)); } pub fn setNonzeroBitsFrom64(self: *Self, bits: u64) void { const valid = bits & validBits(@min(max_size, 64)); std.debug.assert(valid == bits); self.words[0].setNonzeroBitsFrom64(valid); if (valid != 0) self.nonzero.set(0); } pub fn clear(self: *Self, index: usize) void { std.debug.assert(index < max_size); const word_index = wordIndex(index); self.words[word_index].clear(bitIndex(index)); if (!self.words[word_index].any()) self.nonzero.clear(word_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 { return self.nonzero.any(); } pub fn all(self: *const Self) bool { if (self.nonzero.count() != word_count) return false; return self.count() == max_size; } pub fn first(self: *const Self) usize { std.debug.assert(self.any()); const word_index = self.nonzero.first(); return word_index * 64 + self.words[word_index].first(); } 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 get64(self: *const Self) u64 { return self.words[0].get64(); } pub fn foreach(self: *const Self, function: anytype) void { var remaining_words = self.nonzero.get64(); while (remaining_words != 0) { const word_index = firstBit(remaining_words); remaining_words &= remaining_words - 1; visitWord(self.words[word_index].get64(), word_index * 64, function); } } pub fn count(self: *const Self) usize { var total: usize = 0; var remaining_words = self.nonzero.get64(); while (remaining_words != 0) { const word_index = firstBit(remaining_words); remaining_words &= remaining_words - 1; total += self.words[word_index].count(); } std.debug.assert(total <= max_size); return total; } };}Source: lib/simd/src/root.zig:541
zig
pub const BitSet4096 = bitset.BitSet4096;Complete call list
7 direct calls.
lib.simd.src.bitset.bitIndex[function] — private source atlib/simd/src/bitset.zig:407in nearest public ownertiny.simd.bitsetlib.simd.src.bitset.firstBit[function] — private source atlib/simd/src/bitset.zig:393in nearest public ownertiny.simd.bitsetlib.simd.src.bitset.requireCapacity[function] — private source atlib/simd/src/bitset.zig:423in nearest public ownertiny.simd.bitsetlib.simd.src.bitset.validBits[function] — private source atlib/simd/src/bitset.zig:415in nearest public ownertiny.simd.bitsetlib.simd.src.bitset.visitWord[function] — private source atlib/simd/src/bitset.zig:384in nearest public ownertiny.simd.bitsetlib.simd.src.bitset.wordIndex[function] — private source atlib/simd/src/bitset.zig:403in nearest public ownertiny.simd.bitsetlib.simd.src.bitset.wordsFor[function] — private source atlib/simd/src/bitset.zig:411in nearest public ownertiny.simd.bitset
Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |