pub struct NamedList {
list: List,
index: HashMap<String, usize>,
}Expand description
A named list with O(1) name-based element lookup.
Wraps a List and builds a HashMap<String, usize> index of element names
on construction. Use this when you need to access multiple elements by name
from the same list — each lookup is O(1) instead of O(n).
§When to Use
| Pattern | Type |
|---|---|
| Single named lookup | List::get_named is fine |
| Multiple named lookups | NamedList (O(n) build + O(1) per lookup) |
| Positional access only | List — no indexing overhead |
§Name Handling
NAand empty-string names are excluded from the index- If duplicate names exist, the last occurrence wins
- Positional access via
get_indexis always available
Fields§
§list: List§index: HashMap<String, usize>Implementations§
Source§impl NamedList
impl NamedList
Sourcepub fn as_data_frame(&self) -> Result<DataFrameView, DataFrameError>
pub fn as_data_frame(&self) -> Result<DataFrameView, DataFrameError>
Promote this named list to a DataFrameView.
Validates that all columns have equal length, then sets the class
attribute to "data.frame" and adds compact integer row.names.
§Errors
Returns DataFrameError::UnequalLengths if columns differ in length.
Source§impl NamedList
impl NamedList
Sourcepub fn new(list: List) -> Option<Self>
pub fn new(list: List) -> Option<Self>
Build a NamedList from a List, indexing all non-empty, non-NA names.
Returns None if the list has no names attribute.
Sourcepub fn get<T>(&self, name: &str) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
pub fn get<T>(&self, name: &str) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
Get an element by name with O(1) lookup, converting to type T.
Returns None if the name is not found or conversion fails.
Sourcepub fn get_raw(&self, name: &str) -> Option<SEXP>
pub fn get_raw(&self, name: &str) -> Option<SEXP>
Get a raw SEXP element by name with O(1) lookup.
Sourcepub fn get_index<T>(&self, idx: isize) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
pub fn get_index<T>(&self, idx: isize) -> Option<T>where
T: TryFromSexp<Error = SexpError>,
Get element at 0-based index and convert to type T.
Falls through to List::get_index — no name lookup involved.