indexical/bitset/
bitvec.rs1use bitvec::{prelude::Lsb0, store::BitStore};
4
5use crate::{
6 bitset::BitSet,
7 pointer::{ArcFamily, RcFamily, RefFamily},
8};
9
10pub use ::bitvec::{self, vec::BitVec};
11
12impl BitSet for BitVec {
13 fn empty(size: usize) -> Self {
14 bitvec::bitvec![usize, Lsb0; 0; size]
15 }
16
17 fn contains(&self, index: usize) -> bool {
18 self[index]
19 }
20
21 fn insert(&mut self, index: usize) -> bool {
22 let contained = self[index];
23 self.set(index, true);
24 !contained
25 }
26
27 fn remove(&mut self, index: usize) -> bool {
28 let contained = self[index];
29 self.set(index, false);
30 contained
31 }
32
33 fn iter(&self) -> impl Iterator<Item = usize> {
34 self.iter_ones()
35 }
36
37 fn len(&self) -> usize {
38 self.count_ones()
39 }
40
41 fn union(&mut self, other: &Self) {
42 *self |= other;
43 }
44
45 fn intersect(&mut self, other: &Self) {
46 *self &= other;
47 }
48
49 fn invert(&mut self) {
50 for elem in self.as_raw_mut_slice() {
52 elem.store_value(!elem.load_value());
53 }
54 }
55
56 fn clear(&mut self) {
57 for elem in self.as_raw_mut_slice() {
58 elem.store_value(0);
59 }
60 }
61
62 fn subtract(&mut self, other: &Self) {
63 let mut other_copy = other.clone();
64 other_copy.invert();
65 self.intersect(&other_copy);
66 }
67
68 fn insert_all(&mut self) {
69 self.fill(true);
70 }
71
72 fn copy_from(&mut self, other: &Self) {
73 self.copy_from_bitslice(other);
74 }
75}
76
77pub type RcIndexSet<T> = crate::set::IndexSet<'static, T, BitVec, RcFamily>;
79
80pub type ArcIndexSet<T> = crate::set::IndexSet<'static, T, BitVec, ArcFamily>;
82
83pub type RefIndexSet<'a, T> = crate::set::IndexSet<'a, T, BitVec, RefFamily<'a>>;
85
86pub type RcIndexMatrix<R, C> = crate::matrix::IndexMatrix<'static, R, C, BitVec, RcFamily>;
88
89pub type ArcIndexMatrix<R, C> = crate::matrix::IndexMatrix<'static, R, C, BitVec, ArcFamily>;
91
92pub type RefIndexMatrix<'a, R, C> = crate::matrix::IndexMatrix<'a, R, C, BitVec, RefFamily<'a>>;
94
95#[test]
96fn test_bitvec() {
97 crate::test_utils::impl_test::<BitVec>();
98}