pub struct MultiArrayList<T: SoaRow, A: Allocator = Global> { /* private fields */ }Expand description
Struct-of-arrays list. See module docs.
Implementations§
Source§impl<T: SoaRow, A: Allocator> MultiArrayList<T, A>
impl<T: SoaRow, A: Allocator> MultiArrayList<T, A>
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
Sourcepub fn to_owned_slice(&mut self) -> Slice<T>where
A: Default,
pub fn to_owned_slice(&mut self) -> Slice<T>where
A: Default,
The caller owns the returned memory. Empties this MultiArrayList.
Only available with the global allocator (the returned Slice carries
no allocator handle). Slice has no Drop; call Slice::deinit_owned.
Sourcepub fn slice(&self) -> Slice<T>
pub fn slice(&self) -> Slice<T>
Compute pointers to the start of each field of the array.
If you need to access multiple fields, calling this may
be more efficient than calling items() multiple times.
Sourcepub fn items_named<F>(&self, name: &str) -> &[F]
pub fn items_named<F>(&self, name: &str) -> &[F]
Get the shared slice of values for field name (size-checked lookup).
Sourcepub fn items_named_mut<F>(&mut self, name: &str) -> &mut [F]
pub fn items_named_mut<F>(&mut self, name: &str) -> &mut [F]
Get the mutable slice of values for field name.
Sourcepub fn items_raw_named<F>(&self, name: &str) -> *mut F
pub fn items_raw_named<F>(&self, name: &str) -> *mut F
Raw column pointer; see [Slice::items_raw]. Obtaining the pointer is
always sound; the read/write contract is on the caller’s dereference.
Sourcepub fn get(&self, index: usize) -> ManuallyDrop<T>
pub fn get(&self, index: usize) -> ManuallyDrop<T>
Obtain all the data for one array element.
Returns ManuallyDrop<T> because the gathered struct is a bitwise
copy of column storage that the list still owns; see Slice::get.
Sourcepub fn push(&mut self, elem: T) -> Result<(), AllocError>
pub fn push(&mut self, elem: T) -> Result<(), AllocError>
Extend the list by 1 element. Allocates more memory as necessary.
Sourcepub fn append(&mut self, elem: T) -> Result<(), AllocError>
pub fn append(&mut self, elem: T) -> Result<(), AllocError>
Alias for [push] (Zig: append).
Sourcepub fn append_assume_capacity(&mut self, elem: T)
pub fn append_assume_capacity(&mut self, elem: T)
Extend the list by 1 element, asserting self.capacity is sufficient
to hold an additional item.
Sourcepub fn add_one(&mut self) -> Result<usize, AllocError>
pub fn add_one(&mut self) -> Result<usize, AllocError>
Extend the list by 1 element, returning the newly reserved index with uninitialized data. Allocates more memory as necessary.
Sourcepub fn add_one_assume_capacity(&mut self) -> usize
pub fn add_one_assume_capacity(&mut self) -> usize
Extend the list by 1 element, asserting self.capacity
is sufficient to hold an additional item. Returns the
newly reserved index with uninitialized data.
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Remove and return the last element from the list, or return None if list is empty.
Invalidates pointers to fields of the removed element.
Sourcepub fn insert(&mut self, index: usize, elem: T) -> Result<(), AllocError>
pub fn insert(&mut self, index: usize, elem: T) -> Result<(), AllocError>
Inserts an item into an ordered list. Shifts all elements after and including the specified index back by one and sets the given index to the specified element. May reallocate and invalidate iterators.
Sourcepub fn insert_assume_capacity(&mut self, index: usize, elem: T)
pub fn insert_assume_capacity(&mut self, index: usize, elem: T)
Inserts an item into an ordered list which has room for it.
pub fn append_list_assume_capacity(&mut self, other: &Self)
Sourcepub fn swap_remove(&mut self, index: usize) -> T
pub fn swap_remove(&mut self, index: usize) -> T
Remove the specified item from the list, swapping the last
item in the list into its position. Fast, but does not
retain list ordering. Returns the removed element, like pop.
Sourcepub fn ordered_remove(&mut self, index: usize) -> T
pub fn ordered_remove(&mut self, index: usize) -> T
Remove the specified item from the list, shifting items
after it to preserve order. Returns the removed element, like pop.
Sourcepub fn resize(&mut self, new_len: usize) -> Result<(), AllocError>
pub fn resize(&mut self, new_len: usize) -> Result<(), AllocError>
Adjust the list’s length to new_len.
Does not initialize added items, if any.
Sourcepub fn shrink_and_free(&mut self, new_len: usize)
pub fn shrink_and_free(&mut self, new_len: usize)
Attempt to reduce allocated capacity to new_len.
pub fn clear_and_free(&mut self)
Sourcepub fn drop_elements(&mut self)
pub fn drop_elements(&mut self)
Run every element’s destructor, then reset to empty (len = 0,
capacity retained).
Drop for this type is slab-only — it frees the SoA backing buffer
but never runs column destructors (see the Drop impl for why: bitwise
[clone] aliasing). When T has fields that own global-heap resources
and the list is the unique owner, call this before the list goes out of
scope or those payloads leak. No-op when !needs_drop::<T>().
Elements are dropped by gathering each row’s column bytes back into a
stack T (the inverse of [scatter]) and letting it drop, so every
field — not just one named column — is destructed.
Sourcepub fn shrink_retaining_capacity(&mut self, new_len: usize)
pub fn shrink_retaining_capacity(&mut self, new_len: usize)
Reduce length to new_len.
Sourcepub fn clear_retaining_capacity(&mut self)
pub fn clear_retaining_capacity(&mut self)
Invalidates all element pointers.
Sourcepub fn ensure_total_capacity(
&mut self,
new_capacity: usize,
) -> Result<(), AllocError>
pub fn ensure_total_capacity( &mut self, new_capacity: usize, ) -> Result<(), AllocError>
Modify the array so that it can hold at least new_capacity items.
Sourcepub fn ensure_unused_capacity(
&mut self,
additional_count: usize,
) -> Result<(), AllocError>
pub fn ensure_unused_capacity( &mut self, additional_count: usize, ) -> Result<(), AllocError>
Modify the array so that it can hold at least additional_count more items.
Sourcepub fn set_capacity(&mut self, new_capacity: usize) -> Result<(), AllocError>
pub fn set_capacity(&mut self, new_capacity: usize) -> Result<(), AllocError>
Modify the array so that it can hold exactly new_capacity items.
new_capacity must be greater or equal to len.
Sourcepub fn clone(&self) -> Result<Self, AllocError>where
A: Clone,
pub fn clone(&self) -> Result<Self, AllocError>where
A: Clone,
Create a copy of this list with a new backing store.
Sourcepub fn sort<C: SortContext>(&mut self, ctx: &C)
pub fn sort<C: SortContext>(&mut self, ctx: &C)
Stable sort by index-based context.
Sourcepub fn sort_span<C: SortContext>(&mut self, a: usize, b: usize, ctx: &C)
pub fn sort_span<C: SortContext>(&mut self, a: usize, b: usize, ctx: &C)
Stable sort of [a, b) by index-based context.
Sourcepub fn sort_unstable<C: SortContext>(&mut self, ctx: &C)
pub fn sort_unstable<C: SortContext>(&mut self, ctx: &C)
Unstable sort by index-based context.
Sourcepub fn sort_span_unstable<C: SortContext>(
&mut self,
a: usize,
b: usize,
ctx: &C,
)
pub fn sort_span_unstable<C: SortContext>( &mut self, a: usize, b: usize, ctx: &C, )
Unstable sort of [a, b) by index-based context.
pub fn capacity_in_bytes(capacity: usize) -> usize
Sourcepub fn memory_cost(&self) -> usize
pub fn memory_cost(&self) -> usize
Returns the amount of memory used by this list, in bytes.
Trait Implementations§
impl<T: SoaRow + Send, A: Allocator + Send> Send for MultiArrayList<T, A>
Auto Trait Implementations§
impl<T, A = Global> !Sync for MultiArrayList<T, A>
impl<T, A> Freeze for MultiArrayList<T, A>
impl<T, A> RefUnwindSafe for MultiArrayList<T, A>
impl<T, A> Unpin for MultiArrayList<T, A>
impl<T, A> UnsafeUnpin for MultiArrayList<T, A>
impl<T, A> UnwindSafe for MultiArrayList<T, A>
Blanket Implementations§
Source§impl<T> AsCtxPtr for Twhere
T: ?Sized,
impl<T> AsCtxPtr for Twhere
T: ?Sized,
Source§fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
self’s address as *mut Self for deferred-task / scopeguard /
RefPtr::init_ref ctx slots. The closures/trampolines deref it as shared
(&*p) — every method they reach is &self post-R-2, so no write
provenance is required; the *mut spelling is purely to match the
existing HasAutoFlush / RefCount ABI.