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

Construct a new, empty AA-Tree based set.

Returns the number of elements in the set.

Returns true if the set contains no elements.

Clears the set, removing all elements.

Example
let mut set = AATreeSet::new();
set.insert(1);
set.clear();
assert!(set.is_empty());

Creates an iterator over this set that visits the values in ascending order.

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);

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));

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));

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));

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);

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);

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);

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));

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));

Removes a value from the set, and returns true if it was removed.

Removes a value from the set, and returns the value that was removed.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.