Struct object_lib::collections::pvec::PVec
source · #[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,
impl<T> PVec<T>where T: Persistable,
pub fn new() -> Self
pub fn is_empty(&self) -> bool
fn get_allocator_internal(&self) -> &Arc<RwLock<BumpAllocator>>
sourcepub fn resize_to_capacity(&mut self, capacity: usize)
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.
sourcepub fn push(&mut self, e: T) -> *mut T
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.
pub fn push_at(&mut self, e: T, idx: usize)
pub fn last(&self) -> Option<&mut T>
pub fn get_ref(&self, idx: usize) -> Option<*const T>
sourcepub fn truncate(&mut self, len: usize)
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.
pub fn find<P>(&self, predicate: P) -> Option<usize>where P: Fn(&T) -> bool,
pub fn iter(&self) -> PVecIter<'_, T> ⓘ
pub fn iter_mut(&mut self) -> PVecIterMut<'_, T> ⓘ
pub fn buf_offset(&self) -> isize
pub fn get_slice<'a>( &'a self, slice_range: Range<usize> ) -> SegmentedSlice<'a, T>
unsafe fn get_section_marker_for_idx( &self, idx: usize ) -> (*const SectionMarker, usize)
unsafe fn get_section_end_marker( &mut self, marker: *const SectionMarker ) -> *mut SectionMarker
unsafe fn is_last_section(&self, marker: *const SectionMarker) -> bool
unsafe fn get_next_section_marker( &self, marker: *const SectionMarker ) -> Option<*const SectionMarker>
fn elements_in_same_segment(&self, idx_1: usize, idx_2: usize) -> bool
pub unsafe fn get_slice_as_ptr_range<'a>( &'a self, slice_range: Range<usize> ) -> Result<Range<*const T>, usize>
pub unsafe fn copy_from_vec(&mut self, other: &Vec<T>) -> bool
sourcepub fn copy_from_pvec(
&mut self,
other: &PVec<T>,
dst_start_idx: Option<usize>,
source_start_idx: Option<usize>
) -> bool
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<'a, T> IntoIterator for &'a PVec<T>where
T: Persistable,
impl<'a, T> IntoIterator for &'a PVec<T>where T: Persistable,
source§impl<T> Ord for PVec<T>where
T: Persistable + Ord,
impl<T> Ord for PVec<T>where T: Persistable + Ord,
source§impl<T> PartialEq for PVec<T>where
T: Persistable + PartialEq,
impl<T> PartialEq for PVec<T>where T: Persistable + PartialEq,
source§impl<T> PartialOrd for PVec<T>where
T: PartialOrd + Persistable,
impl<T> PartialOrd for PVec<T>where T: PartialOrd + Persistable,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl<T> Persistable for PVec<T>where
T: Persistable,
impl<T> Persistable for PVec<T>where T: Persistable,
source§impl<T> PersistentlyAllocatable for PVec<T>where
T: Persistable,
impl<T> PersistentlyAllocatable for PVec<T>where T: Persistable,
source§fn set_allocator(&mut self, allocator: Arc<RwLock<BumpAllocator>>)
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.