/
githubmirror
/
thin-provisioning-tools
Обзор
Документация
Войти
/
githubmirror
/
thin-provisioning-tools
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/utils/ranged_bitset_iter.rs
38 строк
922 B
Joe Thornber
[utils] Introduce RangedBitsetIter to iterate a specific range of bits
08 окт 2025, 07:23
08 окт 2025, 07:23
1bc8efa
Код
Авторство
О чём код?
use fixedbitset::FixedBitSet; use std::ops::Range; pub struct RangedBitsetIter<'a> { bitset: &'a FixedBitSet, range: Range<usize>, current: usize, } impl<'a> RangedBitsetIter<'a> { pub fn new(bitset: &'a FixedBitSet, range: Range<usize>) -> Self { let current = range.start; Self { bitset, range, current, } } } impl<'a> Iterator for RangedBitsetIter<'a> { type Item = u64; fn next(&mut self) -> Option<Self::Item> { while self.current < self.range.end { let index = self.current; self.current += 1; if self.bitset.contains(index) { return Some(index as u64); } } None } } // This impl is safe because FixedBitset is already Sync and Send unsafe impl<'a> Send for RangedBitsetIter<'a> {} unsafe impl<'a> Sync for RangedBitsetIter<'a> {}