diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-07-01 08:51:34 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-07-01 19:41:11 -0700 |
| commit | 87b61296a5cee1eaf7aecc130afa27d63887f707 (patch) | |
| tree | e2b0238e986435f9cd691610096ffcf9cee96f26 | |
| parent | 77b98247a26dcba11bd04f27ff8f5252ecd97df5 (diff) | |
| download | rust-87b61296a5cee1eaf7aecc130afa27d63887f707.tar.gz rust-87b61296a5cee1eaf7aecc130afa27d63887f707.zip | |
Compare values in TreeMap's 'lt' function
Closes #5194
| -rw-r--r-- | src/libextra/treemap.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index 5e898f8e59d..4216b5a6d1a 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -57,23 +57,25 @@ impl<K: Eq + TotalOrd, V: Eq> Eq for TreeMap<K, V> { } // Lexicographical comparison -fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>, +fn lt<K: Ord + TotalOrd, V: Ord>(a: &TreeMap<K, V>, b: &TreeMap<K, V>) -> bool { let mut x = a.iter(); let mut y = b.iter(); let (a_len, b_len) = (a.len(), b.len()); for uint::min(a_len, b_len).times { - let (key_a,_) = x.next().unwrap(); - let (key_b,_) = y.next().unwrap(); + let (key_a, value_a) = x.next().unwrap(); + let (key_b, value_b) = y.next().unwrap(); if *key_a < *key_b { return true; } if *key_a > *key_b { return false; } - }; + if *value_a < *value_b { return true; } + if *value_a > *value_b { return false; } + } a_len < b_len } -impl<K: Ord + TotalOrd, V> Ord for TreeMap<K, V> { +impl<K: Ord + TotalOrd, V: Ord> Ord for TreeMap<K, V> { #[inline] fn lt(&self, other: &TreeMap<K, V>) -> bool { lt(self, other) } #[inline] @@ -935,7 +937,7 @@ mod test_treemap { assert!(b.insert(0, 5)); assert!(a < b); assert!(a.insert(0, 7)); - assert!(!(a < b) && !(b < a)); + assert!(!(a < b) && b < a); assert!(b.insert(-2, 0)); assert!(b < a); assert!(a.insert(-5, 2)); |
