File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " sparse-bin-mat"
3- version = " 0.3 .0"
3+ version = " 0.4 .0"
44authors = [" maxtremblay <maxtremblay>" ]
55edition = " 2018"
66description = " A sparse implementation of a binary matrix optimized for row operations"
Original file line number Diff line number Diff line change @@ -226,8 +226,11 @@ impl<T: Deref<Target = [usize]>> SparseBinVecBase<T> {
226226 /// assert_eq!(iter.next(), Some(3));
227227 /// assert_eq!(iter.next(), None);
228228 /// ```
229- pub fn non_trivial_positions < ' a > ( & ' a self ) -> impl Iterator < Item = usize > + ' a {
230- self . positions . iter ( ) . cloned ( )
229+ pub fn non_trivial_positions < ' a > ( & ' a self ) -> NonTrivialPositions < ' a > {
230+ NonTrivialPositions {
231+ positions : & self . positions ,
232+ index : 0 ,
233+ }
231234 }
232235
233236 /// Returns the concatenation of two vectors.
@@ -424,6 +427,22 @@ impl<T: Deref<Target = [usize]>> fmt::Display for SparseBinVecBase<T> {
424427 }
425428}
426429
430+ pub struct NonTrivialPositions < ' vec > {
431+ positions : & ' vec [ usize ] ,
432+ index : usize ,
433+ }
434+
435+ impl < ' vec > Iterator for NonTrivialPositions < ' vec > {
436+ type Item = usize ;
437+
438+ fn next ( & mut self ) -> Option < Self :: Item > {
439+ self . positions . get ( self . index ) . map ( |position| {
440+ self . index += 1 ;
441+ * position
442+ } )
443+ }
444+ }
445+
427446#[ cfg( test) ]
428447mod test {
429448 use super :: * ;
You can’t perform that action at this time.
0 commit comments