pub struct AATreeSet<T> { /* private fields */ }
Expand description
A set based on an AA-Tree.
See AATreeMap
’s documentation for a detailed discussion of this collection’s performance benefits and drawbacks.
It is a logic error for an item to be modified in such a way that the item’s ordering relative to any
other item, as determined by the Ord
trait, changes while it is in the set. This is normally only possible
through Cell
, RefCell
, global state, I/O, or unsafe code.
Example
This example is adopted from BTreeSet
’s documentation:
use aatree::AATreeSet;
let mut books = AATreeSet::new();
// Add some books.
books.insert("A Dance With Dragons");
books.insert("To Kill a Mockingbird");
books.insert("The Odyssey");
books.insert("The Great Gatsby");
// Check for a specific one
if !books.contains("The Winds of Winter") {
println!("We have {} books, but The Winds of Winter ain't one.", books.len());
}
// Remove a book.
books.remove("The Odyssey");
// Iterate over everything.
for book in &books {
println!("{}", book);
}
Implementations§
source§impl<T> AATreeSet<T>
impl<T> AATreeSet<T>
source§impl<T: Ord> AATreeSet<T>
impl<T: Ord> AATreeSet<T>
sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Adds a value to the set.
If the set did already contain this value, the entry is not updated, and
false
is returned.
Example
let mut set = AATreeSet::new();
set.insert(42);
set.insert(42);
assert_eq!(set.len(), 1);
sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
Moves all elements from other
into self
, leaving other
empty.
Examples
use aatree::AATreeSet;
let mut a = AATreeSet::new();
a.insert(1);
a.insert(2);
a.insert(3);
let mut b = AATreeSet::new();
b.insert(3);
b.insert(4);
b.insert(5);
a.append(&mut b);
assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);
assert!(a.contains(&1));
assert!(a.contains(&2));
assert!(a.contains(&3));
assert!(a.contains(&4));
assert!(a.contains(&5));
sourcepub fn first(&self) -> Option<&T>
pub fn first(&self) -> Option<&T>
Returns the first/smallest element of the set.
Example
let mut set = AATreeSet::new();
assert!(set.first().is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.first(), Some(&40));
sourcepub fn last(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
Returns the last/largest element of the set.
Example
let mut set = AATreeSet::new();
assert!(set.last().is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.last(), Some(&44));
sourcepub fn pop_first(&mut self) -> Option<T>
pub fn pop_first(&mut self) -> Option<T>
Remove and return the first/smallest element of the set.
Example
let mut set = AATreeSet::new();
assert_eq!(set.pop_first(), None);
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.pop_first(), Some(40));
assert_eq!(set.pop_first(), Some(42));
assert_eq!(set.pop_first(), Some(44));
assert_eq!(set.pop_first(), None);
sourcepub fn pop_last(&mut self) -> Option<T>
pub fn pop_last(&mut self) -> Option<T>
Remove and return the last/largest element of the set.
Example
let mut set = AATreeSet::new();
assert_eq!(set.pop_last(), None);
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.pop_last(), Some(44));
assert_eq!(set.pop_last(), Some(42));
assert_eq!(set.pop_last(), Some(40));
assert_eq!(set.pop_last(), None);
sourcepub fn contains<Q>(&self, value: &Q) -> boolwhere
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn contains<Q>(&self, value: &Q) -> boolwhere
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns true
if the set contains an element with the given value.
Example
let mut set = AATreeSet::new();
set.insert(43);
assert_eq!(set.contains(&42), false);
set.insert(42);
assert_eq!(set.contains(&42), true);
sourcepub fn first_at_or_after<Q>(&self, value: &Q) -> Option<&T>where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn first_at_or_after<Q>(&self, value: &Q) -> Option<&T>where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns the first/smallest element of the set that is greater or equal to x
.
Example
let mut set = AATreeSet::new();
assert!(set.first_at_or_after(&41).is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.first_at_or_after(&41), Some(&42));
sourcepub fn last_at_or_before<Q>(&self, value: &Q) -> Option<&T>where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn last_at_or_before<Q>(&self, value: &Q) -> Option<&T>where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns the last/largest element of the set that is smaller or equal to x
.
Example
let mut set = AATreeSet::new();
assert!(set.last_at_or_before(&43).is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.last_at_or_before(&43), Some(&42));
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for AATreeSet<T>where
T: Deserialize<'de> + Ord,
impl<'de, T> Deserialize<'de> for AATreeSet<T>where
T: Deserialize<'de> + Ord,
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<'a, T: Ord + Copy + 'a> Extend<&'a T> for AATreeSet<T>
impl<'a, T: Ord + Copy + 'a> Extend<&'a T> for AATreeSet<T>
source§fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T: Ord> Extend<T> for AATreeSet<T>
impl<T: Ord> Extend<T> for AATreeSet<T>
source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl<T: Ord> FromIterator<T> for AATreeSet<T>
impl<T: Ord> FromIterator<T> for AATreeSet<T>
source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
source§impl<'a, T> IntoIterator for &'a AATreeSet<T>
impl<'a, T> IntoIterator for &'a AATreeSet<T>
source§impl<T> IntoIterator for AATreeSet<T>
impl<T> IntoIterator for AATreeSet<T>
source§impl<T> OpenapiType for AATreeSet<T>where
T: OpenapiType,
impl<T> OpenapiType for AATreeSet<T>where
T: OpenapiType,
fn visit_type<V: Visitor>(visitor: &mut V)
fn schema() -> OpenapiSchema
source§impl<T: Ord> Ord for AATreeSet<T>
impl<T: Ord> Ord for AATreeSet<T>
source§impl<T: PartialEq> PartialEq<AATreeSet<T>> for AATreeSet<T>
impl<T: PartialEq> PartialEq<AATreeSet<T>> for AATreeSet<T>
source§impl<T: PartialOrd> PartialOrd<AATreeSet<T>> for AATreeSet<T>
impl<T: PartialOrd> PartialOrd<AATreeSet<T>> for AATreeSet<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<T: Eq> Eq for AATreeSet<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for AATreeSet<T>where
T: RefUnwindSafe,
impl<T> Send for AATreeSet<T>where
T: Send,
impl<T> Sync for AATreeSet<T>where
T: Sync,
impl<T> Unpin for AATreeSet<T>
impl<T> UnwindSafe for AATreeSet<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.