diff --git a/src/matrix/mat.rs b/src/matrix/mat.rs index 2b1c564..2f4ecba 100644 --- a/src/matrix/mat.rs +++ b/src/matrix/mat.rs @@ -170,12 +170,12 @@ impl Matrix { } } - /// Deletes a column from the matrix. + /// Deletes a column from the matrix. Panics on out-of-bounds. + /// This is O(N) where N is the number of elements. pub fn delete_column(&mut self, col: usize) { - assert!(col < self.cols, "column index out of bounds"); - for r in (0..self.rows).rev() { - self.data.remove(col * self.rows + r); - } + assert!(col < self.cols, "column index {} out of bounds for {} columns", col, self.cols); + let start = col * self.rows; + self.data.drain(start..start + self.rows); // Efficient removal self.cols -= 1; }