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
sourceimpl<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 smallest(&self) -> Option<&T>
pub fn smallest(&self) -> Option<&T>
Returns the smallest element of the set.
Example
let mut set = AATreeSet::new();
assert!(set.smallest().is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.smallest(), Some(&40));
sourcepub fn largest(&self) -> Option<&T>
pub fn largest(&self) -> Option<&T>
Returns the largest element of the set.
Example
let mut set = AATreeSet::new();
assert!(set.largest().is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.largest(), Some(&44));
sourcepub fn pop_smallest(&mut self) -> Option<T>
pub fn pop_smallest(&mut self) -> Option<T>
Remove and return the smallest element of the set.
Example
let mut set = AATreeSet::new();
assert_eq!(set.pop_smallest(), None);
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.pop_smallest(), Some(40));
assert_eq!(set.pop_smallest(), Some(42));
assert_eq!(set.pop_smallest(), Some(44));
assert_eq!(set.pop_smallest(), None);
sourcepub fn pop_largest(&mut self) -> Option<T>
pub fn pop_largest(&mut self) -> Option<T>
Remove and return the largest element of the set.
Example
let mut set = AATreeSet::new();
assert_eq!(set.pop_largest(), None);
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.pop_largest(), Some(44));
assert_eq!(set.pop_largest(), Some(42));
assert_eq!(set.pop_largest(), Some(40));
assert_eq!(set.pop_largest(), None);
sourcepub fn contains<Q>(&self, x: &Q) -> bool where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn contains<Q>(&self, x: &Q) -> bool where
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 smallest_geq_than<Q>(&self, x: &Q) -> Option<&T> where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn smallest_geq_than<Q>(&self, x: &Q) -> Option<&T> where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns the smallest element of the set that is greater or equal to x
.
Example
let mut set = AATreeSet::new();
assert!(set.smallest_geq_than(&41).is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.smallest_geq_than(&41), Some(&42));
sourcepub fn largest_leq_than<Q>(&self, x: &Q) -> Option<&T> where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
pub fn largest_leq_than<Q>(&self, x: &Q) -> Option<&T> where
T: Borrow<Q> + Ord,
Q: Ord + ?Sized,
Returns the largest element of the set that is smaller or equal to x
.
Example
let mut set = AATreeSet::new();
assert!(set.largest_leq_than(&43).is_none());
set.insert(42);
set.insert(44);
set.insert(40);
assert_eq!(set.largest_leq_than(&43), Some(&42));
Trait Implementations
sourceimpl<T: Ord> FromIterator<T> for AATreeSet<T>
impl<T: Ord> FromIterator<T> for AATreeSet<T>
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
sourceimpl<T> IntoIterator for AATreeSet<T>
impl<T> IntoIterator 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> IterContent<T> for T
impl<T> IterContent<T> for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more