Crate bittle[−][src]
Expand description
A library for working with small and cheap bit sets and masks.
The name bittle
comes from bit
and little
.
The bit sets are entirely defined using Copy types in Rust such as u64
or [u128; 4]
who’s number of bits define the capacity of the set.
use bittle::FixedSet;
use std::mem;
let mut set = FixedSet::<u64>::empty();
assert!(!set.test(31));
set.set(31);
assert!(set.test(31));
set.unset(31);
assert!(!set.test(31));
assert_eq!(mem::size_of_val(&set), mem::size_of::<u64>());
The Mask trait can be used to abstract over the read-only side of a bit set. It has useful utilities such as iterating over masked elements through Mask::join.
use bittle::{FixedSet, Mask};
let elements = vec![10, 48, 101];
let mut m = FixedSet::<u128>::empty();
// Since set is empty, no elements are iterated over.
let mut it = m.join(&elements);
assert_eq!(it.next(), None);
m.set(1);
let mut it = m.join(&elements);
assert_eq!(it.next(), Some(&48));
assert_eq!(it.next(), None);
Examples
Macros
Construct a bit set with specific values set.
Structs
A fixed size bit set.
Traits
The trait for a bit pattern.
A trait used to check if an index is masked.
Basic numerical trait for the plumbing of a bit set. This ensures that only
primitive types can be used as the basis of a bit set backed by an array,
like [u64; 4]
and not [[u32; 2]; 4]
.