Struct BitVecCore

Source
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>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Core<T> for BitVecCore<T>

Source§

fn new() -> Self

Creates an empty instance without any elements. Must not allocate memory. Read more
Source§

fn len(&self) -> usize

Returns the length of this core (the len). See the trait docs for more information.
Source§

unsafe fn set_len(&mut self, new_len: usize)

Sets the len to a new value. Read more
Source§

fn cap(&self) -> usize

Returns the capacity of this core (the cap). See the trait docs for more information.
Source§

unsafe fn realloc(&mut self, new_cap: usize)

Reallocates the memory to have a cap of at least new_cap. This method should try its best to allocate exactly new_cap. Read more
Source§

unsafe fn has_element_at(&self, idx: usize) -> bool

Checks if there exists an element with index idx. Read more
Source§

unsafe fn insert_at(&mut self, idx: usize, elem: T)

Inserts elem at the index idx. Does not updated the used_len. Read more
Source§

unsafe fn remove_at(&mut self, idx: usize) -> T

Removes the element at index idx and returns it. Read more
Source§

unsafe fn get_unchecked(&self, idx: usize) -> &T

Returns a reference to the element at the index idx. Read more
Source§

unsafe fn get_unchecked_mut(&mut self, idx: usize) -> &mut T

Returns a mutable reference to the element at the index idx. Read more
Source§

fn clear(&mut self)

Deletes all elements without deallocating memory. Drops all existing elements. Sets len to 0. Read more
Source§

unsafe fn swap(&mut self, a: usize, b: usize)

Swaps the two slots with indices 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 more
Source§

unsafe fn first_filled_slot_from(&self, idx: usize) -> Option<usize>

Performs a forwards search starting at index idx, returning the index of the first filled slot that is found. Read more
Source§

unsafe fn first_filled_slot_below(&self, idx: usize) -> Option<usize>

Performs a backwards search starting at index idx - 1, returning the index of the first filled slot that is found. Read more
Source§

unsafe fn first_empty_slot_from(&self, idx: usize) -> Option<usize>

Performs a forwards search starting at index idx, returning the index of the first empty slot that is found. Read more
Source§

unsafe fn first_empty_slot_below(&self, idx: usize) -> Option<usize>

Performs a backwards search starting at index idx - 1, returning the index of the first empty slot that is found. Read more
Source§

impl<T> Debug for BitVecCore<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for BitVecCore<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send> Send for BitVecCore<T>

Source§

impl<T: Sync> Sync for BitVecCore<T>

Auto Trait Implementations§

§

impl<T> Freeze for BitVecCore<T>

§

impl<T> RefUnwindSafe for BitVecCore<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for BitVecCore<T>

§

impl<T> UnwindSafe for BitVecCore<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.