@@ -1524,6 +1524,12 @@ impl<T, A: Allocator> Vec<T, A> {
1524
1524
/// vec.insert(4, 5);
1525
1525
/// assert_eq!(vec, [1, 4, 2, 3, 5]);
1526
1526
/// ```
1527
+ ///
1528
+ /// # Time complexity
1529
+ ///
1530
+ /// Takes *O*([`Vec::len`]) time. All items after the insertion index must be
1531
+ /// shifted to the right. In the worst case, all elements are shifted when
1532
+ /// the insertion index is 0.
1527
1533
#[ cfg( not( no_global_oom_handling) ) ]
1528
1534
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1529
1535
pub fn insert ( & mut self , index : usize , element : T ) {
@@ -1947,6 +1953,13 @@ impl<T, A: Allocator> Vec<T, A> {
1947
1953
/// vec.push(3);
1948
1954
/// assert_eq!(vec, [1, 2, 3]);
1949
1955
/// ```
1956
+ ///
1957
+ /// # Time complexity
1958
+ ///
1959
+ /// Takes amortized *O*(1) time. If the vector's length would exceed its
1960
+ /// capacity after the push, *O*(*capacity*) time is taken to copy the
1961
+ /// vector's elements to a larger allocation. This expensive operation is
1962
+ /// offset by the *capacity* *O*(1) insertions it allows.
1950
1963
#[ cfg( not( no_global_oom_handling) ) ]
1951
1964
#[ inline]
1952
1965
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1995,6 +2008,10 @@ impl<T, A: Allocator> Vec<T, A> {
1995
2008
/// }
1996
2009
/// assert_eq!(from_iter_fallible(0..100), Ok(Vec::from_iter(0..100)));
1997
2010
/// ```
2011
+ ///
2012
+ /// # Time complexity
2013
+ ///
2014
+ /// Takes *O*(1) time.
1998
2015
#[ inline]
1999
2016
#[ unstable( feature = "vec_push_within_capacity" , issue = "100486" ) ]
2000
2017
pub fn push_within_capacity ( & mut self , value : T ) -> Result < ( ) , T > {
@@ -2024,6 +2041,10 @@ impl<T, A: Allocator> Vec<T, A> {
2024
2041
/// assert_eq!(vec.pop(), Some(3));
2025
2042
/// assert_eq!(vec, [1, 2]);
2026
2043
/// ```
2044
+ ///
2045
+ /// # Time complexity
2046
+ ///
2047
+ /// Takes *O*(1) time.
2027
2048
#[ inline]
2028
2049
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2029
2050
pub fn pop ( & mut self ) -> Option < T > {
0 commit comments