pub struct Offsets<O = Vec<usize>>(/* private fields */);Expand description
A collection of offsets into another collection. This newtype is intended to verify basic invariants about offsets into another collection, namely that the collection is monotonically increasing and non-empty.
Implementations§
Source§impl<O: RemovePrefix + Set> Offsets<O>
impl<O: RemovePrefix + Set> Offsets<O>
Sourcepub unsafe fn remove_prefix_unchecked(&mut self, n: usize)
pub unsafe fn remove_prefix_unchecked(&mut self, n: usize)
Unchecked version of RemovePrefix::remove_prefix.
§Safety
This function may cause undefined behaviour in safe APIs if calling this function produces
an empty offsets collection.
Source§impl Offsets<&[usize]>
impl Offsets<&[usize]>
Sourcepub unsafe fn remove_suffix_unchecked(&mut self, n: usize)
pub unsafe fn remove_suffix_unchecked(&mut self, n: usize)
Remove n offsets from the end.
§Safety
This function may cause undefined behaviour in safe APIs if calling this function produces
an empty offsets collection.
Source§impl<O: AsRef<[usize]> + Set> Offsets<O>
impl<O: AsRef<[usize]> + Set> Offsets<O>
Source§impl<O: AsRef<[usize]>> Offsets<O>
impl<O: AsRef<[usize]>> Offsets<O>
Source§impl<O> Offsets<O>
impl<O> Offsets<O>
pub fn into_inner(self) -> O
Source§impl<O: AsMut<[usize]>> Offsets<O>
impl<O: AsMut<[usize]>> Offsets<O>
Sourcepub fn move_back(&mut self, at: usize, by: usize)
pub fn move_back(&mut self, at: usize, by: usize)
Moves an offset back by a specified amount.
This effectively transfers by elements to the specified at chunk from the preceeding chunk.
§Panics
This function panics if at is out of bounds.
If at it zero, the beginning of the indexed range is simply extended, but an overflow
panic will be caused if the first offset is moved below zero since offsets are represented
by unsigned integers.
It is a logic error to move an offset past its preceeding offset because this will break the monotonicity of the offset sequence, which can cause panics from other function on the Offsets.
§Example
use flatk::Offsets;
let mut o = Offsets::new(vec![0, 4, 9]);
o.move_back(1, 2);
assert_eq!(o, vec![0, 2, 9].into());Sourcepub fn move_forward(&mut self, at: usize, by: usize)
pub fn move_forward(&mut self, at: usize, by: usize)
Moves an offset forward by a specified amount.
This effectively transfers by elements to the specified at chunk from the succeeding chunk.
If at indexes the last offset, then the indexed range is simply increased.
§Panics
This function panics if at is out of bounds.
It is a logic error to move an offset past its succeeding offset because this will break the monotonicity of the offset sequence, which can cause panics from other function on the Offsets.
§Example
use flatk::Offsets;
let mut o = Offsets::new(vec![0, 4, 9]);
o.move_forward(1, 2);
assert_eq!(o, vec![0, 6, 9].into());Sourcepub fn extend_last(&mut self, by: usize)
pub fn extend_last(&mut self, by: usize)
Extend the last offset.
This effectively increases the last chunk size.
This function is the same as self.move_forward(self.len() - 1, by).
§Example
use flatk::Offsets;
let mut o = Offsets::new(vec![0, 4, 9]);
o.extend_last(2);
assert_eq!(o, vec![0, 4, 11].into());Sourcepub fn shrink_last(&mut self, by: usize)
pub fn shrink_last(&mut self, by: usize)
Shrink the last offset.
This effectively decreases the last chunk size.
This function is the same as self.move_back(self.len() - 1, by).
§Panics
It is a logic error to move an offset past its preceeding offset because this will break the monotonicity of the offset sequence, which can cause panics from other function on the Offsets.
§Example
use flatk::Offsets;
let mut o = Offsets::new(vec![0, 4, 9]);
o.shrink_last(2);
assert_eq!(o, vec![0, 4, 7].into());Trait Implementations§
Source§impl<O: AsRef<[usize]>> BinarySearch<usize> for Offsets<O>
impl<O: AsRef<[usize]>> BinarySearch<usize> for Offsets<O>
Source§fn binary_search(&self, off: &usize) -> Result<usize, usize>
fn binary_search(&self, off: &usize) -> Result<usize, usize>
Binary search the offsets for a given offset off.
off is expected to be with respect to the beginning of the range represented by the
current offsets. In other words, we are searching for offsets, not raw offset values
stored in Offsets.
The semantics of this function are identical to Rust’s std::slice::binary_search.
Source§impl Extend<usize> for Offsets
impl Extend<usize> for Offsets
Source§fn extend<T: IntoIterator<Item = usize>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = usize>>(&mut self, iter: T)
Extend this set of offsets with a given iterator of offsets.
This operation automatically shifts the merged offsets in the iterator
to start from the last offset in self.
Note that there will be 1 less offset added to self than produced by
iter since the first offset is only used to determine the relative
magnitude of the rest and corresponds to the last offset in self.
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)Source§impl<O: AsRef<[usize]> + Set> From<ClumpedOffsets<O>> for Offsets
impl<O: AsRef<[usize]> + Set> From<ClumpedOffsets<O>> for Offsets
Source§fn from(clumped_offsets: ClumpedOffsets<O>) -> Self
fn from(clumped_offsets: ClumpedOffsets<O>) -> Self
Convert ClumpedOffsets into owned Offsets.
This function causes allocations.
Source§impl<O: AsRef<[usize]> + Set> From<Offsets<O>> for ClumpedOffsets
impl<O: AsRef<[usize]> + Set> From<Offsets<O>> for ClumpedOffsets
Source§fn from(offsets: Offsets<O>) -> Self
fn from(offsets: Offsets<O>) -> Self
Convert Offsets to owned ClumpedOffsets.
This function causes allocations.
§Example
use flatk::{Offsets, ClumpedOffsets};
let offsets = Offsets::new(vec![0, 3, 6, 9, 12, 16, 20, 24, 27, 30, 33, 36, 39]);
let clumped_offsets = ClumpedOffsets::new(vec![0, 4, 7, 12], vec![0, 12, 24, 39]);
assert_eq!(ClumpedOffsets::from(offsets), clumped_offsets);Source§impl<O: FromIterator<usize> + AsRef<[usize]>> FromIterator<usize> for Offsets<O>
impl<O: FromIterator<usize> + AsRef<[usize]>> FromIterator<usize> for Offsets<O>
Source§impl<O: AsRef<[usize]>> GetOffset for Offsets<O>
impl<O: AsRef<[usize]>> GetOffset for Offsets<O>
Source§unsafe fn offset_value_unchecked(&self, index: usize) -> usize
unsafe fn offset_value_unchecked(&self, index: usize) -> usize
A version of offset_value without bounds checking.
§Safety
It is assumed that index is strictly less than self.num_offsets().
Source§fn num_offsets(&self) -> usize
fn num_offsets(&self) -> usize
Get the total number of offsets.
This is one more than the number of chunks represented.
Source§fn chunk_len(&self, chunk_index: usize) -> usize
fn chunk_len(&self, chunk_index: usize) -> usize
Source§unsafe fn chunk_len_unchecked(&self, chunk_index: usize) -> usize
unsafe fn chunk_len_unchecked(&self, chunk_index: usize) -> usize
Source§fn offset_value(&self, index: usize) -> usize
fn offset_value(&self, index: usize) -> usize
Source§fn offset(&self, index: usize) -> usize
fn offset(&self, index: usize) -> usize
data if index is equal to
self.len(). Read moreSource§unsafe fn offset_unchecked(&self, index: usize) -> usize
unsafe fn offset_unchecked(&self, index: usize) -> usize
offset without bounds checking. Read moreSource§fn last_offset(&self) -> usize
fn last_offset(&self) -> usize
Source§fn first_offset(&self) -> usize
fn first_offset(&self) -> usize
Source§fn last_offset_value(&self) -> usize
fn last_offset_value(&self) -> usize
Source§fn first_offset_value(&self) -> usize
fn first_offset_value(&self) -> usize
Source§impl<'a> IntoOffsetValuesAndSizes for Offsets<&'a [usize]>
impl<'a> IntoOffsetValuesAndSizes for Offsets<&'a [usize]>
Source§fn into_offset_values_and_sizes(self) -> OffsetValuesAndSizes<'a> ⓘ
fn into_offset_values_and_sizes(self) -> OffsetValuesAndSizes<'a> ⓘ
Returns an iterator over offset value and chunk size pairs.
type Iter = OffsetValuesAndSizes<'a>
Source§impl<'a> IntoParOffsetValuesAndSizes for Offsets<&'a [usize]>
impl<'a> IntoParOffsetValuesAndSizes for Offsets<&'a [usize]>
Source§impl<'a> IntoRanges for Offsets<&'a [usize]>
impl<'a> IntoRanges for Offsets<&'a [usize]>
Source§impl<'a> IntoValues for Offsets<&'a [usize]>
impl<'a> IntoValues for Offsets<&'a [usize]>
Source§fn into_values(self) -> OffsetValues<'a> ⓘ
fn into_values(self) -> OffsetValues<'a> ⓘ
Returns an iterator over offset values represented by the stored Offsets.
type Iter = OffsetValues<'a>
Source§impl<O: Isolate<Range<usize>>> IsolateIndex<Offsets<O>> for Range<usize>
impl<O: Isolate<Range<usize>>> IsolateIndex<Offsets<O>> for Range<usize>
Source§impl<O: Isolate<usize>> IsolateIndex<Offsets<O>> for usize
impl<O: Isolate<usize>> IsolateIndex<Offsets<O>> for usize
Source§impl<O: RemovePrefix + Set> RemovePrefix for Offsets<O>
impl<O: RemovePrefix + Set> RemovePrefix for Offsets<O>
Source§fn remove_prefix(&mut self, n: usize)
fn remove_prefix(&mut self, n: usize)
Remove the first n offsets.
§Panics
This function will panic if all offsets are removed, which violates the Offsets invariant
that there must always be at least one offset.
Source§impl<'a> SplitOffsetsAt for Offsets<&'a [usize]>
impl<'a> SplitOffsetsAt for Offsets<&'a [usize]>
Source§fn split_offsets_with_intersection_at(
self,
mid: usize,
) -> (Offsets<&'a [usize]>, Offsets<&'a [usize]>, usize)
fn split_offsets_with_intersection_at( self, mid: usize, ) -> (Offsets<&'a [usize]>, Offsets<&'a [usize]>, usize)
Same as split_offsets_at, but in addition, return the offset of the middle element
(intersection): this is the value offsets[mid] - offsets[0].
§Panics
Calling this function with an empty slice or with mid greater than or equal to its length
will cause a panic.
Source§fn split_offsets_at(
self,
mid: usize,
) -> (Offsets<&'a [usize]>, Offsets<&'a [usize]>)
fn split_offsets_at( self, mid: usize, ) -> (Offsets<&'a [usize]>, Offsets<&'a [usize]>)
Splits a slice of offsets at the given index into two slices such that each
slice is a valid slice of offsets. This means that the element at index
mid is shared between the two output slices.
§Panics
Calling this function with an empty slice or with mid greater than or equal to its length
will cause a panic.
impl<O: Copy> Copy for Offsets<O>
impl<O> StructuralPartialEq for Offsets<O>
impl<O: Viewed> Viewed for Offsets<O>
Auto Trait Implementations§
impl<O> Freeze for Offsets<O>where
O: Freeze,
impl<O> RefUnwindSafe for Offsets<O>where
O: RefUnwindSafe,
impl<O> Send for Offsets<O>where
O: Send,
impl<O> Sync for Offsets<O>where
O: Sync,
impl<O> Unpin for Offsets<O>where
O: Unpin,
impl<O> UnwindSafe for Offsets<O>where
O: 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<'a, S, I> Get<'a, I> for Swhere
I: GetIndex<'a, S>,
impl<'a, S, I> Get<'a, I> for Swhere
I: GetIndex<'a, S>,
type Output = <I as GetIndex<'a, S>>::Output
fn get(&self, idx: I) -> Option<<I as GetIndex<'a, S>>::Output>
Source§fn at(&self, idx: I) -> Self::Output
fn at(&self, idx: I) -> Self::Output
get that will panic if the equivalent get call is None,
which typically means that the given index is out of bounds. Read more