pub trait GrowthWithConstantTimeAccess: Growth {
    // Required methods
    fn get_fragment_and_inner_indices_unchecked(
        &self,
        element_index: usize,
    ) -> (usize, usize);
    fn fragment_capacity_of(&self, fragment_index: usize) -> usize;

    // Provided methods
    fn get_ptr<T>(
        &self,
        fragments: &[Fragment<T>],
        index: usize,
    ) -> Option<*const T> { ... }
    fn get_ptr_mut<T>(
        &self,
        fragments: &mut [Fragment<T>],
        index: usize,
    ) -> Option<*mut T> { ... }
    fn get_ptr_mut_and_indices<T>(
        &self,
        fragments: &mut [Fragment<T>],
        index: usize,
    ) -> Option<(*mut T, usize, usize)> { ... }
}
Expand description

Growth strategy of a split vector which allows for constant time access to the elements.

Required Methods§

source

fn get_fragment_and_inner_indices_unchecked( &self, element_index: usize, ) -> (usize, usize)

O(1) Returns the location of the element with the given element_index on the split vector as a tuple of (fragment-index, index-within-fragment).

Notice that unlike the Growth::get_fragment_and_inner_indices:

  • this method does not receive the current state of the split vector,
  • therefore, it does not perform bounds check,
  • and hence, returns the expected fragment and within-fragment indices for any index computed by the constant access time function.
source

fn fragment_capacity_of(&self, fragment_index: usize) -> usize

O(1) Returns the capacity of the fragment with the given fragment_index.

Provided Methods§

source

fn get_ptr<T>( &self, fragments: &[Fragment<T>], index: usize, ) -> Option<*const T>

O(1) Returns a pointer to the index-th element of the split vector of the fragments.

Returns None if index-th position does not belong to the split vector; i.e., if index is out of cumulative capacity of fragments.

§Safety

This method allows to write to a memory which is greater than the split vector’s length. On the other hand, it will never return a pointer to a memory location that the vector does not own.

source

fn get_ptr_mut<T>( &self, fragments: &mut [Fragment<T>], index: usize, ) -> Option<*mut T>

O(1) Returns a mutable reference to the index-th element of the split vector of the fragments.

Returns None if index-th position does not belong to the split vector; i.e., if index is out of cumulative capacity of fragments.

§Safety

This method allows to write to a memory which is greater than the split vector’s length. On the other hand, it will never return a pointer to a memory location that the vector does not own.

source

fn get_ptr_mut_and_indices<T>( &self, fragments: &mut [Fragment<T>], index: usize, ) -> Option<(*mut T, usize, usize)>

O(1) Returns a mutable reference to the index-th element of the split vector of the fragments together with the index of the fragment that the element belongs to and index of the element withing the respective fragment.

Returns None if index-th position does not belong to the split vector; i.e., if index is out of cumulative capacity of fragments.

§Safety

This method allows to write to a memory which is greater than the split vector’s length. On the other hand, it will never return a pointer to a memory location that the vector does not own.

Object Safety§

This trait is not object safe.

Implementors§