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
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BitSetIterator<'a, BSA: BitSetAware>
{
bit_set: &'a BitSet<BSA>,
word_index: usize,
relative_bit_index_within_word: usize,
}
impl<'a, BSA: BitSetAware> Iterator for BitSetIterator<'a, BSA>
{
type Item = BSA;
#[inline(always)]
fn next(&mut self) -> Option<Self::Item>
{
while likely!(self.word_index != self.bit_set.0.len())
{
let word = * self.bit_set.0.get_unchecked_safe(self.word_index);
if likely!(word == 0)
{
self.word_index += 1;
continue
}
while likely!(self.relative_bit_index_within_word < BitSet::<BSA>::BitsInAWord)
{
if word & (1 << self.relative_bit_index_within_word) != 0
{
let result = Some(BSA::hydrate(((self.word_index * size_of::<usize>() * BitsInAByte) + self.relative_bit_index_within_word) as u16));
self.relative_bit_index_within_word += 1;
if self.relative_bit_index_within_word == BitSet::<BSA>::BitsInAWord
{
self.relative_bit_index_within_word = 0;
self.word_index +=1 ;
}
return result
}
self.relative_bit_index_within_word += 1;
}
self.word_index += 1;
self.relative_bit_index_within_word = 0;
}
None
}
}
impl<'a, BSA: BitSetAware> BitSetIterator<'a, BSA>
{
#[inline(always)]
fn reset(&mut self)
{
self.word_index = 0;
self.relative_bit_index_within_word = 0;
}
}