1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/// Macro to implement common trait impls for BitSet types.
macro_rules! impl_bitset_traits {
($bitset:ident) => {
// impl std::fmt::Debug for $bitset {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// f.debug_struct(stringify!($bitset))
// .field("bits", &self.bits)
// .finish()
// }
// }
// impl Clone for $bitset {
// fn clone(&self) -> Self {
// Self {
// bits: self.bits.clone(),
// }
// }
// }
// impl PartialEq for $bitset {
// fn eq(&self, other: &Self) -> bool {
// self.bits == other.bits
// }
// }
impl<W: BitWord> BitRead for $bitset<W> {
type Iter<'b>
= Iter<'b, W>
where
Self: 'b;
#[inline(always)]
fn len(&self) -> usize {
self.len
}
#[inline]
fn is_empty(&self) -> bool {
unsafe { bitset_is_empty(self.ptr, self.len) }
}
#[inline]
fn test(&self, idx: usize) -> bool {
unsafe { bitset_test(self.ptr, self.len, idx) }
}
#[inline]
fn count_ones(&self) -> usize {
unsafe { bitset_count_ones(self.ptr, self.len) }
}
#[inline]
fn all(&self) -> bool {
unsafe { bitset_all(self.ptr, self.len) }
}
#[inline]
fn any(&self) -> bool {
unsafe { bitset_any(self.ptr, self.len) }
}
#[inline]
fn iter(&self) -> Self::Iter<'_> {
Iter::new(self.ptr, self.len)
}
}
};
}
pub(crate) use impl_bitset_traits;
macro_rules! impl_bitsetmut_traits {
($bitset:ident) => {
// impl std::fmt::Debug for $bitset {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// f.debug_struct(stringify!($bitset))
// .field("bits", &self.bits)
// .finish()
// }
// }
// impl Clone for $bitset {
// fn clone(&self) -> Self {
// Self {
// bits: self.bits.clone(),
// }
// }
// }
// impl PartialEq for $bitset {
// fn eq(&self, other: &Self) -> bool {
// self.bits == other.bits
// }
// }
impl<W: BitWord> BitWrite for $bitset<W> {
#[inline]
fn set(&mut self, idx: usize) {
unsafe { bitset_set(self.ptr, self.len, idx) };
}
#[inline]
fn reset(&mut self, idx: usize) {
unsafe { bitset_reset(self.ptr, self.len, idx) };
}
#[inline]
fn flip(&mut self, idx: usize) {
unsafe { bitset_flip(self.ptr, self.len, idx) };
}
#[inline]
fn test_and_set(&mut self, idx: usize) -> bool {
unsafe { bitset_test_and_set(self.ptr, self.len, idx) }
}
#[inline]
fn fill(&mut self) {
unsafe { bitset_fill(self.ptr, self.len) };
}
#[inline]
fn clear(&mut self) {
unsafe { bitset_clear(self.ptr, self.len) };
}
}
};
}
pub(crate) use impl_bitsetmut_traits;