[−][src]Struct small_ord_set::SmallOrdSet
A set represented by a sorted SmallVec
.
Implementations
impl<A, K, V> SmallOrdSet<A> where
A: Array<Item = KeyValuePair<K, V>>,
K: Ord,
[src]
A: Array<Item = KeyValuePair<K, V>>,
K: Ord,
pub fn insert_value(&mut self, key: K, value: V) -> bool
[src]
Inserts a key-value pair into the map.
This function is a convenience wrapper around insert
pub fn replace_value(&mut self, key: K, value: V) -> Option<V>
[src]
Replaces a key-value pair in the map.
This function is a convenience wrapper around replace
pub fn remove_value(&mut self, key: &K) -> Option<V>
[src]
Removes a key-value pair from the map.
This function is a convenience wrapper around remove
pub fn get_value<'a>(&'a self, key: &K) -> Option<&'a V> where
K: 'a,
[src]
K: 'a,
Gets a reference to the value for a key in the map.
This function is a convenience wrapper around get
pub fn get_value_mut<'a>(&'a mut self, key: &K) -> Option<&'a mut V> where
K: 'a,
[src]
K: 'a,
Gets a mutable reference to the value for a key in the map.
This function is a convenience wrapper around get_mut
.
Unlike get_mut
, it prevents changing the order of elements by only returning the value part of
the pair.
pub fn keys<'a>(&'a self) -> impl Iterator<Item = &'a K> + Clone where
KeyValuePair<K, V>: 'a,
[src]
KeyValuePair<K, V>: 'a,
Get an iterator over all keys in the map.
pub fn values<'a>(&'a self) -> impl Iterator<Item = &'a V> + Clone where
KeyValuePair<K, V>: 'a,
[src]
KeyValuePair<K, V>: 'a,
Get an iterator over all values in the map.
impl<A: Array> SmallOrdSet<A>
[src]
pub fn new() -> Self
[src]
Make a new, empty, SmallOrdSet
.
pub fn as_slice(&self) -> &[A::Item]
[src]
Get a slice containing the whole set in sorted order.
pub fn capacity(&self) -> usize
[src]
The number of elements the set can hold without reallocating
pub fn clear(&mut self)
[src]
Remove all elements from the set.
pub fn drain<R>(&mut self, range: R) -> Drain<'_, A> where
R: RangeBounds<usize>,
[src]
R: RangeBounds<usize>,
Creates a draining iterator that removes the specified range in the set and yields the removed items.
Note 1: The element range is removed even if the iterator is only partially consumed or not consumed at all.
Note 2: It is unspecified how many elements are removed from the set
if the Drain
value is leaked.
Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the set.
pub fn grow(&mut self, new_cap: usize)
[src]
Re-allocate to set the capacity to max(new_cap, inline_size())
.
Panics if new_cap
is less than the set's length.
pub fn inline_size(&self) -> usize
[src]
The maximum number of elements this set can hold inline
pub fn into_vec(self) -> SmallVec<A>
[src]
Convert the set into the inner SmallVec
.
pub fn len(&self) -> usize
[src]
The number of elements in the set.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the vector is empty.
pub fn reserve(&mut self, additional: usize)
[src]
Reserve capacity for additional
more elements to be inserted.
May reserve more space to avoid frequent reallocations.
pub fn reserve_exact(&mut self, additional: usize)
[src]
Reserve the minimum capacity for additional
more elements to be inserted.
Panics if the new capacity overflows usize
.
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&mut A::Item) -> bool,
[src]
F: FnMut(&mut A::Item) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all elements e
such that f(&e)
returns false
.
This method operates in place and preserves the order of the retained
elements.
pub fn from_vec_unchecked(vec: SmallVec<A>) -> Self
[src]
Construct a new SmallOrdSet
from a sorted SmallVec
. vec
must
be sorted and may not contain duplicate elements.
Safety
Failure to uphold the restrictions on the vec
parameter will not cause memory unsafety,
however the result of any operations on the resulting SmallOrdSet
is unspecified.
pub fn iter(&self) -> Iter<'_, A::Item>
[src]
Construct an iterator over the set, in ascending order.
pub fn first(&self) -> Option<&A::Item>
[src]
Returns a reference to the first element in the set, if any. This element is always the minimum of all elements in the set.
pub fn last(&self) -> Option<&A::Item>
[src]
Returns a reference to the first element in the set, if any. This element is always the maximum of all elements in the set.
impl<A> SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
pub fn append(&mut self, other: &mut Self)
[src]
Moves all elements from other
into Self
, leaving other empty
.
pub fn from_vec(vec: SmallVec<A>) -> Self
[src]
Construct a new SmallOrdSet
from a SmallVec
. The vector will be
sorted and duplicate elements removed.
pub fn from_buf(buf: A) -> Self
[src]
Constructs a new SmallOrdSet
on the stack from an A
without
copying elements.
pub fn insert(&mut self, element: A::Item) -> bool
[src]
Adds an element to the set.
If the set did not have this element present, true
is returned.
If the set did have this element present, false
is returned, and the
entry is not updated.
Examples
use small_ord_set::SmallOrdSet; let mut set = SmallOrdSet::<[u32; 4]>::new(); assert_eq!(set.insert(2), true); assert_eq!(set.insert(2), false); assert_eq!(set.len(), 1);
pub fn replace(&mut self, element: A::Item) -> Option<A::Item>
[src]
Adds a element to the set, replacing the existing element, if any, that is equal to the given one. Returns the replaced element.
Examples
use small_ord_set::SmallOrdSet; let mut set = SmallOrdSet::<[u32; 4]>::new(); assert_eq!(set.replace(2), None); assert_eq!(set.replace(2), Some(2)); assert_eq!(set.len(), 1);
pub fn remove<Q: ?Sized>(&mut self, element: &Q) -> Option<A::Item> where
A::Item: Borrow<Q>,
Q: Ord,
[src]
A::Item: Borrow<Q>,
Q: Ord,
Removes and returns the element in the set, if any, that is equal to the given one.
The element may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use small_ord_set::SmallOrdSet; let mut set = SmallOrdSet::<[u32; 4]>::new(); set.insert(2); assert_eq!(set.remove(&2), Some(2)); assert_eq!(set.remove(&2), None);
pub fn contains<Q: ?Sized>(&self, element: &Q) -> bool where
A::Item: Borrow<Q>,
Q: Ord,
[src]
A::Item: Borrow<Q>,
Q: Ord,
Returns true
if the set contains an element.
The value may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
Examples
use small_ord_set::SmallOrdSet; let set = SmallOrdSet::from_buf([1, 2, 3]); assert_eq!(set.contains(&1), true); assert_eq!(set.contains(&4), false);
pub fn get<Q: ?Sized>(&self, element: &Q) -> Option<&A::Item> where
A::Item: Borrow<Q>,
Q: Ord,
[src]
A::Item: Borrow<Q>,
Q: Ord,
Returns a reference to the element in the set, if any, that is equal to the given value.
The value may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
pub fn get_mut<Q: ?Sized>(&mut self, element: &Q) -> Option<&mut A::Item> where
A::Item: Borrow<Q>,
Q: Ord,
[src]
A::Item: Borrow<Q>,
Q: Ord,
Returns a mutable reference to the element in the set, if any, that is equal to the given value. It is an error to mutate the element such that its ordering changes.
The value may be any borrowed form of the set's element type, but the ordering on the borrowed form must match the ordering on the element type.
pub fn entry<Q>(&mut self, key: Q) -> Entry<'_, A, Q> where
A::Item: Borrow<Q>,
Q: Ord,
[src]
A::Item: Borrow<Q>,
Q: Ord,
Gets the given key's corresponding entry in the map for in-place manipulation.
Examples
use small_ord_set::{SmallOrdSet, KeyValuePair}; let mut letters = SmallOrdSet::<[KeyValuePair<char, u32>; 8]>::new(); for ch in "a short treatise on fungi".chars() { let counter = letters.entry(ch).or_insert(0); *counter += 1; } assert_eq!(letters.get_value(&'s'), Some(&2)); assert_eq!(letters.get_value(&'t'), Some(&3)); assert_eq!(letters.get_value(&'u'), Some(&1)); assert_eq!(letters.get_value(&'y'), None);
Trait Implementations
impl<A: Array> AsRef<[<A as Array>::Item]> for SmallOrdSet<A>
[src]
impl<A: Array> Borrow<[<A as Array>::Item]> for SmallOrdSet<A>
[src]
impl<A> Clone for SmallOrdSet<A> where
A: Array,
A::Item: Clone,
[src]
A: Array,
A::Item: Clone,
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
[src]
impl<A> Debug for SmallOrdSet<A> where
A: Array,
A::Item: Debug,
[src]
A: Array,
A::Item: Debug,
impl<A: Array> Default for SmallOrdSet<A>
[src]
impl<A: Array> Deref for SmallOrdSet<A>
[src]
type Target = [A::Item]
The resulting type after dereferencing.
pub fn deref(&self) -> &Self::Target
[src]
impl<A> Eq for SmallOrdSet<A> where
A: Array,
A::Item: Eq,
[src]
A: Array,
A::Item: Eq,
impl<A> Extend<<A as Array>::Item> for SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
pub fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = A::Item>,
[src]
I: IntoIterator<Item = A::Item>,
pub fn extend_one(&mut self, item: A)
[src]
pub fn extend_reserve(&mut self, additional: usize)
[src]
impl<A> From<A> for SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
impl<A> From<SmallVec<A>> for SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
impl<A> FromIterator<<A as Array>::Item> for SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
pub fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A::Item>,
[src]
T: IntoIterator<Item = A::Item>,
impl<A> Hash for SmallOrdSet<A> where
A: Array,
A::Item: Hash,
[src]
A: Array,
A::Item: Hash,
pub fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A: Array, I: SliceIndex<[A::Item]>> Index<I> for SmallOrdSet<A>
[src]
type Output = I::Output
The returned type after indexing.
pub fn index(&self, index: I) -> &Self::Output
[src]
impl<A: Array> IntoIterator for SmallOrdSet<A>
[src]
type IntoIter = IntoIter<A>
Which kind of iterator are we turning this into?
type Item = A::Item
The type of the elements being iterated over.
pub fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, A: Array> IntoIterator for &'a SmallOrdSet<A>
[src]
type IntoIter = Iter<'a, A::Item>
Which kind of iterator are we turning this into?
type Item = &'a A::Item
The type of the elements being iterated over.
pub fn into_iter(self) -> Self::IntoIter
[src]
impl<A> Ord for SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
pub fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<A> PartialEq<SmallOrdSet<A>> for SmallOrdSet<A> where
A: Array,
A::Item: PartialEq,
[src]
A: Array,
A::Item: PartialEq,
pub fn eq(&self, other: &Self) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A> PartialOrd<SmallOrdSet<A>> for SmallOrdSet<A> where
A: Array,
A::Item: Ord,
[src]
A: Array,
A::Item: Ord,
Auto Trait Implementations
impl<A> RefUnwindSafe for SmallOrdSet<A> where
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
[src]
A: RefUnwindSafe,
<A as Array>::Item: RefUnwindSafe,
impl<A> Send for SmallOrdSet<A> where
<A as Array>::Item: Send,
[src]
<A as Array>::Item: Send,
impl<A> Sync for SmallOrdSet<A> where
A: Sync,
[src]
A: Sync,
impl<A> Unpin for SmallOrdSet<A> where
A: Unpin,
[src]
A: Unpin,
impl<A> UnwindSafe for SmallOrdSet<A> where
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe,
[src]
A: UnwindSafe,
<A as Array>::Item: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,