From d63e0f0e477654cb39036eb6f8b45e2dd6f4d371 Mon Sep 17 00:00:00 2001 From: Takashi Idobe Date: Thu, 23 Sep 2021 17:58:02 -0500 Subject: [PATCH 1/4] Add time complexities to linked_list.rs --- library/alloc/src/collections/linked_list.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 9d45c5082db43..e98b32703362e 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -631,6 +631,8 @@ impl LinkedList { /// Returns `true` if the `LinkedList` contains an element equal to the /// given value. /// + /// This operation should compute in *O*(*n*) time. + /// /// # Examples /// /// ``` @@ -655,6 +657,8 @@ impl LinkedList { /// Provides a reference to the front element, or `None` if the list is /// empty. + /// + /// This operation should compute in *O*(*1*) time. /// /// # Examples /// @@ -675,6 +679,8 @@ impl LinkedList { /// Provides a mutable reference to the front element, or `None` if the list /// is empty. + /// + /// This operation should compute in *O*(*1*) time. /// /// # Examples /// @@ -701,6 +707,8 @@ impl LinkedList { /// Provides a reference to the back element, or `None` if the list is /// empty. + /// + /// This operation should compute in *O*(*1*) time. /// /// # Examples /// @@ -721,6 +729,8 @@ impl LinkedList { /// Provides a mutable reference to the back element, or `None` if the list /// is empty. + /// + /// This operation should compute in *O*(*1*) time. /// /// # Examples /// From b146525140a8776aec1f7852643ec2abd787a197 Mon Sep 17 00:00:00 2001 From: Takashi Idobe Date: Thu, 23 Sep 2021 18:20:46 -0500 Subject: [PATCH 2/4] remove trailing whitespace --- library/alloc/src/collections/linked_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index e98b32703362e..dfd0039baf64d 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -657,7 +657,7 @@ impl LinkedList { /// Provides a reference to the front element, or `None` if the list is /// empty. - /// + /// /// This operation should compute in *O*(*1*) time. /// /// # Examples @@ -679,7 +679,7 @@ impl LinkedList { /// Provides a mutable reference to the front element, or `None` if the list /// is empty. - /// + /// /// This operation should compute in *O*(*1*) time. /// /// # Examples @@ -707,7 +707,7 @@ impl LinkedList { /// Provides a reference to the back element, or `None` if the list is /// empty. - /// + /// /// This operation should compute in *O*(*1*) time. /// /// # Examples @@ -729,7 +729,7 @@ impl LinkedList { /// Provides a mutable reference to the back element, or `None` if the list /// is empty. - /// + /// /// This operation should compute in *O*(*1*) time. /// /// # Examples From cebba31d4ae6bd1dea410dc7d74e496846f5980d Mon Sep 17 00:00:00 2001 From: Takashi Idobe Date: Fri, 24 Sep 2021 08:33:49 -0500 Subject: [PATCH 3/4] unitalicize O(1) complexities --- library/alloc/src/collections/linked_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index dfd0039baf64d..c5c32674eec15 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -658,7 +658,7 @@ impl LinkedList { /// Provides a reference to the front element, or `None` if the list is /// empty. /// - /// This operation should compute in *O*(*1*) time. + /// This operation should compute in *O*(1) time. /// /// # Examples /// @@ -680,7 +680,7 @@ impl LinkedList { /// Provides a mutable reference to the front element, or `None` if the list /// is empty. /// - /// This operation should compute in *O*(*1*) time. + /// This operation should compute in *O*(1) time. /// /// # Examples /// @@ -708,7 +708,7 @@ impl LinkedList { /// Provides a reference to the back element, or `None` if the list is /// empty. /// - /// This operation should compute in *O*(*1*) time. + /// This operation should compute in *O*(1) time. /// /// # Examples /// @@ -730,7 +730,7 @@ impl LinkedList { /// Provides a mutable reference to the back element, or `None` if the list /// is empty. /// - /// This operation should compute in *O*(*1*) time. + /// This operation should compute in *O*(1) time. /// /// # Examples /// From fa1a87888c49b72b7963055fafe8cd22b32a7a46 Mon Sep 17 00:00:00 2001 From: takashiidobe Date: Fri, 24 Sep 2021 14:42:48 -0500 Subject: [PATCH 4/4] add time complexity for into_sorted_vec --- library/alloc/src/collections/binary_heap.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs index 28e4f8bba05c8..d228c66f52492 100644 --- a/library/alloc/src/collections/binary_heap.rs +++ b/library/alloc/src/collections/binary_heap.rs @@ -506,6 +506,10 @@ impl BinaryHeap { /// let vec = heap.into_sorted_vec(); /// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]); /// ``` + /// + /// # Time complexity + /// + /// The time complexity of `into_sorted_vec` on a heap containing `n` items is *O*(*n*log(*n*)). #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] pub fn into_sorted_vec(mut self) -> Vec { let mut end = self.len();