pub trait GrowthWithConstantTimeAccess: Growth {
// Required method
fn get_fragment_and_inner_indices_unchecked(
&self,
element_index: usize,
) -> (usize, usize);
// Provided methods
unsafe fn get_ptr_mut<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<*mut T> { ... }
unsafe 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§
sourcefn get_fragment_and_inner_indices_unchecked(
&self,
element_index: usize,
) -> (usize, usize)
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.
Provided Methods§
sourceunsafe fn get_ptr_mut<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<*mut T>
unsafe 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.
sourceunsafe fn get_ptr_mut_and_indices<T>(
&self,
fragments: &mut [Fragment<T>],
index: usize,
) -> Option<(*mut T, usize, usize)>
unsafe 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.