pub struct Slice<T> { /* private fields */ }
Expand description
Implementations§
Source§impl<T> Slice<T>
impl<T> Slice<T>
Sourcepub fn get_index(&self, index: usize) -> Option<&T>
pub fn get_index(&self, index: usize) -> Option<&T>
Get a value by index.
Valid indices are 0 <= index < self.len()
.
Sourcepub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Self>
pub fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Self>
Returns a slice of values in the given range of indices.
Valid indices are 0 <= index < self.len()
.
Sourcepub fn split_at(&self, index: usize) -> (&Self, &Self)
pub fn split_at(&self, index: usize) -> (&Self, &Self)
Divides one slice into two at an index.
Panics if index > len
.
Sourcepub fn split_first(&self) -> Option<(&T, &Self)>
pub fn split_first(&self) -> Option<(&T, &Self)>
Returns the first value and the rest of the slice,
or None
if it is empty.
Sourcepub fn split_last(&self) -> Option<(&T, &Self)>
pub fn split_last(&self) -> Option<(&T, &Self)>
Returns the last value and the rest of the slice,
or None
if it is empty.
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
Search over a sorted set for a value.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search
for more details.
Computes in O(log(n)) time, which is notably less scalable than looking the value up in
the set this is a slice from using IndexSet::get_index_of
, but this can also position
missing values.
Sourcepub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
Search over a sorted set with a comparator function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by
for more details.
Computes in O(log(n)) time.
Sourcepub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
Search over a sorted set with an extraction function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by_key
for more details.
Computes in O(log(n)) time.
Sourcepub fn partition_point<P>(&self, pred: P) -> usize
pub fn partition_point<P>(&self, pred: P) -> usize
Returns the index of the partition point of a sorted set according to the given predicate (the index of the first element of the second partition).
See slice::partition_point
for more details.
Computes in O(log(n)) time.