@@ -1490,6 +1490,12 @@ impl<T, A: Allocator> Vec<T, A> {
1490
1490
/// vec.insert(4, 5);
1491
1491
/// assert_eq!(vec, [1, 4, 2, 3, 5]);
1492
1492
/// ```
1493
+ ///
1494
+ /// # Time complexity
1495
+ ///
1496
+ /// Takes *O*([`Vec::len`]) time. All items after the insertion index must be
1497
+ /// shifted to the right. In the worst case, all elements are shifted when
1498
+ /// the insertion index is 0.
1493
1499
#[ cfg( not( no_global_oom_handling) ) ]
1494
1500
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1495
1501
pub fn insert ( & mut self , index : usize , element : T ) {
@@ -1913,6 +1919,13 @@ impl<T, A: Allocator> Vec<T, A> {
1913
1919
/// vec.push(3);
1914
1920
/// assert_eq!(vec, [1, 2, 3]);
1915
1921
/// ```
1922
+ ///
1923
+ /// # Time complexity
1924
+ ///
1925
+ /// Takes amortized *O*(1) time. If the vector's length would exceed its
1926
+ /// capacity after the push, *O*(*capacity*) time is taken to copy the
1927
+ /// vector's elements to a larger allocation. This expensive operation is
1928
+ /// offset by the *capacity* *O*(1) insertions it allows.
1916
1929
#[ cfg( not( no_global_oom_handling) ) ]
1917
1930
#[ inline]
1918
1931
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1961,6 +1974,10 @@ impl<T, A: Allocator> Vec<T, A> {
1961
1974
/// }
1962
1975
/// assert_eq!(from_iter_fallible(0..100), Ok(Vec::from_iter(0..100)));
1963
1976
/// ```
1977
+ ///
1978
+ /// # Time complexity
1979
+ ///
1980
+ /// Takes *O*(1) time.
1964
1981
#[ inline]
1965
1982
#[ unstable( feature = "vec_push_within_capacity" , issue = "100486" ) ]
1966
1983
pub fn push_within_capacity ( & mut self , value : T ) -> Result < ( ) , T > {
@@ -1990,6 +2007,10 @@ impl<T, A: Allocator> Vec<T, A> {
1990
2007
/// assert_eq!(vec.pop(), Some(3));
1991
2008
/// assert_eq!(vec, [1, 2]);
1992
2009
/// ```
2010
+ ///
2011
+ /// # Time complexity
2012
+ ///
2013
+ /// Takes *O*(1) time.
1993
2014
#[ inline]
1994
2015
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1995
2016
pub fn pop ( & mut self ) -> Option < T > {
0 commit comments