@@ -344,6 +344,11 @@ impl<K, V, S> HashMap<K, V, S> {
344344 /// println!("{key}");
345345 /// }
346346 /// ```
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.
347352 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
348353 pub fn keys ( & self ) -> Keys < ' _ , K , V > {
349354 Keys { inner : self . iter ( ) }
@@ -370,6 +375,11 @@ impl<K, V, S> HashMap<K, V, S> {
370375 /// vec.sort_unstable();
371376 /// assert_eq!(vec, ["a", "b", "c"]);
372377 /// ```
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.
373383 #[ inline]
374384 #[ rustc_lint_query_instability]
375385 #[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
@@ -395,6 +405,11 @@ impl<K, V, S> HashMap<K, V, S> {
395405 /// println!("{val}");
396406 /// }
397407 /// ```
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.
398413 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
399414 pub fn values ( & self ) -> Values < ' _ , K , V > {
400415 Values { inner : self . iter ( ) }
@@ -422,6 +437,11 @@ impl<K, V, S> HashMap<K, V, S> {
422437 /// println!("{val}");
423438 /// }
424439 /// ```
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.
425445 #[ stable( feature = "map_values_mut" , since = "1.10.0" ) ]
426446 pub fn values_mut ( & mut self ) -> ValuesMut < ' _ , K , V > {
427447 ValuesMut { inner : self . iter_mut ( ) }
@@ -448,6 +468,11 @@ impl<K, V, S> HashMap<K, V, S> {
448468 /// vec.sort_unstable();
449469 /// assert_eq!(vec, [1, 2, 3]);
450470 /// ```
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.
451476 #[ inline]
452477 #[ rustc_lint_query_instability]
453478 #[ stable( feature = "map_into_keys_values" , since = "1.54.0" ) ]
@@ -473,6 +498,11 @@ impl<K, V, S> HashMap<K, V, S> {
473498 /// println!("key: {key} val: {val}");
474499 /// }
475500 /// ```
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.
476506 #[ rustc_lint_query_instability]
477507 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
478508 pub fn iter ( & self ) -> Iter < ' _ , K , V > {
@@ -503,6 +533,11 @@ impl<K, V, S> HashMap<K, V, S> {
503533 /// println!("key: {key} val: {val}");
504534 /// }
505535 /// ```
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.
506541 #[ rustc_lint_query_instability]
507542 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
508543 pub fn iter_mut ( & mut self ) -> IterMut < ' _ , K , V > {
@@ -633,6 +668,11 @@ impl<K, V, S> HashMap<K, V, S> {
633668 /// map.retain(|&k, _| k % 2 == 0);
634669 /// assert_eq!(map.len(), 4);
635670 /// ```
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.
636676 #[ inline]
637677 #[ rustc_lint_query_instability]
638678 #[ stable( feature = "retain_hash_collection" , since = "1.18.0" ) ]
0 commit comments