Struct splay_tree::SplaySet [] [src]

pub struct SplaySet<T> { /* fields omitted */ }

A set based on splay tree.

A splay tree based set is a self-adjusting data structure. It performs insertion, removal and look-up in O(log n) amortized time.

It is a logic error for a key to be modified in such a way that the key's ordering relative to any other key, as determined by the Ord trait, changes while it is in the map. This is normally only possible through Cell, RefCell, global state, I/O, or unsafe code.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();

set.insert("foo");
set.insert("bar");
set.insert("baz");
assert_eq!(set.len(), 3);

assert!(set.contains("bar"));
assert!(set.remove("bar"));
assert!(!set.contains("bar"));

assert_eq!(vec!["baz", "foo"], set.into_iter().collect::<Vec<_>>());

Methods

impl<T> SplaySet<T> where
    T: Ord
[src]

[src]

Makes a new SplaySet

Examples

use splay_tree::SplaySet;

let set: SplaySet<()> = SplaySet::new();
assert!(set.is_empty());

[src]

Clears the set, removing all values.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
set.clear();
assert!(set.is_empty());

[src]

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.

Because SplaySet is a self-adjusting amortized data structure, this function requires the mut qualifier for self.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
assert!(set.contains("foo"));
assert!(!set.contains("bar"));

[src]

Returns a reference to the value in the set, if any, 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.

Because SplaySet is a self-adjusting amortized data structure, this function requires the mut qualifier for self.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
assert_eq!(set.get("foo"), Some(&"foo"));
assert_eq!(set.get("bar"), None);

[src]

Finds a minimum element which satisfies "greater than or equal to value" condition 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.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert(1);
set.insert(3);

assert_eq!(set.find_lower_bound(&0), Some(&1));
assert_eq!(set.find_lower_bound(&1), Some(&1));
assert_eq!(set.find_lower_bound(&4), None);

[src]

Finds a minimum element which satisfies "greater than value" condition 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.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert(1);
set.insert(3);

assert_eq!(set.find_upper_bound(&0), Some(&1));
assert_eq!(set.find_upper_bound(&1), Some(&3));
assert_eq!(set.find_upper_bound(&4), None);

[src]

Gets the minimum value in the map.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert(1);
set.insert(3);

assert_eq!(set.smallest(), Some(&1));

[src]

Takes the minimum value in the map.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert(1);
set.insert(3);

assert_eq!(set.take_smallest(), Some(1));
assert_eq!(set.take_smallest(), Some(3));
assert_eq!(set.take_smallest(), None);

[src]

Gets the maximum value in the map.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert(1);
set.insert(3);

assert_eq!(set.largest(), Some(&3));

[src]

Takes the maximum value in the map.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert(1);
set.insert(3);

assert_eq!(set.take_largest(), Some(3));
assert_eq!(set.take_largest(), Some(1));
assert_eq!(set.take_largest(), None);

[src]

Adds a value to the set.

If the set did not have this value present, true is returned.

If the set did have this value present, false is returned, and the entry is not updated.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
assert!(set.insert("foo"));
assert!(!set.insert("foo"));
assert_eq!(set.len(), 1);

[src]

Adds a value to the set, replacing the existing value, if any, that is equal to the given one. Returns the replaced value.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
assert_eq!(set.replace("foo"), None);
assert_eq!(set.replace("foo"), Some("foo"));

[src]

Removes a value from the set. Returns true is the value was present 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.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
assert_eq!(set.remove("foo"), true);
assert_eq!(set.remove("foo"), false);

[src]

Removes and returns the value in the set, if any, that is equal to the given one.

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.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
assert_eq!(set.take("foo"), Some("foo"));
assert_eq!(set.take("foo"), None);

[src]

Visits the values representing the difference, in ascending order.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();

assert_eq!(a.difference(&b).cloned().collect::<Vec<_>>(),
           [1]);

[src]

Visits the values representing the symmetric difference, in ascending order.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();

assert_eq!(a.symmetric_difference(&b).cloned().collect::<Vec<_>>(),
           [1, 4]);

[src]

Visits the values representing the intersection, in ascending order.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();

assert_eq!(a.intersection(&b).cloned().collect::<Vec<_>>(),
           [2, 3]);

[src]

Visits the values representing the union, in ascending order.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();

assert_eq!(a.union(&b).cloned().collect::<Vec<_>>(),
           [1, 2, 3, 4]);

[src]

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

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();
let c: SplaySet<_> = vec![4, 5, 6].into_iter().collect();

assert!(!a.is_disjoint(&b));
assert!(!b.is_disjoint(&c));
assert!(a.is_disjoint(&c));
assert!(c.is_disjoint(&a));

[src]

Returns true if the set is a subset of another.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();
let c: SplaySet<_> = vec![1, 2, 3, 4].into_iter().collect();

assert!(!a.is_subset(&b));
assert!(!b.is_subset(&a));
assert!(!c.is_subset(&a));
assert!(a.is_subset(&c));
assert!(b.is_subset(&c));
assert!(c.is_subset(&c));

[src]

Returns true if the set is a superset of another.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![2, 3, 4].into_iter().collect();
let c: SplaySet<_> = vec![1, 2, 3, 4].into_iter().collect();

assert!(!a.is_superset(&b));
assert!(!b.is_superset(&a));
assert!(!a.is_superset(&c));
assert!(c.is_superset(&a));
assert!(c.is_superset(&b));
assert!(c.is_superset(&c));

[src]

Returns a vector like mutable view of the set.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
set.insert("bar");
{
    let mut vec = set.as_vec_like_mut();
    vec.push("baz");

    assert_eq!(vec.get(0), Some(&"foo"));
    assert_eq!(vec.get(2), Some(&"baz"));

    assert_eq!(vec.find_index(&"bar"), Some(1));

    assert_eq!(vec.iter().cloned().collect::<Vec<_>>(),
               ["foo", "bar", "baz"]);
}
assert_eq!(set.iter().cloned().collect::<Vec<_>>(),
           ["bar", "baz", "foo"]);

impl<T> SplaySet<T>
[src]

[src]

Returns the number of elements in the set.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
set.insert("bar");
assert_eq!(set.len(), 2);

[src]

Returns true if the set contains no elements.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
assert!(set.is_empty());

set.insert("foo");
assert!(!set.is_empty());

set.clear();
assert!(set.is_empty());

[src]

Gets an iterator over the SplaySet's contents, in sorted order.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
set.insert("bar");
set.insert("baz");

assert_eq!(set.iter().collect::<Vec<_>>(), [&"bar", &"baz", &"foo"]);

[src]

Returns a vector like view of the set.

Examples

use splay_tree::SplaySet;

let mut set = SplaySet::new();
set.insert("foo");
set.insert("bar");
{
    let mut vec = set.as_vec_like();
    assert_eq!(vec.get(0), Some(&"foo"));
    assert_eq!(vec.get(1), Some(&"bar"));

    assert_eq!(vec.iter().cloned().collect::<Vec<_>>(),
               ["foo", "bar"]);
}
assert_eq!(set.iter().cloned().collect::<Vec<_>>(),
           ["bar", "foo"]);

Trait Implementations

impl<T: Debug> Debug for SplaySet<T>
[src]

[src]

Formats the value using the given formatter.

impl<T: Clone> Clone for SplaySet<T>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<T: Hash> Hash for SplaySet<T>
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: PartialEq> PartialEq for SplaySet<T>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<T: Eq> Eq for SplaySet<T>
[src]

impl<T: PartialOrd> PartialOrd for SplaySet<T>
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

[src]

This method tests less than (for self and other) and is used by the < operator. Read more

[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T: Ord> Ord for SplaySet<T>
[src]

[src]

This method returns an Ordering between self and other. Read more

[src]

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the maximum of two values. Read more

[src]

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the minimum of two values. Read more

impl<T> Default for SplaySet<T> where
    T: Ord
[src]

[src]

Returns the "default value" for a type. Read more

impl<T> FromIterator<T> for SplaySet<T> where
    T: Ord
[src]

[src]

Creates a value from an iterator. Read more

impl<T> IntoIterator for SplaySet<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<'a, T> IntoIterator for &'a SplaySet<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<T> Extend<T> for SplaySet<T> where
    T: Ord
[src]

[src]

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

impl<'a, T> Extend<&'a T> for SplaySet<T> where
    T: Copy + 'a + Ord
[src]

[src]

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

impl<'a, 'b, T> Sub<&'b SplaySet<T>> for &'a SplaySet<T> where
    T: Ord + Clone
[src]

The resulting type after applying the - operator.

[src]

Returns the difference of self and rhs as a new SplaySet<T>.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![3, 4, 5].into_iter().collect();

assert_eq!((&a - &b).into_iter().collect::<Vec<_>>(),
           [1, 2]);

impl<'a, 'b, T> BitXor<&'b SplaySet<T>> for &'a SplaySet<T> where
    T: Ord + Clone
[src]

The resulting type after applying the ^ operator.

[src]

Returns the symmetric difference of self and rhs as a new SplaySet<T>.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![3, 4, 5].into_iter().collect();

assert_eq!((&a ^ &b).into_iter().collect::<Vec<_>>(),
           [1, 2, 4, 5]);

impl<'a, 'b, T> BitAnd<&'b SplaySet<T>> for &'a SplaySet<T> where
    T: Ord + Clone
[src]

The resulting type after applying the & operator.

[src]

Returns the intersection of self and rhs as a new SplaySet<T>.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![3, 4, 5].into_iter().collect();

assert_eq!((&a & &b).into_iter().collect::<Vec<_>>(),
           [3]);

impl<'a, 'b, T> BitOr<&'b SplaySet<T>> for &'a SplaySet<T> where
    T: Ord + Clone
[src]

The resulting type after applying the | operator.

[src]

Returns the union of self and rhs as a new SplaySet<T>.

Examples

use splay_tree::SplaySet;

let a: SplaySet<_> = vec![1, 2, 3].into_iter().collect();
let b: SplaySet<_> = vec![3, 4, 5].into_iter().collect();

assert_eq!((&a | &b).into_iter().collect::<Vec<_>>(),
           [1, 2, 3, 4, 5]);