pub struct BitVecCore<T> { /* private fields */ }
Expand description
A Core
implementation that is conceptually a BitVec
and a Vec<T>
.
This is the default core as it has quite a few advantages. For one, it does
not waste memory due to padding. The information about whether a slot is
filled or not is stored in a BitVec
and thus only takes one bit per slot.
Using a BitVec
has another important advantage: iterating over the
indices of a stable vector (i.e. without touching the actual data) is very
cache-friendly. This is due to the dense packing of information. It’s also
possible to very quickly scan the bit vector in order to find filled/empty
slots.
However, this core implementation has disadvantages, too. It manages two allocations which means that reallocating (growing or shrinking) has to perform two allocations with the underlying memory allocator. Potentially more important is the decrease of cache-friendliness when accessing elements at random. Because in the worst case, this means that each element access results in two cache-misses instead of only one.
For most use cases, this is a good choice. That’s why it’s default.
Trait Implementations§
Source§impl<T: Clone> Clone for BitVecCore<T>
impl<T: Clone> Clone for BitVecCore<T>
Source§impl<T> Core<T> for BitVecCore<T>
impl<T> Core<T> for BitVecCore<T>
Source§fn new() -> Self
fn new() -> Self
Source§fn len(&self) -> usize
fn len(&self) -> usize
len
). See the trait docs for
more information.Source§fn cap(&self) -> usize
fn cap(&self) -> usize
cap
). See the trait docs for
more information.Source§unsafe fn realloc(&mut self, new_cap: usize)
unsafe fn realloc(&mut self, new_cap: usize)
cap
of at least new_cap
. This
method should try its best to allocate exactly new_cap
. Read moreSource§unsafe fn has_element_at(&self, idx: usize) -> bool
unsafe fn has_element_at(&self, idx: usize) -> bool
idx
. Read moreSource§unsafe fn remove_at(&mut self, idx: usize) -> T
unsafe fn remove_at(&mut self, idx: usize) -> T
idx
and returns it. Read moreSource§unsafe fn get_unchecked(&self, idx: usize) -> &T
unsafe fn get_unchecked(&self, idx: usize) -> &T
idx
. Read moreSource§unsafe fn get_unchecked_mut(&mut self, idx: usize) -> &mut T
unsafe fn get_unchecked_mut(&mut self, idx: usize) -> &mut T
idx
. Read moreSource§fn clear(&mut self)
fn clear(&mut self)
len
to 0. Read moreSource§unsafe fn swap(&mut self, a: usize, b: usize)
unsafe fn swap(&mut self, a: usize, b: usize)
a
and b
. That is: the element
and the “filled/empty” status are swapped. The slots at indices a
and b
can be empty or filled. Read moreSource§unsafe fn first_filled_slot_from(&self, idx: usize) -> Option<usize>
unsafe fn first_filled_slot_from(&self, idx: usize) -> Option<usize>
idx
, returning the
index of the first filled slot that is found. Read moreSource§unsafe fn first_filled_slot_below(&self, idx: usize) -> Option<usize>
unsafe fn first_filled_slot_below(&self, idx: usize) -> Option<usize>
idx - 1
, returning the
index of the first filled slot that is found. Read more