Struct avl::AvlTreeSet

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

An ordered set implemented with an AVL tree.

use avl::AvlTreeSet;
let mut set = AvlTreeSet::new();
set.insert(0);
set.insert(1);
set.insert(2);
assert!(set.contains(&1));
set.remove(&1);
assert!(!set.contains(&1));

Implementations§

source§

impl<T: Ord> AvlTreeSet<T>

source

pub fn new() -> Self

Creates an empty set. No memory is allocated until the first item is inserted.

source§

impl<T> AvlTreeSet<T>

source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

source

pub fn len(&self) -> usize

Returns the number of elements in the set.

source

pub fn clear(&mut self)

Clears the set, deallocating all memory.

source

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

Gets an iterator over the values of the map in sorted order.

source

pub fn get<Q>(&self, value: &Q) -> Option<&T>where T: Borrow<Q>, Q: Ord + ?Sized,

Returns a reference to the value in the set that is equal to the given value.

The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.

source

pub fn contains<Q>(&self, value: &Q) -> boolwhere T: Borrow<Q>, Q: Ord + ?Sized,

Returns true if the set contains a value.

The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.

source

pub fn remove<Q>(&mut self, value: &Q) -> boolwhere T: Borrow<Q>, Q: Ord + ?Sized,

Removes a value from the set. Returns whether the value was previously in the set.

The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.

source

pub fn take<Q>(&mut self, value: &Q) -> Option<T>where T: Borrow<Q>, Q: Ord + ?Sized,

Removes a value from the set. Returns the value if it was previously in the set.

The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.

source

pub fn range<Q, R>(&self, range: R) -> Range<'_, T> where T: Borrow<Q>, R: RangeBounds<Q>, Q: Ord + ?Sized,

Gets an iterator over a sub-range of values in the set in sorted order.

The value may be any borrowed form of the set’s value type, but the ordering on the borrowed form must match the ordering on the value type.

Panics

Panics if range start > end. Panics if range start == end and both bounds are Excluded.

source§

impl<T: Ord> AvlTreeSet<T>

source

pub fn insert(&mut self, value: T) -> bool

Inserts a value into the set.

source

pub fn append(&mut self, other: &mut Self)

Moves all values from other into self, leaving other empty.

source

pub fn split_off<Q>(&mut self, key: &Q) -> Selfwhere T: Borrow<Q>, Q: ?Sized + Ord,

Splits the collection into two at the given key. Returns everything after the given key, including the key.

source

pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T>

Gets an iterator over the values of the union set, i.e., all values in self or other, without duplicates, in ascending order.

source

pub fn intersection<'a>(&'a self, other: &'a Self) -> Intersection<'a, T>

Gets an iterator over the values of the intersection set, i.e., all values that are botih in self and other, in ascending order.

source

pub fn difference<'a>(&'a self, other: &'a Self) -> Difference<'a, T>

Gets an iterator over the values of the difference between two sets, i.e., all values that are in self but not in other, in ascending order.

source

pub fn symmetric_difference<'a>( &'a self, other: &'a Self ) -> SymmetricDifference<'a, T>

Gets an iterator over the values of the symmectric difference of two sets, i.e., all values in self or other, but not in both, in ascending order.

source

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

Returns true if self has no elements in common with other. This is equivalent to checking for an empty intersection.

source

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

Returns true if the set is a subset of another, i.e., other contains at least all the values in self.

source

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

Returns true if the set is a superset of another, i.e., self contains at least all the values in other.

Trait Implementations§

source§

impl<T: Ord + Clone> BitAnd<&AvlTreeSet<T>> for &AvlTreeSet<T>

source§

fn bitand(self, rhs: &AvlTreeSet<T>) -> AvlTreeSet<T>

Returns the intersection of self and rhs as a new set.

§

type Output = AvlTreeSet<T>

The resulting type after applying the & operator.
source§

impl<T: Ord + Clone> BitOr<&AvlTreeSet<T>> for &AvlTreeSet<T>

source§

fn bitor(self, rhs: &AvlTreeSet<T>) -> AvlTreeSet<T>

Returns the union of self and rhs as a new set.

§

type Output = AvlTreeSet<T>

The resulting type after applying the | operator.
source§

impl<T: Ord + Clone> BitXor<&AvlTreeSet<T>> for &AvlTreeSet<T>

source§

fn bitxor(self, rhs: &AvlTreeSet<T>) -> AvlTreeSet<T>

Returns the symmetric difference of self and rhs as a new set.

§

type Output = AvlTreeSet<T>

The resulting type after applying the ^ operator.
source§

impl<T: Clone> Clone for AvlTreeSet<T>

source§

fn clone(&self) -> AvlTreeSet<T>

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 AvlTreeSet<T>

source§

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

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

impl<T: Ord> Default for AvlTreeSet<T>

source§

fn default() -> Self

Creates an empty set.

source§

impl<'a, T> Extend<&'a T> for AvlTreeSet<T>where T: Ord + Copy + 'a,

source§

fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = &'a T>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T: Ord> Extend<T> for AvlTreeSet<T>

source§

fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = T>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T: Ord> FromIterator<T> for AvlTreeSet<T>

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<T: Hash> Hash for AvlTreeSet<T>

source§

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

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

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

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

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for AvlTreeSet<T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: Ord> Ord for AvlTreeSet<T>

source§

fn cmp(&self, other: &AvlTreeSet<T>) -> Ordering

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

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq> PartialEq<AvlTreeSet<T>> for AvlTreeSet<T>

source§

fn eq(&self, other: &AvlTreeSet<T>) -> 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<AvlTreeSet<T>> for AvlTreeSet<T>

source§

fn partial_cmp(&self, other: &AvlTreeSet<T>) -> 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: Ord + Clone> Sub<&AvlTreeSet<T>> for &AvlTreeSet<T>

source§

fn sub(self, rhs: &AvlTreeSet<T>) -> AvlTreeSet<T>

Returns the difference of self and rhs as a new set.

§

type Output = AvlTreeSet<T>

The resulting type after applying the - operator.
source§

impl<T: Eq> Eq for AvlTreeSet<T>

source§

impl<T> StructuralEq for AvlTreeSet<T>

source§

impl<T> StructuralPartialEq for AvlTreeSet<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> Unpin for AvlTreeSet<T>

§

impl<T> UnwindSafe for AvlTreeSet<T>where T: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.