#[repr(C)]
pub struct PVec<T> { /* private fields */ }
Expand description

A persistable dynamic array type, which is safely movable between runtime instances.

This vector implementation trades off some complexity and space to eliminate internal fragmentation within the object it is stored in. More specifically, it models its buffer as (essentially) a linked list of sections (i.e. fixed-length arrays) of type T. See the corresponding book chapter for more details.

Implementations§

source§

impl<T> PVec<T>where T: Persistable,

source

pub fn new() -> Self

source

pub fn is_empty(&self) -> bool

source

fn get_allocator_internal(&self) -> &Arc<RwLock<BumpAllocator>>

source

pub fn resize_to_capacity(&mut self, capacity: usize)

This call will set the initial capacity of the vector. This should be called with an argument that is (roughly) of the same order-of-magnitude as the expected number of elements this vector is expected to hold at its largest, to minimize the number of sections that will have to be allocated.

source

pub fn push(&mut self, e: T) -> *mut T

Appends an element to the end of the vector, potentially allocating more space if the current capacity has already been exhausted.

source

pub fn pop(&mut self) -> Option<T>

Returns the last element from the vector (if not empty).

source

pub fn push_at(&mut self, e: T, idx: usize)

source

pub fn last(&self) -> Option<&mut T>

source

pub fn get_ref(&self, idx: usize) -> Option<*const T>

source

pub fn truncate(&mut self, len: usize)

Shortens the vector, keeping the first len elements and dropping the rest.

The allocated space of the vector remains unaffected.

source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

source

pub fn find<P>(&self, predicate: P) -> Option<usize>where P: Fn(&T) -> bool,

source

pub fn iter(&self) -> PVecIter<'_, T>

source

pub fn iter_mut(&mut self) -> PVecIterMut<'_, T>

source

pub fn buf_offset(&self) -> isize

source

pub fn get_slice<'a>( &'a self, slice_range: Range<usize> ) -> SegmentedSlice<'a, T>

source

unsafe fn get_section_marker_for_idx( &self, idx: usize ) -> (*const SectionMarker, usize)

source

unsafe fn get_section_end_marker( &mut self, marker: *const SectionMarker ) -> *mut SectionMarker

source

unsafe fn is_last_section(&self, marker: *const SectionMarker) -> bool

source

unsafe fn get_next_section_marker( &self, marker: *const SectionMarker ) -> Option<*const SectionMarker>

source

fn elements_in_same_segment(&self, idx_1: usize, idx_2: usize) -> bool

source

pub unsafe fn get_slice_as_ptr_range<'a>( &'a self, slice_range: Range<usize> ) -> Result<Range<*const T>, usize>

source

pub unsafe fn copy_from_vec(&mut self, other: &Vec<T>) -> bool

source

pub fn copy_from_pvec( &mut self, other: &PVec<T>, dst_start_idx: Option<usize>, source_start_idx: Option<usize> ) -> bool

Fast copy between PVec instances.

This method tries to repeatedly memcpy the largest possible chunks of data between two PVec instances, potentially allocating new sections in self. The segmented layout of PVec makes this method necessary if we want to have fast copying.

Trait Implementations§

source§

impl<T> Debug for PVec<T>where T: Persistable + Debug + ToString,

source§

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

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

impl<T> Index<usize> for PVec<T>where T: Persistable,

§

type Output = T

The returned type after indexing.
source§

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

Performs the indexing (container[index]) operation. Read more
source§

impl<T> IndexMut<usize> for PVec<T>where T: Persistable,

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a, T> IntoIterator for &'a PVec<T>where T: Persistable,

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = PVecIter<'a, T>

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<T> Ord for PVec<T>where T: Persistable + Ord,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T> PartialEq for PVec<T>where T: Persistable + PartialEq,

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialOrd for PVec<T>where T: PartialOrd + Persistable,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Persistable for PVec<T>where T: Persistable,

source§

fn adjust_from(&mut self, other: &Self)

Used for object moves.
source§

fn as_bytes(&self) -> &[u8] where Self: Sized,

source§

fn from_bytes(src: *mut [u8]) -> *mut Selfwhere Self: Sized,

source§

fn from_bytes_ref(src: *const [u8]) -> &'static Selfwhere Self: Sized,

source§

impl<T> PersistentlyAllocatable for PVec<T>where T: Persistable,

source§

fn set_allocator(&mut self, allocator: Arc<RwLock<BumpAllocator>>)

Sets the allocator that is going to be used by the PVec instance whenever it needs to extend its internal capacity.

NOTE This needs to be set before any subsequent calls are made that would trigger an allocation.

source§

fn get_allocator(&self) -> Option<Arc<RwLock<BumpAllocator>>>

source§

impl<T> Eq for PVec<T>where T: Persistable + Ord,

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for PVec<T>

§

impl<T> Send for PVec<T>where T: Send,

§

impl<T> Sync for PVec<T>where T: Sync,

§

impl<T> Unpin for PVec<T>where T: Unpin,

§

impl<T> !UnwindSafe for PVec<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V