Add BitIter::new()
.
This factors out some duplicated code.
This commit is contained in:
parent
237d54ff6c
commit
2918a7d5a9
1 changed files with 13 additions and 10 deletions
|
@ -168,11 +168,7 @@ impl<T: Idx> BitSet<T> {
|
|||
/// Iterates over the indices of set bits in a sorted order.
|
||||
#[inline]
|
||||
pub fn iter(&self) -> BitIter<'_, T> {
|
||||
BitIter {
|
||||
cur: None,
|
||||
iter: self.words.iter().enumerate(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
BitIter::new(&self.words)
|
||||
}
|
||||
|
||||
/// Duplicates the set as a hybrid set.
|
||||
|
@ -296,6 +292,17 @@ pub struct BitIter<'a, T: Idx> {
|
|||
marker: PhantomData<T>
|
||||
}
|
||||
|
||||
impl<'a, T: Idx> BitIter<'a, T> {
|
||||
#[inline]
|
||||
fn new(words: &'a [Word]) -> BitIter<'a, T> {
|
||||
BitIter {
|
||||
cur: None,
|
||||
iter: words.iter().enumerate(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Idx> Iterator for BitIter<'a, T> {
|
||||
type Item = T;
|
||||
fn next(&mut self) -> Option<T> {
|
||||
|
@ -851,11 +858,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
|
|||
pub fn iter(&self, row: R) -> BitIter<'_, C> {
|
||||
assert!(row.index() < self.num_rows);
|
||||
let (start, end) = self.range(row);
|
||||
BitIter {
|
||||
cur: None,
|
||||
iter: self.words[start..end].iter().enumerate(),
|
||||
marker: PhantomData,
|
||||
}
|
||||
BitIter::new(&self.words[start..end])
|
||||
}
|
||||
|
||||
/// Returns the number of elements in `row`.
|
||||
|
|
Loading…
Add table
Reference in a new issue