}
}
+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>> {
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>,
self.inner.len()
}
+ #[inline]
+ pub fn is_empty(&self) -> bool {
+ self.inner.is_empty()
+ }
+
#[inline]
pub fn insert(&mut self, v: V) -> bool {
self.inner.insert(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())
}
// 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)
}
}
}
+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) {
}
#[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())
}