mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00:01 +00:00
Enhance delete_column method to improve efficiency of column removal
This commit is contained in:
parent
20727a2b91
commit
8574d86abc
@ -170,12 +170,12 @@ impl<T: Clone> Matrix<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user