From 8574d86abc66b4c8cce0da398362eafd5e032525 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 3 May 2025 00:26:21 +0100 Subject: [PATCH] Enhance delete_column method to improve efficiency of column removal --- src/matrix/mat.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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; }