pub unsafe trait GetOffset {
// Required methods
unsafe fn offset_value_unchecked(&self, index: usize) -> usize;
fn num_offsets(&self) -> usize;
// Provided methods
fn chunk_len(&self, chunk_index: usize) -> usize { ... }
unsafe fn chunk_len_unchecked(&self, chunk_index: usize) -> usize { ... }
fn offset_value(&self, index: usize) -> usize { ... }
fn offset(&self, index: usize) -> usize { ... }
unsafe fn offset_unchecked(&self, index: usize) -> usize { ... }
fn last_offset(&self) -> usize { ... }
fn first_offset(&self) -> usize { ... }
fn last_offset_value(&self) -> usize { ... }
fn first_offset_value(&self) -> usize { ... }
}Expand description
Manipulate a non-empty collection of offsets.
§Safety
The implementing type must ensure that there is always at least one offset in the container.
That is num_offsets() never returns 0.
If that is not inherent in the collection, the implementor should make sure to override the functions in this trait that make this assumption.
Required Methods§
Sourceunsafe 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
The given index must be less than self.len() to avoid undefined behaviour.
Sourcefn num_offsets(&self) -> usize
fn num_offsets(&self) -> usize
Get the total number of offsets.
Provided Methods§
Sourcefn chunk_len(&self, chunk_index: usize) -> usize
fn chunk_len(&self, chunk_index: usize) -> usize
Get the length of the chunk at the given index.
Returns the distance between offsets at index and index + 1.
§Panics
This funciton will panic if chunk_index+1 is greater than or equal to
self.num_offsets().
Sourceunsafe fn chunk_len_unchecked(&self, chunk_index: usize) -> usize
unsafe fn chunk_len_unchecked(&self, chunk_index: usize) -> usize
Get the length of the chunk at the given index without bounds checking.
Returns the distance between offsets at index and index + 1.
§Safety
May cause undefined behaviour if chunk_index+1 is greater than or equal to
self.num_offsets().
Sourcefn offset_value(&self, index: usize) -> usize
fn offset_value(&self, index: usize) -> usize
Return the raw value corresponding to the offset at the given index.
Using first_* and last_* variants for getting first and last offsets are preferred
since they don’t require bounds checking.
§Panics
This function panics if index is greater than or equal to self.len().
§Example
use flatk::*;
let s = Offsets::new(vec![2,5,6,8]);
assert_eq!(2, s.offset_value(0));
assert_eq!(5, s.offset_value(1));
assert_eq!(6, s.offset_value(2));
assert_eq!(8, s.offset_value(3));Sourcefn offset(&self, index: usize) -> usize
fn offset(&self, index: usize) -> usize
Returns the offset at the given index with respect to (minus) the first offset.
This function returns the total length of data if index is equal to
self.len().
§Panics
This function panics if index is greater than or equal to self.len().
§Example
use flatk::*;
let s = Offsets::new(vec![2,5,6,8]);
assert_eq!(0, s.offset(0));
assert_eq!(3, s.offset(1));
assert_eq!(4, s.offset(2));
assert_eq!(6, s.offset(3));Sourceunsafe fn offset_unchecked(&self, index: usize) -> usize
unsafe fn offset_unchecked(&self, index: usize) -> usize
A version of offset without bounds checking.
§Safety
It is assumed that index is strictly less than self.len().
Sourcefn last_offset(&self) -> usize
fn last_offset(&self) -> usize
Get the last offset.
Since offsets are never empty by construction, this will always work.
Sourcefn first_offset(&self) -> usize
fn first_offset(&self) -> usize
Get the first offset.
This should always return 0.
Sourcefn last_offset_value(&self) -> usize
fn last_offset_value(&self) -> usize
Get the raw value corresponding to the last offset.
Sourcefn first_offset_value(&self) -> usize
fn first_offset_value(&self) -> usize
Get the raw value corresponding to the first offset.