Struct flatk::Offsets[][src]

pub struct Offsets<O = Vec<usize>>(_);
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

Separate the offsets into two groups overlapping by one chunk at the given index.

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.

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.

Returns an iterator over chunk sizes represented by the stored Offsets.

Returns an iterator over offsets.

Returns an iterator over offset values.

Returns an iterator over offset ranges.

Construct a set Offsets from a given set of offsets.

Panics

The given offsets must be a non-empty collection, otherwise this function will panic.

An unchecked version of the new constructor.

Safety

Calling this function with empty offsets may cause undefined behaviour in safe APIs.

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());

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());

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());

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

Performs the conversion.

Performs the conversion.

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.

Remove all elements from the current set without necessarily deallocating the space previously used. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

A default set of offsets must allocate.

Returns the “default value” for a type. Read more

Constructs a potentially invalid instance of a type. Read more

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.

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Convert ClumpedOffsets into owned Offsets.

This function causes allocations.

Performs the conversion.

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);

Creates a value from an iterator. Read more

Gets the value in the set at this index.

Gets the value in the set at this index. Read more

Gets the value in the set at this index.

Gets the value in the set at this index. Read more

Gets the value in the set at this index.

Gets the value in the set at this index. Read more

A version of offset_value without bounds checking.

Safety

It is assumed that index is strictly less than self.num_offsets().

Get the total number of offsets.

This is one more than the number of chunks represented.

Get the length of the chunk at the given index. Read more

Get the length of the chunk at the given index without bounds checking. Read more

Return the raw value corresponding to the offset at the given index. Read more

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(). Read more

A version of offset without bounds checking. Read more

Get the last offset. Read more

Get the first offset. Read more

Get the raw value corresponding to the last offset.

Get the raw value corresponding to the first offset.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Return the [begin..end) bound of the chunk at the given index.

Safety Read more

Returns an iterator over offset value and chunk size pairs.

Returns a parallel iterator over chunk sizes represented by the stored Offsets.

Returns an iterator over offset ranges represented by the stored Offsets.

Returns an iterator over chunk sizes represented by the stored Offsets.

Returns an iterator over offset values represented by the stored Offsets.

Attempts to isolate a value in the given set at this index. Read more

Attempts to isolate a value in the given set at this index. Read more

Attempts to isolate a value in the given set at this index. Read more

Attempts to isolate a value in the given set at this index. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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.

Owned element of the set.

The most basic element contained by this collection. If this collection contains other collections, this type should be different than Elem. Read more

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.

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.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Return a value at the given index. This is provided as the checked version of get that will panic if the equivalent get call is None, which typically means that the given index is out of bounds. Read more

Return a value at the given index. Read more

Performs the conversion.

Unchecked version of isolate. Read more

Return a value at the given index. This is provided as the checked version of try_isolate that will panic if the equivalent try_isolate call is None, which typically means that the given index is out of bounds. Read more

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.