1use crate::{iter::BitIter, util::*, DrainableBitSet};
2
3pub struct DrainBitIter<'a, T: 'a> {
7 iter: BitIter<&'a mut T>,
8}
9
10impl<'a, T: DrainableBitSet> DrainBitIter<'a, T> {
11 pub fn new(
16 set: &'a mut T, masks: [usize; LAYERS], prefix: [u32; LAYERS - 1],
17 ) -> Self {
18 DrainBitIter {
19 iter: BitIter::new(set, masks, prefix),
20 }
21 }
22}
23
24impl<'a, T> Iterator for DrainBitIter<'a, T>
25where T: DrainableBitSet
26{
27 type Item = Index;
28
29 fn next(&mut self) -> Option<Self::Item> {
30 let next = self.iter.next();
31 if let Some(next) = next {
32 self.iter.set.remove(next);
33 }
34 next
35 }
36}
37
38#[test]
39fn drain_all() {
40 use crate::{BitSet, BitSetLike};
41 let mut bit_set: BitSet = (0..10000).filter(|i| i % 2 == 0).collect();
42 bit_set.drain().for_each(|_| {});
43 assert_eq!(0, bit_set.iter().count());
44}