pub struct StableVec<T> { /* private fields */ }Expand description
A vector type with indices stable across removes & inserts, and which reuses deleted indices; comparable to Vec<Option
This is very similar to the Slab crate, which we aren’t using because Slab’s Vec entries are at
least size_of<usize>() + 1 bytes – since we’re using this primarily to store things smaller
than usize, it’s much more efficient to use this.
There’s also a stable-vec crate but that was last updated in 2019, so I think it’s unmaintained.
Honestly, at the moment, I’m not really happy with this. It’s all a bit haphazard.
Implementations§
Source§impl<T> StableVec<T>
impl<T> StableVec<T>
Sourcepub unsafe fn from_parts(
data: NonNull<MaybeUninit<T>>,
flags: BitVec,
cap: usize,
init_amt: usize,
farthest_init: Option<usize>,
) -> Self
pub unsafe fn from_parts( data: NonNull<MaybeUninit<T>>, flags: BitVec, cap: usize, init_amt: usize, farthest_init: Option<usize>, ) -> Self
§Safety
datamust be allocatedflagsmust have length = length ofdataallocationcap= length ofdataallocationinit_amt= number of initialized entries indatafarthest_init= index of initialized value at highest index, or None if no initialized values
pub fn new() -> Self
pub fn farthest_init_index(&self) -> Option<usize>
pub fn with_capacity(cap: usize) -> Self
Sourcepub fn spare_slots(&self) -> usize
pub fn spare_slots(&self) -> usize
Get the number of empty spaces within this StableVec
Sourcepub fn spare_capacity(&self) -> usize
pub fn spare_capacity(&self) -> usize
Get the number of elements that can be added to this StableVec without allocation
Sourcepub unsafe fn get_raw_unsafe(&self, index: usize) -> &MaybeUninit<T>
pub unsafe fn get_raw_unsafe(&self, index: usize) -> &MaybeUninit<T>
§Safety
index<self.cap
Sourcepub unsafe fn get_raw_unsafe_mut(&mut self, index: usize) -> &mut MaybeUninit<T>
pub unsafe fn get_raw_unsafe_mut(&mut self, index: usize) -> &mut MaybeUninit<T>
§Safety
index<self.cap
Sourcepub unsafe fn get_unsafe(&self, index: usize) -> &T
pub unsafe fn get_unsafe(&self, index: usize) -> &T
§Safety
index<self.capself[index]must already be initialized
Sourcepub unsafe fn get_unsafe_mut(&mut self, index: usize) -> &mut T
pub unsafe fn get_unsafe_mut(&mut self, index: usize) -> &mut T
§Safety
index<self.capself[index]must already be initialized
pub fn get_unchecked(&self, index: usize) -> &T
pub fn get_unchecked_mut(&mut self, index: usize) -> &mut T
pub fn get(&self, index: usize) -> Option<&T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn shrink_to_fit(&mut self)
pub fn from_vec(data: Vec<T>) -> Self
pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>]
pub fn next_push_index(&self) -> usize
pub fn push(&mut self, data: T) -> usize
pub fn remove(&mut self, index: usize) -> Option<T>
pub fn replace(&mut self, index: usize, data: T) -> Option<T>
pub fn reserve_exact(&mut self, amt: usize)
pub fn reserve(&mut self, amt: usize)
pub fn push_iter<'s, Idx: PrimInt + 'static>(
&'s mut self,
iter: impl IntoIterator<Item = T> + 's,
) -> impl Iterator<Item = Idx> + 'swhere
usize: AsPrimitive<Idx>,
pub fn extend_from_iter( &mut self, iter: impl IntoIterator<Item = T>, ) -> Vec<usize>
pub fn extend_from_other(&mut self, other: Self) -> HashMap<usize, usize>
Sourcepub unsafe fn prepare_raw_array<'s, const LEN: usize>(
&'s mut self,
) -> [&'s mut MaybeUninit<T>; LEN]
pub unsafe fn prepare_raw_array<'s, const LEN: usize>( &'s mut self, ) -> [&'s mut MaybeUninit<T>; LEN]
§Safety
- Must initialize all returned values
pub fn extend_from_slice_cloned(&mut self, slice: &[T]) -> Vec<usize>where
T: Clone,
pub fn extend_from_slice_copied(&mut self, slice: &[T]) -> Vec<usize>where
T: Copy,
pub fn as_uninit_slice(&self) -> &[MaybeUninit<T>]
pub fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<T>]
pub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn enumerate(&self) -> impl Iterator<Item = (usize, &T)>
pub fn is_init(&self, index: usize) -> bool
pub fn is_fragmented(&self) -> bool
Sourcepub unsafe fn swap_unchecked(&mut self, a: usize, b: usize)
pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize)
§Safety
a<self.capb<self.cap
pub fn swap(&mut self, a: usize, b: usize)
Sourcepub fn defragment(&mut self) -> Vec<(usize, usize)>
pub fn defragment(&mut self) -> Vec<(usize, usize)>
Partition self such that initialized values are stored contiguously from index 0; return the new locations of
each value in the form (from, to).
Sourcepub fn compress(&mut self) -> Vec<(usize, usize)>
pub fn compress(&mut self) -> Vec<(usize, usize)>
Defragment & reallocate self such that self.cap == self.init_amt.
pub fn as_slice(&self) -> Option<&[T]>
pub fn as_slice_mut(&mut self) -> Option<&mut [T]>
pub fn init_flags(&self) -> &BitVec
Trait Implementations§
Source§impl<T> FromIterator<T> for StableVec<T>
impl<T> FromIterator<T> for StableVec<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Auto Trait Implementations§
impl<T> Freeze for StableVec<T>
impl<T> RefUnwindSafe for StableVec<T>where
T: RefUnwindSafe,
impl<T> !Send for StableVec<T>
impl<T> !Sync for StableVec<T>
impl<T> Unpin for StableVec<T>
impl<T> UnwindSafe for StableVec<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.