use bitvec::{prelude::Lsb0, store::BitStore};
use crate::{
bitset::BitSet,
pointer::{ArcFamily, RcFamily, RefFamily},
};
pub use ::bitvec::{self, vec::BitVec};
impl BitSet for BitVec {
fn empty(size: usize) -> Self {
bitvec::bitvec![usize, Lsb0; 0; size]
}
fn contains(&self, index: usize) -> bool {
self[index]
}
fn insert(&mut self, index: usize) -> bool {
let contained = self[index];
self.set(index, true);
!contained
}
fn remove(&mut self, index: usize) -> bool {
let contained = self[index];
self.set(index, false);
contained
}
fn iter(&self) -> impl Iterator<Item = usize> {
self.iter_ones()
}
fn len(&self) -> usize {
self.count_ones()
}
fn union(&mut self, other: &Self) {
*self |= other;
}
fn intersect(&mut self, other: &Self) {
*self &= other;
}
fn invert(&mut self) {
for elem in self.as_raw_mut_slice() {
elem.store_value(!elem.load_value());
}
}
fn clear(&mut self) {
for elem in self.as_raw_mut_slice() {
elem.store_value(0);
}
}
fn subtract(&mut self, other: &Self) {
let mut other_copy = other.clone();
other_copy.invert();
self.intersect(&other_copy);
}
fn insert_all(&mut self) {
self.fill(true);
}
fn copy_from(&mut self, other: &Self) {
self.copy_from_bitslice(other);
}
}
pub type RcIndexSet<T> = crate::set::IndexSet<'static, T, BitVec, RcFamily>;
pub type ArcIndexSet<T> = crate::set::IndexSet<'static, T, BitVec, ArcFamily>;
pub type RefIndexSet<'a, T> = crate::set::IndexSet<'a, T, BitVec, RefFamily<'a>>;
pub type RcIndexMatrix<R, C> = crate::matrix::IndexMatrix<'static, R, C, BitVec, RcFamily>;
pub type ArcIndexMatrix<R, C> = crate::matrix::IndexMatrix<'static, R, C, BitVec, ArcFamily>;
pub type RefIndexMatrix<'a, R, C> = crate::matrix::IndexMatrix<'a, R, C, BitVec, RefFamily<'a>>;
#[test]
fn test_bitvec() {
crate::test_utils::impl_test::<BitVec>();
}