#boolean #bool #vec

boolvec

A vector of boolean stored contiguously in memory

4 releases

0.2.6 Jun 28, 2020
0.2.5 Jun 27, 2020
0.1.0 Jun 24, 2020

#978 in Data structures

Download history 91/week @ 2024-07-25 167/week @ 2024-08-01 86/week @ 2024-08-08 104/week @ 2024-08-15 55/week @ 2024-08-22 113/week @ 2024-08-29 92/week @ 2024-09-05 78/week @ 2024-09-12 76/week @ 2024-09-19 86/week @ 2024-09-26 218/week @ 2024-10-03 117/week @ 2024-10-10 73/week @ 2024-10-17 105/week @ 2024-10-24 85/week @ 2024-10-31 260/week @ 2024-11-07

556 downloads per month
Used in 3 crates (via annonars)

MIT license

54KB
1.5K SLoC

This crate provides the BoolVec structure. This is basically a wrapper around a Vec<u8> where each byte is interpreted as 8 bool.

Quick Note: Do what you want with this code, I don't really care :)

Example

// Create a new `BoolVec`
use boolvec::BoolVec;

let mut vec = BoolVec::new();

// You can push data onto it
vec.push(true);
vec.push(false);

// ... retreve it
assert_eq!(vec.get(0), Some(true));
assert_eq!(vec.get(3), None);

// ... update it
vec.set(0, false);
assert_eq!(vec.get(0), Some(false));

// You can get a reference to an unaligned boolean.
let mut boolean = vec.get_mut(1).unwrap();
assert_eq!(boolean.get(), false);

boolean.set(true);
assert_eq!(vec.get(1), Some(true));

// You can also iterate over this data (mutably or not).
let mut iter = vec.iter_mut();

iter.next().unwrap().set(true);
iter.next().unwrap().set(false);

let mut iter = vec.iter();

assert_eq!(iter.next(), Some(true));
assert_eq!(iter.next(), Some(false));
assert_eq!(iter.next(), None);

No runtime deps