#traits #container #static #copy #set #storage

nightly staticbitset

类似于 std::collections::BitSet 的容器,但具有静态存储 + Copy 特性

3 个不稳定版本

0.5.2 2022年8月4日
0.5.1 2022年8月4日
0.1.1 2019年2月2日

数据结构 中排名第 2211

MIT 许可证

14KB
318

#
use staticbitset::StaticBitSet;
#[repr(usize)]
enum Hats {
    Cap,
    Top,
    Bowler,
    Beret,
    Fez,
}
use Hats::*;
use core::mem;

type HatBitSet = StaticBitSet::<{mem::variant_count::<Hats>()}>;
assert_eq!(4, mem::size_of::<HatBitSet>());

assert_eq!(8, mem::size_of::< StaticBitSet::<64> >());
assert_eq!(4, mem::size_of::< StaticBitSet::<32> >());
assert_eq!(4, mem::size_of::< StaticBitSet::<31> >());

let mut x = StaticBitSet::<64>::default();
assert!(!x.contains(Fez as usize));

x.insert(Fez as usize);
assert!(x.contains(Fez as usize));

x.clear();
assert!(!x.contains(Fez as usize));

x.set(Fez as usize, true);
assert!(x.contains(Fez as usize));

x.set(Fez as usize, false);
assert!(!x.contains(Fez as usize));
assert!(!x.contains(Bowler as usize));

for hat in x.ones().into_iter() {
   println!("Hat index: {}", hat);
}

无运行时依赖