Skip to main content

ColumnStore

Struct ColumnStore 

Source
pub struct ColumnStore { /* private fields */ }
Expand description

Order-preserving, duplicate-tolerant column store.

Step .1 of the duplicate-column-label work (br-frankenpandas-b6orh, parent br-frankenpandas-ih4t0): pandas lets a DataFrame carry repeated column labels and a plain BTreeMap<String, Column> structurally cannot. This type can represent repeats while behaving exactly like the map it replaces, so the representation lands before any operation is allowed to build one (that is .4).

§Layout

  • primary — the FIRST occurrence of every distinct name. BTreeMap iterates name-sorted, which is load-bearing: columns().keys() order is observed by ~40 downstream call sites, while the user-visible column ORDER lives separately in DataFrame::column_order.
  • repeats — every occurrence after the first, kept name-sorted so ColumnStore::iter merges the two in one pass. Empty on every path that exists today: nothing in the crate constructs a duplicate yet, so the merge degenerates to a straight primary walk.

Single-valued reads (get, contains_key, Index, and everything reached through Deref) resolve to the FIRST occurrence. That is unobservable today because duplicates are still rejected at every construction site; .4 turns it into the documented rule once ops may create them.

§Why the BTreeMap spine is kept

DataFrame::columns() hands out a &BTreeMap<String, Column> and is called from 223 in-crate plus 149 downstream sites. A purely Vec-backed store cannot produce that borrow without materializing and caching a parallel BTreeMap, which would double column-map memory and add a map build per frame to the default build. Keeping primary as a real BTreeMap makes columns() a zero-cost borrow and From<BTreeMap> a move, so the ~150 frame-rebuild sites keep their current cost exactly. The fully positional Vec layout becomes affordable in .3, after .2 removes the &BTreeMap leak.

§Not yet duplicate-aware

Serialize writes primary as a map, because a JSON object cannot hold repeated keys; the wire format has to change in .4 together with the ops that can produce repeats. Likewise every method reached through Deref sees primary only. Both are safe while repeats is unreachable, and .2 removes the Deref escape hatch.

Implementations§

Source§

impl ColumnStore

Source

pub fn new() -> Self

Empty store.

Source

pub fn from_pairs(pairs: impl IntoIterator<Item = (String, Column)>) -> Self

Build from an ordered pair sequence, PRESERVING repeated names and arrival order.

Source

pub fn push(&mut self, name: String, column: Column)

Append a column at the next position, allowing repeated names.

Source

pub fn get(&self, name: &str) -> Option<&Column>

First column stored under name, if any.

Source

pub fn get_mut(&mut self, name: &str) -> Option<&mut Column>

Mutable reference to the first column stored under name, if any.

Source

pub fn get_all<'a>( &'a self, name: &'a str, ) -> impl Iterator<Item = &'a Column> + 'a

Every column stored under name, first occurrence first.

Source

pub fn occurrences(&self, name: &str) -> usize

How many columns are stored under name (0, 1, or more).

Source

pub fn contains_key(&self, name: &str) -> bool

Source

pub fn has_duplicates(&self) -> bool

Whether any column name appears more than once.

Source

pub fn len(&self) -> usize

Total column count, counting each repeat separately.

Source

pub fn is_empty(&self) -> bool

Source

pub fn name_at(&self, position: usize) -> Option<&str>

O(1) positional column name access.

Source

pub fn column_at(&self, position: usize) -> Option<&Column>

O(1) positional column access.

Source

pub fn column_at_mut(&mut self, position: usize) -> Option<&mut Column>

O(1) mutable positional column access.

Source

pub fn position_of(&self, name: &str) -> Option<usize>

First position of name, if present.

Source

pub fn positions_of(&self, name: &str) -> &[usize]

All positions of name, in encounter order.

Source

pub fn ordered_names(&self) -> impl ExactSizeIterator<Item = &String> + '_

Iterator over column names in positional (insertion) order.

Source

pub fn ordered_columns(&self) -> impl ExactSizeIterator<Item = &Column> + '_

Iterator over columns in positional (insertion) order.

Source

pub fn iter_positional( &self, ) -> impl ExactSizeIterator<Item = (&String, &Column)> + '_

Iterator over (name, column) pairs in positional (insertion) order.

Source

pub fn iter(&self) -> ColumnStoreIter<'_> ⓘ

Name-sorted walk over every column, repeats included.

Source

pub fn keys(&self) -> impl Iterator<Item = &String> + '_

Name-sorted walk over column names, repeats included.

Source

pub fn values(&self) -> impl Iterator<Item = &Column> + '_

Name-sorted walk over columns, repeats included.

Source

pub fn insert(&mut self, name: String, column: Column) -> Option<Column>

Replace the FIRST column stored under name, or append if absent. Returns the column it displaced, if any.

Source

pub fn replace_all(&mut self, name: &str, column: Column)

Replace ALL columns stored under name with copies of column, or append if absent.

Source

pub fn remove(&mut self, name: &str) -> Option<Column>

Remove EVERY column stored under name, returning the first.

Source

pub fn iter_mut(&mut self) -> ColumnStoreIterMut<'_> ⓘ

Mutable walk over all stored columns in positional order.

Source

pub fn into_ordered_pairs(self) -> Vec<(String, Column)>

Owned pairs in positional (arrival) order.

Source

pub fn reorder(&mut self, order: &[String])

Reorder columns according to order, keeping any unlisted columns at the end.

Each listed name takes the next of its stored columns in position order; a name listed more often than it is stored repeats its first placed column; a name never stored is skipped. Linear in the column count through the name -> positions lookup: it searched every slot for each name, O(n^2), and a 100k-column frame (the transpose of 100k rows) spent 26 s here.

Trait Implementations§

Source§

impl Clone for ColumnStore

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ColumnStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ColumnStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ColumnStore

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<BTreeMap<String, Column>> for ColumnStore

Source§

fn from(primary: BTreeMap<String, Column>) -> Self

Converts to this type from the input type.
Source§

impl From<ColumnStore> for BTreeMap<String, Column>

Source§

fn from(store: ColumnStore) -> Self

Converts to this type from the input type.
Source§

impl Index<&str> for ColumnStore

Source§

fn index(&self, name: &str) -> &Self::Output

Panicking lookup, matching BTreeMap’s message shape so the ~435 self.columns[name] sites keep their existing failure text.

Source§

type Output = Column

The returned type after indexing.
Source§

impl IntoIterator for ColumnStore

Source§

type Item = (String, Column)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(String, Column)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a ColumnStore

Source§

type Item = (&'a String, &'a Column)

The type of the elements being iterated over.
Source§

type IntoIter = ColumnStoreIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a mut ColumnStore

Source§

type Item = (&'a String, &'a mut Column)

The type of the elements being iterated over.
Source§

type IntoIter = ColumnStoreIterMut<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for ColumnStore

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ColumnStore

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ColumnStore

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.