diff options
author | ljedrz <ljedrz@gmail.com> | 2018-11-18 10:44:49 +0100 |
---|---|---|
committer | ljedrz <ljedrz@gmail.com> | 2018-12-10 14:06:32 +0100 |
commit | 08c6bda3eed64f3a7e767f9e3792a6e94d395839 (patch) | |
tree | 986c49280ee8c33dddcd1fe04c0e3f9b8f622cd6 /src/librustc_data_structures | |
parent | eb772045f88ba8af8555f086b425225fbc891aa0 (diff) | |
download | rust-08c6bda3eed64f3a7e767f9e3792a6e94d395839.tar.gz |
sorted_map: readability/whitespace fixes
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r-- | src/librustc_data_structures/sorted_map.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_data_structures/sorted_map.rs b/src/librustc_data_structures/sorted_map.rs index c8f85797191..2fa8453c4b5 100644 --- a/src/librustc_data_structures/sorted_map.rs +++ b/src/librustc_data_structures/sorted_map.rs @@ -25,11 +25,10 @@ use std::ops::{RangeBounds, Bound, Index, IndexMut}; #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug, RustcEncodable, RustcDecodable)] pub struct SortedMap<K: Ord, V> { - data: Vec<(K,V)> + data: Vec<(K, V)> } impl<K: Ord, V> SortedMap<K, V> { - #[inline] pub fn new() -> SortedMap<K, V> { SortedMap { @@ -128,13 +127,13 @@ impl<K: Ord, V> SortedMap<K, V> { /// Iterate over the keys, sorted #[inline] - pub fn keys(&self) -> impl Iterator<Item=&K> + ExactSizeIterator { + pub fn keys(&self) -> impl Iterator<Item = &K> + ExactSizeIterator { self.data.iter().map(|&(ref k, _)| k) } /// Iterate over values, sorted by key #[inline] - pub fn values(&self) -> impl Iterator<Item=&V> + ExactSizeIterator { + pub fn values(&self) -> impl Iterator<Item = &V> + ExactSizeIterator { self.data.iter().map(|&(_, ref v)| v) } @@ -266,6 +265,7 @@ impl<K: Ord, V> SortedMap<K, V> { impl<K: Ord, V> IntoIterator for SortedMap<K, V> { type Item = (K, V); type IntoIter = ::std::vec::IntoIter<(K, V)>; + fn into_iter(self) -> Self::IntoIter { self.data.into_iter() } @@ -294,10 +294,12 @@ impl<'a, K, Q, V> IndexMut<&'a Q> for SortedMap<K, V> impl<K: Ord, V> FromIterator<(K, V)> for SortedMap<K, V> { fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self { let mut data: Vec<(K, V)> = iter.into_iter().collect(); + data.sort_unstable_by(|&(ref k1, _), &(ref k2, _)| k1.cmp(k2)); data.dedup_by(|&mut (ref k1, _), &mut (ref k2, _)| { k1.cmp(k2) == Ordering::Equal }); + SortedMap { data } |