pipecircuit 0.0.21

Correct. Robust. Fast. Portable. Pick four.
Documentation
use core::iter::FusedIterator;
use roaring::bitmap;

use super::{SlotSet, StableSlot};

pub struct SlotSetSlots<'set>(bitmap::Iter<'set>);
pub(in crate::storage::warp_table) struct SlotSetIntoSlots(bitmap::IntoIter);

impl Iterator for SlotSetSlots<'_> {
    type Item = StableSlot;

    fn next(&mut self) -> Option<Self::Item> {
        self.0.next().map(StableSlot::new)
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.0.size_hint()
    }
}

impl DoubleEndedIterator for SlotSetSlots<'_> {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.0.next_back().map(StableSlot::new)
    }
}

#[cfg(target_pointer_width = "64")]
impl ExactSizeIterator for SlotSetSlots<'_> {}

impl FusedIterator for SlotSetSlots<'_> {}

impl Iterator for SlotSetIntoSlots {
    type Item = StableSlot;

    fn next(&mut self) -> Option<Self::Item> {
        self.0.next().map(StableSlot::new)
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.0.size_hint()
    }
}

impl DoubleEndedIterator for SlotSetIntoSlots {
    fn next_back(&mut self) -> Option<Self::Item> {
        self.0.next_back().map(StableSlot::new)
    }
}

impl ExactSizeIterator for SlotSetIntoSlots {}
impl FusedIterator for SlotSetIntoSlots {}

impl SlotSet {
    pub fn contains(&self, slot: StableSlot) -> bool {
        self.0.contains(slot.value())
    }

    pub fn len(&self) -> u64 {
        self.0.len()
    }

    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    pub fn slots(&self) -> SlotSetSlots<'_> {
        SlotSetSlots(self.0.iter())
    }

    pub(in crate::storage::warp_table) fn into_slots(self) -> SlotSetIntoSlots {
        SlotSetIntoSlots(self.0.into_iter())
    }
}