@@ -17,23 +17,27 @@ pub struct BitVector {
17
17
}
18
18
19
19
impl BitVector {
20
+ #[inline]
20
21
pub fn new(num_bits: usize) -> BitVector {
21
22
let num_words = u64s(num_bits);
22
23
BitVector { data: vec![0; num_words] }
23
24
}
24
25
26
+ #[inline]
25
27
pub fn clear(&mut self) {
26
28
for p in &mut self.data {
27
29
*p = 0;
28
30
}
29
31
}
30
32
33
+ #[inline]
31
34
pub fn contains(&self, bit: usize) -> bool {
32
35
let (word, mask) = word_mask(bit);
33
36
(self.data[word] & mask) != 0
34
37
}
35
38
36
39
/// Returns true if the bit has changed.
40
+ #[inline]
37
41
pub fn insert(&mut self, bit: usize) -> bool {
38
42
let (word, mask) = word_mask(bit);
39
43
let data = &mut self.data[word];
@@ -43,6 +47,7 @@ impl BitVector {
43
47
new_value != value
44
48
}
45
49
50
+ #[inline]
46
51
pub fn insert_all(&mut self, all: &BitVector) -> bool {
47
52
assert!(self.data.len() == all.data.len());
48
53
let mut changed = false;
@@ -56,6 +61,7 @@ impl BitVector {
56
61
changed
57
62
}
58
63
64
+ #[inline]
59
65
pub fn grow(&mut self, num_bits: usize) {
60
66
let num_words = u64s(num_bits);
61
67
if self.data.len() < num_words {
@@ -64,6 +70,7 @@ impl BitVector {
64
70
}
65
71
66
72
/// Iterates over indexes of set bits in a sorted order
73
+ #[inline]
67
74
pub fn iter<'a>(&'a self) -> BitVectorIter<'a> {
68
75
BitVectorIter {
69
76
iter: self.data.iter(),
@@ -226,10 +233,12 @@ impl BitMatrix {
226
233
}
227
234
}
228
235
236
+ #[inline]
229
237
fn u64s(elements: usize) -> usize {
230
238
(elements + 63) / 64
231
239
}
232
240
241
+ #[inline]
233
242
fn word_mask(index: usize) -> (usize, u64) {
234
243
let word = index / 64;
235
244
let mask = 1 << (index % 64);
0 commit comments