Skip to content

Commit cb8ce9d

Browse files
committed
time complexity for push
1 parent bcb3545 commit cb8ce9d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,13 @@ impl<T, A: Allocator> Vec<T, A> {
19121912
/// vec.push(3);
19131913
/// assert_eq!(vec, [1, 2, 3]);
19141914
/// ```
1915+
///
1916+
/// # Time complexity
1917+
///
1918+
/// Takes amortized *O*(1) time. If the vector's length would exceed its capacity after
1919+
/// the push,*O*(*capacity*) space is allocated, doubling the capacity and
1920+
/// taking *O*(*capacity*) time. This expensive operation is offset by the
1921+
/// *capacity* *O*(1) insertions it allows.
19151922
#[cfg(not(no_global_oom_handling))]
19161923
#[inline]
19171924
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)