#compile-time

fixed-bitset

A bitset whose size is fixed at compile-time

1 unstable release

0.0.1 Apr 30, 2019

#571 in #compile-time

MIT license

13KB
277 lines

fixed-bitset

A bitset whose size is fixed at compile-time.

use fixed_bitset::Bitset;
use typenum::consts::*;

let mut set = Bitset::<U100>::new();

set.insert(20);
set.insert(70);
// set.insert(100); // WILL PANIC!

let values: Vec<usize> = set.iter().collect();
assert_eq!(values, vec![20, 70]);

let mut superset = set.clone();
superset.insert(50);

assert!(superset.is_superset(&set));
assert!(set.is_subset(&superset));


let difference = &superset - &set;
assert_eq!(difference.iter().collect::<Vec<_>>(), vec![50]);
assert!(difference.is_disjoint(&set));

lib.rs:

A fixed-size, stack-allocated bitset.

use fixed_bitset::Bitset;
use typenum::consts::*;

let mut set = Bitset::<U100>::new();

set.insert(20);
set.insert(70);
// set.insert(100); // WILL PANIC!

let values: Vec<usize> = set.iter().collect();
assert_eq!(values, vec![20, 70]);

let mut superset = set.clone();
superset.insert(50);

assert!(superset.is_superset(&set));
assert!(set.is_subset(&superset));


let difference = &superset - &set;
assert_eq!(difference.iter().collect::<Vec<_>>(), vec![50]);
assert!(difference.is_disjoint(&set));

Dependencies

~410KB