pub rec Bitset;
在 u64 字数组中存储 nbits 个位的动态位集
alloc:用于后备存储的分配器 words:指向 u64 字数组的指针 nbits:位的数量 nwords:u64 字的数量
pub fun init(alloc: *allocator.Allocator, nbits: usize) Result[Bitset, str];
创建一个所有位都已清零的位集
alloc:用于后备存储的分配器 nbits:位的数量 ret:一个新的清零后的 Bitset,或一个错误
pub fun dnit(bs: *Bitset) bool;
释放后备字数组
ret:如果内存成功释放则为 true
pub fun set(bs: *Bitset, idx: usize);
设置给定索引处的位
idx:位索引
pub fun clear(bs: *Bitset, idx: usize);
清除给定索引处的位
idx:位索引
pub fun get(bs: *Bitset, idx: usize) bool;
测试给定索引处的位
idx:位索引 ret:如果位置位则为 true,如果清零或超出范围则为 false
pub fun toggle(bs: *Bitset, idx: usize);
翻转给定索引处的位
idx:位索引
pub fun count(bs: *Bitset) usize;
计算置位(1)的数量
ret:置位计数(population count)
pub fun clear_all(bs: *Bitset);
将所有位清零
pub fun set_all(bs: *Bitset);
将所有位置 1,同时对尾随字进行掩码处理