mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 12:20: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) {
|
pub fn delete_column(&mut self, col: usize) {
|
||||||
assert!(col < self.cols, "column index out of bounds");
|
assert!(col < self.cols, "column index {} out of bounds for {} columns", col, self.cols);
|
||||||
for r in (0..self.rows).rev() {
|
let start = col * self.rows;
|
||||||
self.data.remove(col * self.rows + r);
|
self.data.drain(start..start + self.rows); // Efficient removal
|
||||||
}
|
|
||||||
self.cols -= 1;
|
self.cols -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user