[][src]Struct small_ord_set::SmallOrdSet

pub struct SmallOrdSet<A: Array> { /* fields omitted */ }

A set represented by a sorted SmallVec.

Implementations

impl<A, K, V> SmallOrdSet<A> where
    A: Array<Item = KeyValuePair<K, V>>,
    K: Ord
[src]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

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]

impl<A> Debug for SmallOrdSet<A> where
    A: Array,
    A::Item: Debug
[src]

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.

impl<A> Eq for SmallOrdSet<A> where
    A: Array,
    A::Item: Eq
[src]

impl<A> Extend<<A as Array>::Item> for SmallOrdSet<A> where
    A: Array,
    A::Item: Ord
[src]

impl<A> From<A> for SmallOrdSet<A> where
    A: Array,
    A::Item: Ord
[src]

impl<A> From<SmallVec<A>> for SmallOrdSet<A> where
    A: Array,
    A::Item: Ord
[src]

impl<A> FromIterator<<A as Array>::Item> for SmallOrdSet<A> where
    A: Array,
    A::Item: Ord
[src]

impl<A> Hash for SmallOrdSet<A> where
    A: Array,
    A::Item: Hash
[src]

impl<A: Array, I: SliceIndex<[A::Item]>> Index<I> for SmallOrdSet<A>[src]

type Output = I::Output

The returned type after indexing.

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.

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.

impl<A> Ord for SmallOrdSet<A> where
    A: Array,
    A::Item: Ord
[src]

impl<A> PartialEq<SmallOrdSet<A>> for SmallOrdSet<A> where
    A: Array,
    A::Item: PartialEq
[src]

impl<A> PartialOrd<SmallOrdSet<A>> for SmallOrdSet<A> where
    A: Array,
    A::Item: Ord
[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for SmallOrdSet<A> where
    A: RefUnwindSafe,
    <A as Array>::Item: RefUnwindSafe
[src]

impl<A> Send for SmallOrdSet<A> where
    <A as Array>::Item: Send
[src]

impl<A> Sync for SmallOrdSet<A> where
    A: Sync
[src]

impl<A> Unpin for SmallOrdSet<A> where
    A: Unpin
[src]

impl<A> UnwindSafe for SmallOrdSet<A> where
    A: UnwindSafe,
    <A as Array>::Item: RefUnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.