Enhance column access methods to clarify usage by name and physical index

This commit is contained in:
Palash Tyagi 2025-06-22 05:00:42 +01:00
parent 349ae52629
commit 49f7558225

View File

@ -309,7 +309,7 @@ impl<T: Clone + PartialEq> Frame<T> {
)
}
/// Returns an immutable slice of the specified column's data.
/// Returns an immutable slice of the specified column's data by name.
/// Panics if the column name is not found.
pub fn column(&self, name: &str) -> &[T] {
let idx = self
@ -318,7 +318,13 @@ impl<T: Clone + PartialEq> Frame<T> {
self.matrix.column(idx)
}
/// Returns a mutable slice of the specified column's data.
/// Returns an immutable slice of the specified column's data by its physical index.
/// Panics if the index is out of bounds.
pub fn column_by_physical_idx(&self, idx: usize) -> &[T] {
self.matrix.column(idx)
}
/// Returns a mutable slice of the specified column's data by name.
/// Panics if the column name is not found.
pub fn column_mut(&mut self, name: &str) -> &mut [T] {
let idx = self
@ -327,6 +333,12 @@ impl<T: Clone + PartialEq> Frame<T> {
self.matrix.column_mut(idx)
}
/// Returns a mutable slice of the specified column's data by its physical index.
/// Panics if the index is out of bounds.
pub fn column_mut_by_physical_idx(&mut self, idx: usize) -> &mut [T] {
self.matrix.column_mut(idx)
}
// Row access methods
/// Returns an immutable view of the row for the given integer key.