diff options
| author | Jacob Asper <jacobasper191@gmail.com> | 2024-02-16 09:41:48 -0500 |
|---|---|---|
| committer | Jacob Asper <jacobasper191@gmail.com> | 2024-02-18 05:21:33 -0500 |
| commit | cb8ce9d9e543ccf16a2f0a04e47a3691af10d5a6 (patch) | |
| tree | a6fbac2d332c6fc4cfc6d891785c36bd6031987f /library/alloc/src/vec | |
| parent | bcb3545164d7621353c7b152b6339ce44c640add (diff) | |
time complexity for push
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 08e3cdedc66..7bdf92053f1 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1912,6 +1912,13 @@ impl<T, A: Allocator> Vec<T, A> { /// vec.push(3); /// assert_eq!(vec, [1, 2, 3]); /// ``` + /// + /// # Time complexity + /// + /// Takes amortized *O*(1) time. If the vector's length would exceed its capacity after + /// the push,*O*(*capacity*) space is allocated, doubling the capacity and + /// taking *O*(*capacity*) time. This expensive operation is offset by the + /// *capacity* *O*(1) insertions it allows. #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "rust1", since = "1.0.0")] |
