@@ -21,11 +21,11 @@ impl<T> SparseVector<T>
2121where
2222 T : Clone + Copy + Default ,
2323{
24- pub fn new ( ) -> Self { Self { entries : Vec :: new ( ) } }
24+ pub const fn new ( ) -> Self { Self { entries : Vec :: new ( ) } }
2525
2626 pub fn clear ( & mut self ) { self . entries . clear ( ) ; }
2727
28- pub fn iter ( & self ) -> SparseVectorIter < ' _ , T > { SparseVectorIter { vector : self , index : 0 } }
28+ pub const fn iter ( & self ) -> SparseVectorIter < ' _ , T > { SparseVectorIter { vector : self , index : 0 } }
2929}
3030
3131/// Basic iterator struct to go over matrix
4141 pub ( crate ) index : usize ,
4242}
4343
44- impl < ' a , T > Iterator for SparseVectorIter < ' a , T >
44+ impl < T > Iterator for SparseVectorIter < ' _ , T >
4545where
4646 T : Clone + Copy + Default ,
4747{
8686 fn index_mut ( & mut self , index : usize ) -> & mut T {
8787 // TODO: Beautify me
8888
89- let highest_so_far: i32 = match self . entries . last ( ) {
90- None => -1 ,
91- Some ( x) => x. index as i32 ,
92- } ;
89+ let highest_so_far: i32 = self . entries . last ( ) . map_or ( -1 , |x| x. index as i32 ) ;
9390
9491 if index as i32 <= highest_so_far {
9592 unimplemented ! ( "We still need to implement unsorted insertion. As of today, you need to insert element in strictly ascending order." ) ;
@@ -126,7 +123,7 @@ where
126123 pub fn row ( & self , row : usize ) -> & SparseVector < T > { & self . vectors [ row] }
127124
128125 #[ inline]
129- pub fn row_iter ( & self ) -> SparseMatrixIter < ' _ , T > { SparseMatrixIter { matrix : self , index : 0 } }
126+ pub const fn row_iter ( & self ) -> SparseMatrixIter < ' _ , T > { SparseMatrixIter { matrix : self , index : 0 } }
130127}
131128
132129impl < T > Index < ( usize , usize ) > for SparseMatrix < T >
0 commit comments