bittle

github crates.io docs.rs build status

A library for working with bitsets.

The name bittle comes from bit and little. Small bitsets!

This crate defines the [Bits] and [OwnedBits] traits which allows for generically interacting with and manipulating bit sets over types such as u128, [u32; 4], or even slices like &[u8].


Usage

Add bittle to your Cargo.toml:

toml [dependencies] bittle = "0.3.2"


Examples

```rust use std::mem;

use bittle::Bits;

let mut set = 0u64;

assert!(!set.test(31)); set.set(31); assert!(set.test(31)); set.unset(31); assert!(!set.test(31));

asserteq!(mem::sizeofval(&set), mem::sizeof::()); ```

Some other interesting operations, such as [Bits::join] are available, allowing bitsets to act like masks over other iterators:

```rust use bittle::Bits;

let elements = vec![10, 48, 101]; let mut m = 0u128;

// 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); asserteq!(it.next(), Some(&48)); asserteq!(it.next(), None); ```