Crates.io | yabf |
lib.rs | yabf |
version | 0.3.0 |
source | src |
created_at | 2021-03-10 15:29:57.723351 |
updated_at | 2021-10-16 14:10:12.288099 |
description | yet another (deprecated) bit field |
homepage | |
repository | https://github.com/eadf/yabf.rs |
max_upload_size | |
id | 366822 |
size | 69,802 |
This crate can be replaced with vob if you add this trait to your code:
// u32 is slightly faster for random access w/o any bit operations
pub(crate) type VobU32 = vob::Vob<u32>;
pub(crate) trait GrowingVob {
/// Will create a new Vob and fill it with `default`
fn fill(initial_size: usize, default:bool) -> VobU32;
/// Grow to fit new size, set ´bit´ to ´state´ value
fn set_grow(&mut self, bit: usize, state: bool) -> bool;
/// get() with default value `false`
fn get_f(&self, bit: usize) -> bool;
}
impl GrowingVob for VobU32 {
#[inline]
fn fill(initial_size: usize, default:bool) -> Self {
let mut v = Self::new_with_storage_type(0);
v.resize(initial_size, default);
v
}
#[inline]
fn set_grow(&mut self, bit: usize, state: bool) -> bool {
if bit >= self.len() {
self.resize(bit + 64, false);
}
self.set(bit, state)
}
#[inline]
fn get_f(&self, bit: usize) -> bool {
self.get(bit).unwrap_or(false)
}
}
Just what the world needed - yet another bit field struct.
This is a small and simple implementation. It only has the basic functionality of a bit field:
yabf::Yabf is a std::vec::Vec
based bit field
let mut a = Yabf::default();
let mut b = Yabf::with_capacity(12345);
// bits are false by default
assert_eq!(a.bit(45), false);
a.set_bit(12345, true);
assert_eq!(a.bit(12345), true);
b.set_bit(345, true);
assert_eq!(b.bit(345), true);
yabf::SmallYabf is a smallvec::SmallVec
based bit field. The struct will be entirely
stack allocated if it contains less than 129 bits.
let mut a = SmallYabf::default();
let mut b = SmallYabf::with_capacity(12345);
a.set_bit(45, false);
b.set_bit(12345, true);
assert_eq!(a.bit(45), false);
assert_eq!(b.bit(12345), true);
assert_eq!(a.bit(12345), false);
yabf::SmallYabf is enabled by default, disable like this:
yabf = {version="0.3",default-features=false}
yabf::SmallYabf is enabled by default
yabf = {version="0.3"}
Licensed under either of
at your option.