@@ -344,6 +344,11 @@ impl<K, V, S> HashMap<K, V, S> {
344
344
/// println!("{key}");
345
345
/// }
346
346
/// ```
347
+ ///
348
+ /// # Performance
349
+ ///
350
+ /// In the current implementation, iterating over keys takes O(capacity) time
351
+ /// instead of O(len) because it internally visits empty buckets too.
347
352
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
348
353
pub fn keys ( & self ) -> Keys < ' _ , K , V > {
349
354
Keys { inner : self . iter ( ) }
@@ -370,6 +375,11 @@ impl<K, V, S> HashMap<K, V, S> {
370
375
/// vec.sort_unstable();
371
376
/// assert_eq!(vec, ["a", "b", "c"]);
372
377
/// ```
378
+ ///
379
+ /// # Performance
380
+ ///
381
+ /// In the current implementation, iterating over keys takes O(capacity) time
382
+ /// instead of O(len) because it internally visits empty buckets too.
373
383
#[ inline]
374
384
#[ rustc_lint_query_instability]
375
385
#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
@@ -395,6 +405,11 @@ impl<K, V, S> HashMap<K, V, S> {
395
405
/// println!("{val}");
396
406
/// }
397
407
/// ```
408
+ ///
409
+ /// # Performance
410
+ ///
411
+ /// In the current implementation, iterating over values takes O(capacity) time
412
+ /// instead of O(len) because it internally visits empty buckets too.
398
413
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
399
414
pub fn values ( & self ) -> Values < ' _ , K , V > {
400
415
Values { inner : self . iter ( ) }
@@ -422,6 +437,11 @@ impl<K, V, S> HashMap<K, V, S> {
422
437
/// println!("{val}");
423
438
/// }
424
439
/// ```
440
+ ///
441
+ /// # Performance
442
+ ///
443
+ /// In the current implementation, iterating over values takes O(capacity) time
444
+ /// instead of O(len) because it internally visits empty buckets too.
425
445
#[ stable( feature = "map_values_mut" , since = "1.10.0" ) ]
426
446
pub fn values_mut ( & mut self ) -> ValuesMut < ' _ , K , V > {
427
447
ValuesMut { inner : self . iter_mut ( ) }
@@ -448,6 +468,11 @@ impl<K, V, S> HashMap<K, V, S> {
448
468
/// vec.sort_unstable();
449
469
/// assert_eq!(vec, [1, 2, 3]);
450
470
/// ```
471
+ ///
472
+ /// # Performance
473
+ ///
474
+ /// In the current implementation, iterating over values takes O(capacity) time
475
+ /// instead of O(len) because it internally visits empty buckets too.
451
476
#[ inline]
452
477
#[ rustc_lint_query_instability]
453
478
#[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
@@ -473,6 +498,11 @@ impl<K, V, S> HashMap<K, V, S> {
473
498
/// println!("key: {key} val: {val}");
474
499
/// }
475
500
/// ```
501
+ ///
502
+ /// # Performance
503
+ ///
504
+ /// In the current implementation, iterating over map takes O(capacity) time
505
+ /// instead of O(len) because it internally visits empty buckets too.
476
506
#[ rustc_lint_query_instability]
477
507
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
478
508
pub fn iter ( & self ) -> Iter < ' _ , K , V > {
@@ -503,6 +533,11 @@ impl<K, V, S> HashMap<K, V, S> {
503
533
/// println!("key: {key} val: {val}");
504
534
/// }
505
535
/// ```
536
+ ///
537
+ /// # Performance
538
+ ///
539
+ /// In the current implementation, iterating over map takes O(capacity) time
540
+ /// instead of O(len) because it internally visits empty buckets too.
506
541
#[ rustc_lint_query_instability]
507
542
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
508
543
pub fn iter_mut ( & mut self ) -> IterMut < ' _ , K , V > {
@@ -633,6 +668,11 @@ impl<K, V, S> HashMap<K, V, S> {
633
668
/// map.retain(|&k, _| k % 2 == 0);
634
669
/// assert_eq!(map.len(), 4);
635
670
/// ```
671
+ ///
672
+ /// # Performance
673
+ ///
674
+ /// In the current implementation, this operation takes O(capacity) time
675
+ /// instead of O(len) because it internally visits empty buckets too.
636
676
#[ inline]
637
677
#[ rustc_lint_query_instability]
638
678
#[ stable( feature = "retain_hash_collection" , since = "1.18.0" ) ]
0 commit comments