@@ -21,7 +21,7 @@ use crate::map::{self, FrozenMap};
2121/// # Construction
2222///
2323/// If you're building a new set, and you don't expect many overlapping items, consider pushing
24- /// elements into a [`Vec`] and calling [`FrozenSet::from`] or using the [`FromIterator`]
24+ /// items into a [`Vec`] and calling [`FrozenSet::from`] or using the [`FromIterator`]
2525/// implementation via [`Iterator::collect`]. It is typically cheaper to collect into a [`Vec`] and
2626/// sort the items once at the end than it is to maintain a temporary set data structure.
2727///
@@ -30,7 +30,7 @@ use crate::map::{self, FrozenMap};
3030/// many common collections. You should prefer using a [`BTreeSet`], as it matches the sorted
3131/// semantics of [`FrozenSet`] and avoids a sort operation during conversion.
3232///
33- /// Overlapping keys encountered during construction preserve the last overlapping entry , matching
33+ /// Overlapping items encountered during construction preserve the last overlapping item , matching
3434/// similar behavior for other sets in the standard library.
3535///
3636/// Similar to the API of [`BTreeSet`], there are no convenience methods for constructing from a
6565 /// that the iterator is sorted and has no overlapping items.
6666 ///
6767 /// Panics if the `items` are not unique and sorted.
68- pub fn from_unique_sorted_iter ( items : impl IntoIterator < Item = T > ) -> Self
69- where
70- T : Ord ,
71- {
68+ pub fn from_unique_sorted_iter ( items : impl IntoIterator < Item = T > ) -> Self {
7269 FrozenSet {
7370 map : FrozenMap :: from_unique_sorted_box ( items. into_iter ( ) . map ( |t| ( t, ( ) ) ) . collect ( ) ) ,
7471 }
8279 /// # Correctness
8380 ///
8481 /// The caller must ensure that:
85- /// - The iterator yields elements in ascending order according to [`T: Ord`][Ord]
82+ /// - The iterator yields items in ascending order according to [`T: Ord`][Ord]
8683 /// - There are no overlapping items
8784 ///
8885 /// If these invariants are not upheld, the set will behave incorrectly (e.g.,
10097}
10198
10299impl < T : Ord > FromIterator < T > for FrozenSet < T > {
103- /// Creates a [`FrozenSet`] from an iterator of elements . If there are overlapping elements,
104- /// only the last copy is kept.
100+ /// Creates a [`FrozenSet`] from an iterator of items . If there are overlapping items, only the
101+ /// last copy is kept.
105102 fn from_iter < I : IntoIterator < Item = T > > ( items : I ) -> Self {
106103 FrozenSet {
107104 map : FrozenMap :: from_iter ( items. into_iter ( ) . map ( |t| ( t, ( ) ) ) ) ,
@@ -112,7 +109,7 @@ impl<T: Ord> FromIterator<T> for FrozenSet<T> {
112109impl < T > From < BTreeSet < T > > for FrozenSet < T > {
113110 /// Creates a [`FrozenSet`] from a [`BTreeSet`].
114111 ///
115- /// This is more efficient than [ `From<HashSet<T>>`] because [`BTreeSet`] already iterates in
112+ /// This is more efficient than `From<HashSet<T>>` because [`BTreeSet`] already iterates in
116113 /// sorted order, so no re-sorting is needed.
117114 fn from ( set : BTreeSet < T > ) -> Self {
118115 if set. is_empty ( ) {
@@ -133,7 +130,7 @@ where
133130{
134131 /// Creates a [`FrozenSet`] from a [`HashSet`].
135132 ///
136- /// The elements are sorted during construction.
133+ /// The items are sorted during construction.
137134 fn from ( set : HashSet < T , S > ) -> Self {
138135 if set. is_empty ( ) {
139136 return Self :: new ( ) ;
@@ -151,7 +148,7 @@ where
151148{
152149 /// Creates a [`FrozenSet`] from an [`IndexSet`].
153150 ///
154- /// The elements are sorted during construction.
151+ /// The items are sorted during construction.
155152 fn from ( set : IndexSet < T , S > ) -> Self {
156153 if set. is_empty ( ) {
157154 return Self :: new ( ) ;
@@ -163,12 +160,12 @@ where
163160}
164161
165162impl < T : Ord , const N : usize > From < [ T ; N ] > for FrozenSet < T > {
166- /// Creates a [`FrozenSet`] from an array of elements . If there are overlapping elements , the
167- /// last copy is kept.
163+ /// Creates a [`FrozenSet`] from an array of items . If there are overlapping items , the last
164+ /// copy is kept.
168165 ///
169- /// The elements are sorted during construction.
170- fn from ( elements : [ T ; N ] ) -> Self {
171- Self :: from_iter ( elements )
166+ /// The items are sorted during construction.
167+ fn from ( items : [ T ; N ] ) -> Self {
168+ Self :: from_iter ( items )
172169 }
173170}
174171
@@ -201,14 +198,14 @@ impl<T> FrozenSet<T> {
201198 self . map . get_key_value ( value) . map ( |( t, _) | t)
202199 }
203200
204- /// Returns a reference to the first element in the set, if any.
205- /// This element is always the minimum of all elements in the set.
201+ /// Returns a reference to the first element in the set, if any. This element is always the
202+ /// minimum of all elements in the set.
206203 pub fn first ( & self ) -> Option < & T > {
207204 self . map . first_key_value ( ) . map ( |( t, _) | t)
208205 }
209206
210- /// Returns a reference to the last element in the set, if any.
211- /// This element is always the maximum of all elements in the set.
207+ /// Returns a reference to the last element in the set, if any. This element is always the
208+ /// maximum of all elements in the set.
212209 pub fn last ( & self ) -> Option < & T > {
213210 self . map . last_key_value ( ) . map ( |( t, _) | t)
214211 }
@@ -230,8 +227,8 @@ impl<T> FrozenSet<T> {
230227 }
231228 }
232229
233- /// Returns `true` if `self` has no elements in common with `other`.
234- /// This is equivalent to checking for an empty intersection.
230+ /// Returns `true` if `self` has no elements in common with `other`. This is equivalent to
231+ /// checking for an empty intersection.
235232 pub fn is_disjoint ( & self , other : & Self ) -> bool
236233 where
237234 T : Ord ,
@@ -243,8 +240,8 @@ impl<T> FrozenSet<T> {
243240 }
244241 }
245242
246- /// Returns `true` if the set is a subset of another,
247- /// i.e., `other` contains at least all the elements in `self`.
243+ /// Returns `true` if the set is a subset of another, i.e., `other` contains at least all the
244+ /// elements in `self`.
248245 pub fn is_subset ( & self , other : & Self ) -> bool
249246 where
250247 T : Ord ,
@@ -255,8 +252,8 @@ impl<T> FrozenSet<T> {
255252 self . iter ( ) . all ( |v| other. contains ( v) )
256253 }
257254
258- /// Returns `true` if the set is a superset of another,
259- /// i.e., `self` contains at least all the elements in `other`.
255+ /// Returns `true` if the set is a superset of another, i.e., `self` contains at least all the
256+ /// elements in `other`.
260257 pub fn is_superset ( & self , other : & Self ) -> bool
261258 where
262259 T : Ord ,
@@ -297,8 +294,8 @@ impl<T> IntoIterator for FrozenSet<T> {
297294}
298295
299296// These could be newtype wrappers (BTreeSet does this), but type aliases are simpler to implement.
300- type Iter < ' a , T > = map:: Keys < ' a , T , ( ) > ;
301- type IntoIter < T > = map:: IntoKeys < T , ( ) > ;
297+ pub type Iter < ' a , T > = map:: Keys < ' a , T , ( ) > ;
298+ pub type IntoIter < T > = map:: IntoKeys < T , ( ) > ;
302299
303300/// An iterator over a sub-range of elements in a [`FrozenSet`].
304301pub struct Range < ' a , T > {
@@ -481,7 +478,7 @@ mod tests {
481478 }
482479
483480 #[ test]
484- #[ should_panic( expected = "FrozenMap entries must be sorted and unique " ) ]
481+ #[ should_panic( expected = "FrozenMap entries must be unique and sorted " ) ]
485482 fn test_from_unique_sorted_iter_panics ( ) {
486483 let _ = FrozenSet :: from_unique_sorted_iter ( [ 1 , 1 , 2 ] ) ;
487484 }
0 commit comments