Struct indexmap::set::Slice

source ·
pub struct Slice<T> { /* private fields */ }
Expand description

A dynamically-sized slice of values in an IndexSet.

This supports indexed operations much like a [T] slice, but not any hashed operations on the values.

Unlike IndexSet, Slice does consider the order for PartialEq and Eq, and it also implements PartialOrd, Ord, and Hash.

Implementations§

source§

impl<T> Slice<T>

source

pub const fn new<'a>() -> &'a Self

Returns an empty slice.

source

pub const fn len(&self) -> usize

Return the number of elements in the set slice.

source

pub const fn is_empty(&self) -> bool

Returns true if the set slice contains no elements.

source

pub fn get_index(&self, index: usize) -> Option<&T>

Get a value by index.

Valid indices are 0 <= index < self.len()

source

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

source

pub fn first(&self) -> Option<&T>

Get the first value.

source

pub fn last(&self) -> Option<&T>

Get the last value.

source

pub fn split_at(&self, index: usize) -> (&Self, &Self)

Divides one slice into two at an index.

Panics if index > len.

source

pub fn split_first(&self) -> Option<(&T, &Self)>

Returns the first value and the rest of the slice, or None if it is empty.

source

pub fn split_last(&self) -> Option<(&T, &Self)>

Returns the last value and the rest of the slice, or None if it is empty.

source

pub fn iter(&self) -> Iter<'_, T>

Return an iterator over the values of the set slice.

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.

source

pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a T) -> Ordering,

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.

source

pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F ) -> Result<usize, usize>
where F: FnMut(&'a T) -> B, B: Ord,

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.

source

pub fn partition_point<P>(&self, pred: P) -> usize
where P: FnMut(&T) -> bool,

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.

Trait Implementations§

source§

impl<T: Clone> Clone for Box<Slice<T>>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Slice<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for &Slice<T>

source§

fn default() -> Self

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

impl<T> Default for Box<Slice<T>>

source§

fn default() -> Self

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

impl<T: Copy> From<&Slice<T>> for Box<Slice<T>>

source§

fn from(slice: &Slice<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Slice<T>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
source§

impl<T> Index<(Bound<usize>, Bound<usize>)> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: (Bound<usize>, Bound<usize>)) -> &Self::Output

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

impl<T> Index<Range<usize>> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: Range<usize>) -> &Self::Output

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

impl<T> Index<RangeFrom<usize>> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: RangeFrom<usize>) -> &Self::Output

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

impl<T> Index<RangeFull> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: RangeFull) -> &Self::Output

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

impl<T> Index<RangeInclusive<usize>> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: RangeInclusive<usize>) -> &Self::Output

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

impl<T> Index<RangeTo<usize>> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: RangeTo<usize>) -> &Self::Output

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

impl<T> Index<RangeToInclusive<usize>> for Slice<T>

§

type Output = Slice<T>

The returned type after indexing.
source§

fn index(&self, range: RangeToInclusive<usize>) -> &Self::Output

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

impl<T> Index<usize> for Slice<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

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

impl<'a, T> IntoIterator for &'a Slice<T>

§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
§

type Item = &'a T

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Box<Slice<T>>

§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
§

type Item = T

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: Ord> Ord for Slice<T>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl<T: PartialEq> PartialEq for Slice<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd> PartialOrd for Slice<T>

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T: Eq> Eq for Slice<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Slice<T>
where T: RefUnwindSafe,

§

impl<T> Send for Slice<T>
where T: Send,

§

impl<T> !Sized for Slice<T>

§

impl<T> Sync for Slice<T>
where T: Sync,

§

impl<T> Unpin for Slice<T>
where T: Unpin,

§

impl<T> UnwindSafe for Slice<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.