1
Fork 0

Implement Ord for TrieMap/TrieSet/SmallIntMap/Bitv/BitvSet

This commit is contained in:
nham 2014-07-28 02:53:44 -04:00
parent 935c88ce1c
commit 8ebd58cedf
3 changed files with 23 additions and 2 deletions

View file

@ -838,6 +838,13 @@ impl PartialOrd for Bitv {
}
}
impl Ord for Bitv {
#[inline]
fn cmp(&self, other: &Bitv) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}
impl fmt::Show for Bitv {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
for bit in self.iter() {
@ -963,7 +970,7 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
/// assert!(bv.eq_vec([true, true, false, true,
/// false, false, false, false]));
/// ```
#[deriving(Clone, PartialEq, Eq, PartialOrd)]
#[deriving(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BitvSet(Bitv);
impl Default for BitvSet {

View file

@ -380,6 +380,13 @@ impl<V: PartialOrd> PartialOrd for SmallIntMap<V> {
}
}
impl<V: Ord> Ord for SmallIntMap<V> {
#[inline]
fn cmp(&self, other: &SmallIntMap<V>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}
impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));

View file

@ -100,6 +100,13 @@ impl<T: PartialOrd> PartialOrd for TrieMap<T> {
}
}
impl<T: Ord> Ord for TrieMap<T> {
#[inline]
fn cmp(&self, other: &TrieMap<T>) -> Ordering {
iter::order::cmp(self.iter(), other.iter())
}
}
impl<T: Show> Show for TrieMap<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));
@ -524,7 +531,7 @@ impl<S: Writer, T: Hash<S>> Hash<S> for TrieMap<T> {
/// set.clear();
/// assert!(set.is_empty());
/// ```
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd)]
#[deriving(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct TrieSet {
map: TrieMap<()>
}