Skip to content

std.bitset

bits 0..n-1, 64 per word, in an arena; index past the end panics

pub BitSet :: struct {
words: []u64,
n: usize,
}
  • n: how many bits
pub len :: fn(self: *Self) -> usize
pub has :: fn(self: *Self, i: usize) -> bool
pub set :: fn(self: *Self, i: usize)
pub unset :: fn(self: *Self, i: usize)
pub toggle :: fn(self: *Self, i: usize)
pub put :: fn(self: *Self, i: usize, on: bool)

set or clear bit i

pub count :: fn(self: *Self) -> usize

number of set bits

pub set_all :: fn(self: *Self)
pub clear_all :: fn(self: *Self)
pub union_with :: fn(self: *Self, other: *BitSet)

self |= other; same length required

pub intersect_with :: fn(self: *Self, other: *BitSet)

self &= other

pub subtract :: fn(self: *Self, other: *BitSet)

self &= ~other

pub ones :: fn(self: *Self) -> Ones

set bits, smallest first

pub Ones :: struct {
s: *BitSet,
word: usize,
rest: u64,
}

iterator from BitSet.ones

  • word: the word being looked at
  • rest: its bits not given yet
pub next :: fn(self: *Self) -> ?usize
pub make :: fn(a: *Arena, n: usize) -> BitSet

n clear bits in a