diff options
Diffstat (limited to 'compiler/rustc_data_structures/src/unord.rs')
-rw-r--r-- | compiler/rustc_data_structures/src/unord.rs | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index f35f18e51..6c8d54146 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -109,6 +109,12 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> { } } +impl<T> UnordItems<T, std::iter::Empty<T>> { + pub fn empty() -> Self { + UnordItems(std::iter::empty()) + } +} + impl<'a, T: Clone + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> { #[inline] pub fn cloned(self) -> UnordItems<T, impl Iterator<Item = T>> { @@ -133,6 +139,20 @@ impl<T: Ord, I: Iterator<Item = T>> UnordItems<T, I> { items } + #[inline] + pub fn into_sorted_stable_ord(self, use_stable_sort: bool) -> Vec<T> + where + T: Ord + StableOrd, + { + let mut items: Vec<T> = self.0.collect(); + if use_stable_sort { + items.sort(); + } else { + items.sort_unstable() + } + items + } + pub fn into_sorted_small_vec<HCX, const LEN: usize>(self, hcx: &HCX) -> SmallVec<[T; LEN]> where T: ToStableHashKey<HCX>, @@ -176,6 +196,11 @@ impl<V: Eq + Hash> UnordSet<V> { } #[inline] + pub fn is_empty(&self) -> bool { + self.inner.is_empty() + } + + #[inline] pub fn insert(&mut self, v: V) -> bool { self.inner.insert(v) } @@ -199,7 +224,7 @@ impl<V: Eq + Hash> UnordSet<V> { } #[inline] - pub fn items<'a>(&'a self) -> UnordItems<&'a V, impl Iterator<Item = &'a V>> { + pub fn items(&self) -> UnordItems<&V, impl Iterator<Item = &V>> { UnordItems(self.inner.iter()) } @@ -253,7 +278,7 @@ impl<V: Eq + Hash> UnordSet<V> { // We can safely extend this UnordSet from a set of unordered values because that // won't expose the internal ordering anywhere. #[inline] - pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) { + pub fn extend_unord<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) { self.inner.extend(items.0) } @@ -277,6 +302,12 @@ impl<V: Hash + Eq> FromIterator<V> for UnordSet<V> { } } +impl<V: Hash + Eq> From<FxHashSet<V>> for UnordSet<V> { + fn from(value: FxHashSet<V>) -> Self { + UnordSet { inner: value } + } +} + impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> { #[inline] fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { @@ -384,7 +415,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> { } #[inline] - pub fn items<'a>(&'a self) -> UnordItems<(&'a K, &'a V), impl Iterator<Item = (&'a K, &'a V)>> { + pub fn items(&self) -> UnordItems<(&K, &V), impl Iterator<Item = (&K, &V)>> { UnordItems(self.inner.iter()) } |