pub struct Vec2d<T>(/* private fields */);
Expand description
Compact representation of a Vec<Vec<T>>
Implementations§
Source§impl<T> Vec2d<T>
impl<T> Vec2d<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty Vec2d
.
This is equivalent to
Self::with_capacity(0, 0)
.
Sourcepub fn with_capacity(vectors: usize, elements_sum: usize) -> Self
pub fn with_capacity(vectors: usize, elements_sum: usize) -> Self
Create a new empty Vec2d
with at least the specified capacities.
A Vec2d
internally contains two Vec
s, one for the elements of all
the inner vectors and one for the indices where these inner vectors
begin. vectors
is the capacity for the latter and elements_sum
is
the capacity for the former Vec
.
Sourcepub fn reserve_vectors(&mut self, additional: usize)
pub fn reserve_vectors(&mut self, additional: usize)
Reserve space for at least additional
more inner vectors. Note that
this will not reserve space for elements of the inner vectors. To that
end, use Self::reserve_elements()
.
This is essentially a wrapper around Vec::reserve()
, so the
documentation there provides more details.
Sourcepub fn reserve_elements(&mut self, additional: usize)
pub fn reserve_elements(&mut self, additional: usize)
Reserve space for at least additional
more elements in the inner
vectors. The space is shared between the inner vectors: After reserving
space for n
additional elements, pushing, e.g., two vectors with k1 + k2 <= n
elements will not lead to a reallocation.
This is essentially a wrapper around Vec::reserve()
, so the
documentation there provides more details.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
true
iff there are no inner vectors
Equivalent to self.len() == 0
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut [T]>
pub fn get_mut(&mut self, index: usize) -> Option<&mut [T]>
Get the vector at index
if there is one
Sourcepub fn push_vec(&mut self)
pub fn push_vec(&mut self)
Add an empty inner vector
Elements can be added to that vector using Self::push_element()
Sourcepub fn pop_vec(&mut self) -> bool
pub fn pop_vec(&mut self) -> bool
Remove the last vector (if there is one)
Returns true iff the outer vector was non-empty before removal.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncate the outer vector to len
inner vectors
If len
is greater or equal to self.len()
, this is a
no-op.
Sourcepub fn push_element(&mut self, element: T)
pub fn push_element(&mut self, element: T)
Push an element to the last vector
The vector list must be non-empty.
Sourcepub fn push_elements(&mut self, iter: impl IntoIterator<Item = T>)
pub fn push_elements(&mut self, iter: impl IntoIterator<Item = T>)
Extend the last vector by the elements from iter
There must be at least one inner vector (i.e.,
!self.is_empty()
).
Sourcepub fn all_elements(&self) -> &[T]
pub fn all_elements(&self) -> &[T]
Get a slice containing all elements, ignoring the boundaries of the inner vectors
Sourcepub fn all_elements_mut(&mut self) -> &mut [T]
pub fn all_elements_mut(&mut self) -> &mut [T]
Get a slice containing all elements, ignoring the boundaries of the inner vectors
Source§impl<T: Clone> Vec2d<T>
impl<T: Clone> Vec2d<T>
Sourcepub fn resize_last(&mut self, new_len: usize, value: T)
pub fn resize_last(&mut self, new_len: usize, value: T)
Resize the last vector in-place such that its length is equal to
new_len
If new_len
is greater than the current length, the vector is extended
by the difference, with each additional slot filled with value
. If
new_len
is less than len
, the Vec
is simply truncated.
Trait Implementations§
Source§impl<'a, T: Copy> Extend<&'a [T]> for Vec2d<T>
impl<'a, T: Copy> Extend<&'a [T]> for Vec2d<T>
Source§fn extend<I: IntoIterator<Item = &'a [T]>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a [T]>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)impl<T: Eq> Eq for Vec2d<T>
impl<T> StructuralPartialEq for Vec2d<T>
Auto Trait Implementations§
impl<T> Freeze for Vec2d<T>
impl<T> RefUnwindSafe for Vec2d<T>where
T: RefUnwindSafe,
impl<T> Send for Vec2d<T>where
T: Send,
impl<T> Sync for Vec2d<T>where
T: Sync,
impl<T> Unpin for Vec2d<T>where
T: Unpin,
impl<T> UnwindSafe for Vec2d<T>where
T: UnwindSafe,
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<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.