[−][src]Struct crndm::vec::Vec
A contiguous growable persistent array type, written Vec<T>
but pronounced
'vector'.
PVec
is an alias name in the pool module for Vec
.
Examples
Heap::transaction(|j| { let mut vec = Vec::new(j); vec.push(1, j); vec.push(2, j); assert_eq!(vec.len(), 2); assert_eq!(vec[0], 1); assert_eq!(vec.pop(), Some(2)); assert_eq!(vec.len(), 1); vec[0] = 7; assert_eq!(vec[0], 7); vec.extend_from_slice(&[1, 2, 3], j); for x in vec.as_slice() { println!("{}", x); } assert_eq!(vec, [7, 1, 2, 3]); }).unwrap();
Implementations
impl<T: PSafe, A: MemPool> Vec<T, A>
[src]
pub const fn new(_j: &Journal<A>) -> Self
[src]
Creates an empty vector with zero capacity for the pool of the give Journal
pub fn from_slice(x: &[T], journal: &Journal<A>) -> Self
[src]
Creates an empty vector and places x
into it
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2], j); assert_eq!(vec.len(), 2); assert_eq!(vec[0], 1); assert_eq!(vec.pop(), Some(2)); assert_eq!(vec.len(), 1); vec[0] = 7; assert_eq!(vec[0], 7); vec.extend_from_slice(&[1, 2, 3], j); for x in &*vec { println!("{}", x); } assert_eq!(vec, [7, 1, 2, 3]); }).unwrap();
pub fn with_capacity(cap: usize, j: &Journal<A>) -> Self
[src]
Creates an empty Vec
with the specified capacity
The vector will be able to hold exactly capacity
elements without
reallocating. If capacity
is 0, the vector will not allocate.
It is important to note that although the returned vector has the capacity specified, the vector will have a zero length. For an explanation of the difference between length and capacity, see [Capacity and reallocation].
Examples
Heap::transaction(|j| { let mut vec = Vec::with_capacity(10, j); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); // These are all done without reallocating... for i in 0..10 { vec.push(i, j); } // ...but this may make the vector reallocate vec.push(11, j); }).unwrap();
pub const fn empty() -> Self
[src]
Creates an empty vector with zero capacity
pub fn is_empty(&self) -> bool
[src]
Returns true
if the vector contains no elements.
Examples
Heap::transaction(|j| { let mut v = Vec::new(j); assert!(v.is_empty()); v.push(1, j); assert!(!v.is_empty()); }).unwrap();
pub fn split_off(&mut self, at: usize, j: &Journal<A>) -> Self
[src]
Splits the collection into two at the given index.
Returns a newly allocated vector containing the elements in the range
[at, len)
. After the call, the original vector will be left containing
the elements [0, at)
with its previous capacity unchanged.
Panics
Panics if at > len
.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1,2,3], j); let vec2 = vec.split_off(1, j); assert_eq!(vec, [1]); assert_eq!(vec2, [2, 3]); }).unwrap();
pub fn off(&self) -> u64
[src]
Returns the offset of the vector in the persistent pool
pub fn capacity(&self) -> usize
[src]
Returns the available capacity of the vector in the persistent pool
pub unsafe fn set_len(&mut self, new_len: usize)
[src]
Forces the length of the vector to new_len
.
This is a low-level operation that maintains none of the normal
invariants of the type. Normally changing the length of a vector
is done using one of the safe operations instead, such as
truncate
, resize
, push
, or clear
.
Safety
new_len
must be less than or equal tocapacity()
.- The elements at
old_len..new_len
must be initialized.
pub fn len(&self) -> usize
[src]
Returns the length of the vector
pub fn as_slice(&self) -> &[T]
[src]
Consumes the vector and converts it into a slice
pub fn extend_from_slice(&mut self, other: &[T], j: &Journal<A>)
[src]
Copy all the elements of other
into Self
Panics
Panics if the number of elements in the vector overflows a usize
.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); let mut other = vec![4, 5, 6]; vec.extend_from_slice(&other, j); assert_eq!(vec.as_slice(), [1, 2, 3, 4, 5, 6]); }).unwrap();
pub fn shrink_to(&mut self, new_cap: usize, j: &Journal<A>)
[src]
pub fn shrink_to_fit(&mut self, j: &Journal<A>)
[src]
Shrinks the capacity of the vector as much as possible.
It will drop down as close as possible to the length but the allocator may still inform the vector that there is space for a few more elements.
Examples
Heap::transaction(|j| { let mut vec = Vec::with_capacity(10, j); vec.extend_from_slice(&[1, 2, 3], j); assert_eq!(vec.capacity(), 10); vec.shrink_to_fit(j); assert!(vec.capacity() >= 3); }).unwrap();
pub fn reserve(&mut self, additional: usize, j: &Journal<A>)
[src]
Copy all the elements of other
into Self
Panics
Panics if the number of elements in the vector overflows a usize
.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); let mut other = vec![4, 5, 6]; vec.extend_from_slice(&other, j); assert_eq!(vec.as_slice(), [1, 2, 3, 4, 5, 6]); }).unwrap();
pub fn truncate(&mut self, len: usize)
[src]
Shortens the vector, keeping the first len
elements and dropping
the rest.
If len
is greater than the vector's current length, this has no
effect.
Note that this method has no effect on the capacity. To shorten the
capacity too, use shrink_to
or shrink_to_fit
.
Examples
Truncating a five element vector to three elements, then truncating it to two:
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3, 4, 5], j); vec.truncate(3); assert_eq!(vec, [1, 2, 3]); assert_eq!(vec.capacity(), 5); // No effect on capacity vec.truncate(2); assert_eq!(vec.as_slice(), [1, 2]); assert_eq!(vec.capacity(), 5); // Capacity is shrunk to 2 }).unwrap();
No truncation occurs when len
is greater than the vector's current
length:
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); vec.truncate(8); assert_eq!(vec, [1, 2, 3]); }).unwrap();
Truncating when len == 0
is equivalent to calling the clear
method.
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); vec.truncate(0); assert_eq!(vec, []); }).unwrap();
pub fn swap_remove(&mut self, index: usize) -> T
[src]
Removes an element from the vector and returns it.
The removed element is replaced by the last element of the vector.
This does not preserve ordering, but is O(1).
Panics
Panics if index
is out of bounds.
Examples
Heap::transaction(|j| { let mut v = Vec::from_slice(&[1, 2, 3, 4], j); assert_eq!(v.swap_remove(1), 2); assert_eq!(v, [1, 4, 3]); assert_eq!(v.swap_remove(0), 1); assert_eq!(v, [3, 4]); }).unwrap();
pub fn insert(&mut self, index: usize, element: T, j: &Journal<A>)
[src]
Inserts an element at position index
within the vector, shifting all
elements after it to the right.
Panics
Panics if index > len
.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); vec.insert(1, 4, j); assert_eq!(vec, [1, 4, 2, 3]); vec.insert(4, 5, j); assert_eq!(vec, [1, 4, 2, 3, 5]); }).unwrap();
pub fn remove(&mut self, index: usize) -> T
[src]
Removes and returns the element at position index
within the vector,
shifting all elements after it to the left.
Panics
Panics if index
is out of bounds.
Examples
Heap::transaction(|j| { let mut v = Vec::from_slice(&[1, 2, 3], j); assert_eq!(v.remove(1), 2); assert_eq!(v, [1, 3]); }).unwrap();
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&T) -> bool,
[src]
F: FnMut(&T) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all elements e
such that f(&e)
returns false
.
This method operates in place, visiting each element exactly once in the
original order, and preserves the order of the retained elements.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3, 4], j); vec.retain(|&x| x % 2 == 0); assert_eq!(vec, [2, 4]); }).unwrap();
The exact order may be useful for tracking external state, like an index.
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3, 4, 5], j); let keep = [false, true, true, false, true]; let mut i = 0; vec.retain(|_| (keep[i], i += 1).0); assert_eq!(vec, [2, 3, 5]); }).unwrap();
pub fn push(&mut self, value: T, j: &Journal<A>)
[src]
Heap::transaction(|j| { Heap::transaction(|j| { Appends an element to the back of a collection.
Panics
Panics if the number of elements in the vector overflows a usize
.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2], j); vec.push(3, j); assert_eq!(vec, [1, 2, 3]); }).unwrap();
pub fn pop(&mut self) -> Option<T>
[src]
Removes the last element from a vector and returns it, or None
if it
is empty.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); assert_eq!(vec.pop(), Some(3)); assert_eq!(vec, [1, 2]); }).unwrap();
pub fn append(&mut self, other: &mut Self, j: &Journal<A>)
[src]
Moves all the elements of other
into Self
, leaving other
empty.
Panics
Panics if the number of elements in the vector overflows a usize
.
Examples
Heap::transaction(|j| { let mut vec = Vec::from_slice(&[1, 2, 3], j); let mut vec2 = Vec::from_slice(&[4, 5, 6], j); vec.append(&mut vec2, j); assert_eq!(vec, [1, 2, 3, 4, 5, 6]); assert_eq!(vec2, []); }).unwrap();
pub fn clear(&mut self)
[src]
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
Examples
Heap::transaction(|j| { let mut v = Vec::from_slice(&[1, 2, 3], j); v.clear(); assert!(v.is_empty()); }).unwrap();
pub fn cast<U, F: Fn(&T) -> U>(&self, f: F) -> Vec<U>
[src]
impl<A: MemPool> Vec<u8, A>
[src]
Trait Implementations
impl<T: PSafe, A: MemPool> AsMut<[T]> for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> AsMut<Vec<T, A>> for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> AsRef<[T]> for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> AsRef<Vec<T, A>> for Vec<T, A>
[src]
impl<T: PSafe + Debug, A: MemPool> Debug for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> Default for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> Deref for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> DerefMut for Vec<T, A>
[src]
impl<T: PSafe + Display, A: MemPool> Display for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> Drop for Vec<T, A>
[src]
impl<A: MemPool, T: PSafe + Eq> Eq for Vec<T, A>
[src]
impl<A: MemPool> From<String<A>> for Vec<u8, A>
[src]
pub fn from(string: String<A>) -> Vec<u8, A>
[src]
Converts the given String
to a vector Vec
that holds values of type u8
.
Examples
Basic usage:
Heap::transaction(|j| { let s1 = String::<Heap>::pfrom("hello world", j); let v1 = Vec::from(s1); for b in v1.as_slice() { println!("{}", b); } }).unwrap();
impl<A: MemPool, T: PSafe, I: SliceIndex<[T]>> Index<I> for Vec<T, A>
[src]
type Output = I::Output
The returned type after indexing.
pub fn index(&self, index: I) -> &Self::Output
[src]
impl<A: MemPool, T: PSafe, I: SliceIndex<[T]>> IndexMut<I> for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> IntoIterator for Vec<T, A>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIteratorHelper<T>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T: PSafe, A: MemPool> IntoIterator for &'a Vec<T, A>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = IterHelper<'a, T>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> Self::IntoIter
[src]
impl<A: MemPool, T: PSafe + Ord> Ord for Vec<T, A>
[src]
Implements ordering of vectors, lexicographically.
pub fn cmp(&self, other: &Vec<T, A>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<A: MemPool, T: PSafe + PClone<A>> PClone<A> for Vec<T, A>
[src]
pub fn pclone(&self, j: &Journal<A>) -> Self
[src]
pub fn pclone_from(&mut self, source: &Self, journal: &Journal<A>)
[src]
impl<T: Clone + PSafe, A: MemPool, '_> PFrom<&'_ [T], A> for Vec<T, A>
[src]
impl<T: Clone + PSafe, A: MemPool, '_> PFrom<&'_ mut [T], A> for Vec<T, A>
[src]
impl<A: MemPool, '_> PFrom<&'_ str, A> for Vec<u8, A>
[src]
impl<T: PSafe, A: MemPool> PFrom<Box<[T], Global>, A> for Vec<T, A>
[src]
impl<T: PSafe, A: MemPool> PSafe for Vec<T, A>
[src]
impl<T: PSafe, U: PSafe, A: MemPool, const N: usize, '_> PartialEq<&'_ [U; N]> for Vec<T, A> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T: PSafe, U: PSafe, A: MemPool, '_> PartialEq<&'_ [U]> for Vec<T, A> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T: PSafe, U: PSafe, A: MemPool, '_> PartialEq<&'_ mut [U]> for Vec<T, A> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T: PSafe, U: PSafe, A: MemPool, const N: usize> PartialEq<[U; N]> for Vec<T, A> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<T: PSafe, U: PSafe, A: MemPool> PartialEq<Vec<U, A>> for Vec<T, A> where
T: PartialEq<U>,
[src]
T: PartialEq<U>,
impl<A: MemPool, T: PSafe + PartialOrd> PartialOrd<Vec<T, A>> for Vec<T, A>
[src]
Implements comparison of vectors, lexicographically.
pub fn partial_cmp(&self, other: &Vec<T, A>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, A: MemPool> !Send for Vec<T, A>
[src]
impl<T, A: MemPool> !Sync for Vec<T, A>
[src]
impl<T, A: MemPool> !VSafe for Vec<T, A>
[src]
Auto Trait Implementations
impl<T, A> LooseTxInUnsafe for Vec<T, A> where
A: LooseTxInUnsafe,
T: LooseTxInUnsafe,
[src]
A: LooseTxInUnsafe,
T: LooseTxInUnsafe,
impl<T, A> RefUnwindSafe for Vec<T, A> where
A: RefUnwindSafe,
T: RefUnwindSafe,
[src]
A: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, A> TxInSafe for Vec<T, A> where
A: TxInSafe,
T: TxInSafe,
[src]
A: TxInSafe,
T: TxInSafe,
impl<T, A> !TxOutSafe for Vec<T, A>
[src]
impl<T, A> Unpin for Vec<T, A> where
A: Unpin,
T: Unpin,
[src]
A: Unpin,
T: Unpin,
impl<T, A> UnwindSafe for Vec<T, A> where
A: UnwindSafe,
T: UnwindSafe,
[src]
A: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, A> ToString<A> for T where
A: MemPool,
T: Display + ?Sized,
[src]
A: MemPool,
T: Display + ?Sized,
pub default fn to_pstring(&Self, &Journal<A>) -> String<A>
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,