Struct splay_tree::set::VecLikeMut
[−]
[src]
pub struct VecLikeMut<'a, T: 'a> { /* fields omitted */ }
A vector like mutable view of a set.
Methods
impl<'a, T: 'a> VecLikeMut<'a, T> where
T: Ord,
[src]
T: Ord,
fn push(&mut self, value: T) -> bool
[src]
Appends a new element to the back of the vector like set.
If the set did not have this value present, true
is returnd.
If the set did have this value present, false
is returnd,
and the entry is not appended.
This is a synonym of the SplaySet::insert
function.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); let mut vec = set.as_vec_like_mut(); assert_eq!(vec.push("foo"), true); assert_eq!(vec.len(), 1); assert_eq!(vec.push("foo"), false); assert_eq!(vec.len(), 1); assert_eq!(vec.push("bar"), true); assert_eq!(vec.len(), 2); assert_eq!(vec.find_index("foo"), Some(0)); assert_eq!(vec.get(0), Some(&"foo"));
fn pop(&mut self) -> Option<T>
[src]
Removes the last element from the vector like set and returns it, or None
if it is empty.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); set.insert("foo"); set.insert("bar"); { let mut vec = set.as_vec_like_mut(); assert_eq!(vec.pop(), Some("bar")); assert_eq!(vec.pop(), Some("foo")); assert_eq!(vec.pop(), None); } assert!(set.is_empty());
fn find_index<Q: ?Sized>(&mut self, value: &Q) -> Option<usize> where
T: Borrow<Q>,
Q: Ord,
[src]
T: Borrow<Q>,
Q: Ord,
Returns the index of the element that is equal to the given value,
or None
if the collection does not have no such element.
Because underlying 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"); set.insert("bar"); set.insert("baz"); let mut vec = set.as_vec_like_mut(); assert_eq!(vec.find_index("foo"), Some(0)); assert_eq!(vec.find_index("baz"), Some(2)); assert_eq!(vec.find_index("qux"), None);
impl<'a, T: 'a> VecLikeMut<'a, T>
[src]
fn get(&self, index: usize) -> Option<&T>
[src]
Returns the element of the vector at the given index,
or None
if the index is out of bounds.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); set.insert("foo"); set.insert("bar"); set.insert("baz"); let vec = set.as_vec_like_mut(); assert_eq!(vec.get(0), Some(&"foo")); assert_eq!(vec.get(1), Some(&"bar")); assert_eq!(vec.get(2), Some(&"baz")); assert_eq!(vec.get(3), None);
fn first(&self) -> Option<&T>
[src]
Returns the first element of the vector, or None
if it is empty.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); set.insert("foo"); set.insert("bar"); set.insert("baz"); let vec = set.as_vec_like_mut(); assert_eq!(vec.first(), Some(&"foo"));
fn last(&self) -> Option<&T>
[src]
Returns the last element of the vector, or None
if it is empty.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); set.insert("foo"); set.insert("bar"); set.insert("baz"); let vec = set.as_vec_like_mut(); assert_eq!(vec.last(), Some(&"baz"));
fn iter(&self) -> VecLikeIter<T>
[src]
Gets an iterator over the vector's elements, in positional order (low to high).
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); set.insert("foo"); set.insert("bar"); set.insert("baz"); assert_eq!(set.iter().cloned().collect::<Vec<_>>(), ["bar", "baz", "foo"]); let vec = set.as_vec_like_mut(); assert_eq!(vec.iter().cloned().collect::<Vec<_>>(), ["foo", "bar", "baz"]);
fn len(&self) -> usize
[src]
Returns the number of elements in the vector like set.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); set.insert("foo"); { let mut vec = set.as_vec_like_mut(); vec.push("bar"); assert_eq!(vec.len(), 2); } assert_eq!(set.len(), 2);
fn is_empty(&self) -> bool
[src]
Returns true
if the vector like set contains no elements.
Examples
use splay_tree::SplaySet; let mut set = SplaySet::new(); let mut vec = set.as_vec_like_mut(); assert!(vec.is_empty()); vec.push(0); assert!(!vec.is_empty());