treemap: inline the TreeSet wrappers
This commit is contained in:
parent
a5c88366f8
commit
ad16fecc33
@ -77,21 +77,13 @@ pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
|
||||
|
||||
impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> {
|
||||
#[inline(always)]
|
||||
pure fn lt(&self, other: &TreeMap<K, V>) -> bool {
|
||||
lt(self, other)
|
||||
}
|
||||
pure fn lt(&self, other: &TreeMap<K, V>) -> bool { lt(self, other) }
|
||||
#[inline(always)]
|
||||
pure fn le(&self, other: &TreeMap<K, V>) -> bool {
|
||||
!lt(other, self)
|
||||
}
|
||||
pure fn le(&self, other: &TreeMap<K, V>) -> bool { !lt(other, self) }
|
||||
#[inline(always)]
|
||||
pure fn ge(&self, other: &TreeMap<K, V>) -> bool {
|
||||
!lt(self, other)
|
||||
}
|
||||
pure fn ge(&self, other: &TreeMap<K, V>) -> bool { !lt(self, other) }
|
||||
#[inline(always)]
|
||||
pure fn gt(&self, other: &TreeMap<K, V>) -> bool {
|
||||
lt(other, self)
|
||||
}
|
||||
pure fn gt(&self, other: &TreeMap<K, V>) -> bool { lt(other, self) }
|
||||
}
|
||||
|
||||
impl<'self, K: TotalOrd, V> BaseIter<(&'self K, &'self V)> for TreeMap<K, V> {
|
||||
@ -244,19 +236,24 @@ pub struct TreeSet<T> {
|
||||
|
||||
impl<T: TotalOrd> BaseIter<T> for TreeSet<T> {
|
||||
/// Visit all values in order
|
||||
#[inline(always)]
|
||||
pure fn each(&self, f: &fn(&T) -> bool) { self.map.each_key(f) }
|
||||
#[inline(always)]
|
||||
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) }
|
||||
}
|
||||
|
||||
impl<T: TotalOrd> ReverseIter<T> for TreeSet<T> {
|
||||
/// Visit all values in reverse order
|
||||
#[inline(always)]
|
||||
pure fn each_reverse(&self, f: &fn(&T) -> bool) {
|
||||
self.map.each_key_reverse(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Eq + TotalOrd> Eq for TreeSet<T> {
|
||||
#[inline(always)]
|
||||
pure fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
|
||||
#[inline(always)]
|
||||
pure fn ne(&self, other: &TreeSet<T>) -> bool { self.map != other.map }
|
||||
}
|
||||
|
||||
@ -273,29 +270,35 @@ impl<T: Ord + TotalOrd> Ord for TreeSet<T> {
|
||||
|
||||
impl<T: TotalOrd> Container for TreeSet<T> {
|
||||
/// Return the number of elements in the set
|
||||
#[inline(always)]
|
||||
pure fn len(&self) -> uint { self.map.len() }
|
||||
|
||||
/// Return true if the set contains no elements
|
||||
#[inline(always)]
|
||||
pure fn is_empty(&self) -> bool { self.map.is_empty() }
|
||||
}
|
||||
|
||||
impl<T: TotalOrd> Mutable for TreeSet<T> {
|
||||
/// Clear the set, removing all values.
|
||||
#[inline(always)]
|
||||
fn clear(&mut self) { self.map.clear() }
|
||||
}
|
||||
|
||||
impl<T: TotalOrd> Set<T> for TreeSet<T> {
|
||||
/// Return true if the set contains a value
|
||||
#[inline(always)]
|
||||
pure fn contains(&self, value: &T) -> bool {
|
||||
self.map.contains_key(value)
|
||||
}
|
||||
|
||||
/// Add a value to the set. Return true if the value was not already
|
||||
/// present in the set.
|
||||
#[inline(always)]
|
||||
fn insert(&mut self, value: T) -> bool { self.map.insert(value, ()) }
|
||||
|
||||
/// Remove a value from the set. Return true if the value was
|
||||
/// present in the set.
|
||||
#[inline(always)]
|
||||
fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
|
||||
|
||||
/// Return true if the set has no elements in common with `other`.
|
||||
@ -320,6 +323,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
|
||||
}
|
||||
|
||||
/// Return true if the set is a subset of another
|
||||
#[inline(always)]
|
||||
pure fn is_subset(&self, other: &TreeSet<T>) -> bool {
|
||||
other.is_superset(self)
|
||||
}
|
||||
@ -488,10 +492,12 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
|
||||
|
||||
pub impl <T: TotalOrd> TreeSet<T> {
|
||||
/// Create an empty TreeSet
|
||||
#[inline(always)]
|
||||
static pure fn new() -> TreeSet<T> { TreeSet{map: TreeMap::new()} }
|
||||
|
||||
/// Get a lazy iterator over the values in the set.
|
||||
/// Requires that it be frozen (immutable).
|
||||
#[inline(always)]
|
||||
pure fn iter(&self) -> TreeSetIterator/&self<T> {
|
||||
TreeSetIterator{iter: self.map.iter()}
|
||||
}
|
||||
@ -504,11 +510,13 @@ pub struct TreeSetIterator<T> {
|
||||
|
||||
/// Advance the iterator to the next node (in order). If this iterator is
|
||||
/// finished, does nothing.
|
||||
#[inline(always)]
|
||||
pub fn set_next<T>(iter: &mut TreeSetIterator/&r<T>) -> Option<&r/T> {
|
||||
do map_next(&mut iter.iter).map |&(value, _)| { value }
|
||||
}
|
||||
|
||||
/// Advance the iterator through the set
|
||||
#[inline(always)]
|
||||
pub fn set_advance<T>(iter: &mut TreeSetIterator/&r<T>,
|
||||
f: &fn(&r/T) -> bool) {
|
||||
do map_advance(&mut iter.iter) |(k, _)| { f(k) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user