@@ -68,33 +68,35 @@ impl<V: Eq + Hash> FxHashSet<V> {
6868 #[ track_caller]
6969 #[ allow( clippy:: iter_without_into_iter) ]
7070 #[ deprecated(
71- note = "FxHashSet does not guarantee stable iteration order; use FxIndexSet or unstable_iter() instead"
71+ note = "FxHashSet does not guarantee stable iteration order; use BTreeSet or unstable_iter() instead"
7272 ) ]
7373 pub fn iter ( & self ) -> std:: collections:: hash_set:: Iter < ' _ , V > {
7474 panic ! (
75- "FxHashSet does not guarantee stable iteration order; use FxIndexSet or unstable_iter() instead"
75+ "FxHashSet does not guarantee stable iteration order; use BTreeSet or unstable_iter() instead"
7676 ) ;
7777 }
7878
7979 #[ track_caller]
8080 #[ allow( clippy:: should_implement_trait) ]
8181 #[ deprecated(
82- note = "FxHashSet does not guarantee stable iteration order; use FxIndexSet or unstable_into_iter() instead"
82+ note = "FxHashSet does not guarantee stable iteration order; use BTreeSet or unstable_into_iter() instead"
8383 ) ]
8484 pub fn into_iter ( self ) -> std:: collections:: hash_set:: IntoIter < V > {
8585 panic ! (
86- "FxHashSet does not guarantee stable iteration order; use FxIndexSet or unstable_into_iter() instead"
86+ "FxHashSet does not guarantee stable iteration order; use BTreeSet or unstable_into_iter() instead"
8787 ) ;
8888 }
8989}
9090
9191impl < V : Ord > FxHashSet < V > {
92+ /// If you use this often, consider using `BTreeMap` instead of `FxHashMap`.
9293 pub fn sorted_ref_vec ( & self ) -> Vec < & V > {
9394 let mut vec: Vec < & V > = self . 0 . iter ( ) . collect ( ) ;
9495 vec. sort ( ) ;
9596 vec
9697 }
9798
99+ /// If you use this often, consider using `BTreeMap` instead of `FxHashMap`.
98100 pub fn into_sorted_vec ( self ) -> Vec < V > {
99101 let mut vec: Vec < V > = self . 0 . into_iter ( ) . collect ( ) ;
100102 vec. sort ( ) ;
@@ -199,83 +201,113 @@ impl<K: Eq + Hash, V> FxHashMap<K, V> {
199201 #[ track_caller]
200202 #[ allow( clippy:: iter_without_into_iter) ]
201203 #[ deprecated(
202- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_iter() instead"
204+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_iter() instead"
203205 ) ]
204206 pub fn iter ( & self ) -> std:: collections:: hash_map:: Iter < ' _ , K , V > {
205207 panic ! (
206- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_iter() instead"
208+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_iter() instead"
207209 ) ;
208210 }
209211
210212 #[ track_caller]
211213 #[ deprecated(
212- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_keys() instead"
214+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_keys() instead"
213215 ) ]
214216 pub fn keys ( & self ) -> std:: collections:: hash_map:: Keys < ' _ , K , V > {
215217 panic ! (
216- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_keys() instead"
218+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_keys() instead"
217219 ) ;
218220 }
219221
220222 #[ track_caller]
221223 #[ deprecated(
222- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_values() instead"
224+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_values() instead"
223225 ) ]
224226 pub fn values ( & self ) -> std:: collections:: hash_map:: Values < ' _ , K , V > {
225227 panic ! (
226- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_values() instead"
228+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_values() instead"
227229 ) ;
228230 }
229231
230232 #[ track_caller]
231233 #[ allow( clippy:: iter_without_into_iter) ]
232234 #[ deprecated(
233- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_iter_mut() instead"
235+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_iter_mut() instead"
234236 ) ]
235237 pub fn iter_mut ( & mut self ) -> std:: collections:: hash_map:: IterMut < ' _ , K , V > {
236238 panic ! (
237- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_iter_mut() instead"
239+ "FxHashMap does not guarantee stable iteration order; use FxIndexMap/BTreeMap or unstable_iter_mut() instead"
238240 ) ;
239241 }
240242
241243 #[ track_caller]
242244 #[ deprecated(
243- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_values_mut() instead"
245+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_values_mut() instead"
244246 ) ]
245247 pub fn values_mut ( & mut self ) -> std:: collections:: hash_map:: ValuesMut < ' _ , K , V > {
246248 panic ! (
247- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_values_mut() instead"
249+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_values_mut() instead"
248250 ) ;
249251 }
250252
251253 #[ track_caller]
252254 #[ allow( clippy:: should_implement_trait) ]
253255 #[ deprecated(
254- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_into_iter() instead"
256+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_into_iter() instead"
255257 ) ]
256258 pub fn into_iter ( self ) -> std:: collections:: hash_map:: IntoIter < K , V > {
257259 panic ! (
258- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_into_iter() instead"
260+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_into_iter() instead"
259261 ) ;
260262 }
261263
262264 #[ track_caller]
263265 #[ deprecated(
264- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_into_keys() instead"
266+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_into_keys() instead"
265267 ) ]
266268 pub fn into_keys ( self ) -> std:: collections:: hash_map:: IntoKeys < K , V > {
267269 panic ! (
268- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_into_keys() instead"
270+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_into_keys() instead"
269271 ) ;
270272 }
271273
272274 #[ track_caller]
273275 #[ deprecated(
274- note = "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_into_values() instead"
276+ note = "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_into_values() instead"
275277 ) ]
276278 pub fn into_values ( self ) -> std:: collections:: hash_map:: IntoValues < K , V > {
277279 panic ! (
278- "FxHashMap does not guarantee stable iteration order; use FxIndexMap or unstable_into_values() instead"
280+ "FxHashMap does not guarantee stable iteration order; use BTreeMap or unstable_into_values() instead"
279281 ) ;
280282 }
281283}
284+
285+ impl < K : Ord , V > FxHashMap < K , V > {
286+ /// If you use this often, consider using `BTreeMap` instead of `FxHashMap`.
287+ pub fn sorted_key_ref_vec ( & self ) -> Vec < & K > {
288+ let mut vec: Vec < & K > = self . 0 . keys ( ) . collect ( ) ;
289+ vec. sort ( ) ;
290+ vec
291+ }
292+
293+ /// If you use this often, consider using `BTreeMap` instead of `FxHashMap`.
294+ pub fn into_sorted_key_vec ( self ) -> Vec < K > {
295+ let mut vec: Vec < K > = self . 0 . into_keys ( ) . collect ( ) ;
296+ vec. sort ( ) ;
297+ vec
298+ }
299+
300+ /// If you use this often, consider using `BTreeMap` instead of `FxHashMap`.
301+ pub fn sorted_ref_vec ( & self ) -> Vec < ( & K , & V ) > {
302+ let mut vec: Vec < ( & K , & V ) > = self . 0 . iter ( ) . collect ( ) ;
303+ vec. sort_by ( |( k1, _) , ( k2, _) | k1. cmp ( k2) ) ;
304+ vec
305+ }
306+
307+ /// If you use this often, consider using `BTreeMap` instead of `FxHashMap`.
308+ pub fn into_sorted_vec ( self ) -> Vec < ( K , V ) > {
309+ let mut vec: Vec < ( K , V ) > = self . 0 . into_iter ( ) . collect ( ) ;
310+ vec. sort_by ( |( k1, _) , ( k2, _) | k1. cmp ( k2) ) ;
311+ vec
312+ }
313+ }
0 commit comments