-//! A double-ended queue implemented with a growable ring buffer.
+//! A double-ended queue (deque) implemented with a growable ring buffer.
//!
//! This queue has *O*(1) amortized inserts and removals from both ends of the
//! container. It also has *O*(1) indexing like a vector. The contained elements
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for VecDeque<T> {
- /// Creates an empty `VecDeque<T>`.
+ /// Creates an empty deque.
#[inline]
fn default() -> VecDeque<T> {
VecDeque::new()
}
impl<T> VecDeque<T> {
- /// Creates an empty `VecDeque`.
+ /// Creates an empty deque.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let vector: VecDeque<u32> = VecDeque::new();
+ /// let deque: VecDeque<u32> = VecDeque::new();
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
VecDeque::new_in(Global)
}
- /// Creates an empty `VecDeque` with space for at least `capacity` elements.
+ /// Creates an empty deque with space for at least `capacity` elements.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let vector: VecDeque<u32> = VecDeque::with_capacity(10);
+ /// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
}
impl<T, A: Allocator> VecDeque<T, A> {
- /// Creates an empty `VecDeque`.
+ /// Creates an empty deque.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let vector: VecDeque<u32> = VecDeque::new();
+ /// let deque: VecDeque<u32> = VecDeque::new();
/// ```
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
VecDeque::with_capacity_in(INITIAL_CAPACITY, alloc)
}
- /// Creates an empty `VecDeque` with space for at least `capacity` elements.
+ /// Creates an empty deque with space for at least `capacity` elements.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let vector: VecDeque<u32> = VecDeque::with_capacity(10);
+ /// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
/// ```
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {
unsafe { ptr::swap(self.ptr().add(ri), self.ptr().add(rj)) }
}
- /// Returns the number of elements the `VecDeque` can hold without
+ /// Returns the number of elements the deque can hold without
/// reallocating.
///
/// # Examples
}
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
- /// given `VecDeque`. Does nothing if the capacity is already sufficient.
+ /// given deque. Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it requests. Therefore
/// capacity can not be relied upon to be precisely minimal. Prefer [`reserve`] if future
/// ```
/// use std::collections::VecDeque;
///
- /// let mut buf: VecDeque<i32> = vec![1].into_iter().collect();
+ /// let mut buf: VecDeque<i32> = [1].into();
/// buf.reserve_exact(10);
/// assert!(buf.capacity() >= 11);
/// ```
}
/// Reserves capacity for at least `additional` more elements to be inserted in the given
- /// `VecDeque`. The collection may reserve more space to avoid frequent reallocations.
+ /// deque. The collection may reserve more space to avoid frequent reallocations.
///
/// # Panics
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut buf: VecDeque<i32> = vec![1].into_iter().collect();
+ /// let mut buf: VecDeque<i32> = [1].into();
/// buf.reserve(10);
/// assert!(buf.capacity() >= 11);
/// ```
}
/// Tries to reserve the minimum capacity for exactly `additional` more elements to
- /// be inserted in the given `VecDeque<T>`. After calling `try_reserve_exact`,
+ /// be inserted in the given deque. After calling `try_reserve_exact`,
/// capacity will be greater than or equal to `self.len() + additional`.
/// Does nothing if the capacity is already sufficient.
///
/// Note that the allocator may give the collection more space than it
/// requests. Therefore, capacity can not be relied upon to be precisely
- /// minimal. Prefer [`reserve`] if future insertions are expected.
+ /// minimal. Prefer [`try_reserve`] if future insertions are expected.
///
- /// [`reserve`]: VecDeque::reserve
+ /// [`try_reserve`]: VecDeque::try_reserve
///
/// # Errors
///
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
- /// in the given `VecDeque<T>`. The collection may reserve more space to avoid
+ /// in the given deque. The collection may reserve more space to avoid
/// frequent reallocations. After calling `try_reserve`, capacity will be
/// greater than or equal to `self.len() + additional`. Does nothing if
/// capacity is already sufficient.
Ok(())
}
- /// Shrinks the capacity of the `VecDeque` as much as possible.
+ /// Shrinks the capacity of the deque as much as possible.
///
/// It will drop down as close as possible to the length but the allocator may still inform the
- /// `VecDeque` that there is space for a few more elements.
+ /// deque that there is space for a few more elements.
///
/// # Examples
///
self.shrink_to(0);
}
- /// Shrinks the capacity of the `VecDeque` with a lower bound.
+ /// Shrinks the capacity of the deque with a lower bound.
///
/// The capacity will remain at least as large as both the length
/// and the supplied value.
}
}
- /// Shortens the `VecDeque`, keeping the first `len` elements and dropping
+ /// Shortens the deque, keeping the first `len` elements and dropping
/// the rest.
///
- /// If `len` is greater than the `VecDeque`'s current length, this has no
+ /// If `len` is greater than the deque's current length, this has no
/// effect.
///
/// # Examples
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
// SAFETY: The internal `IterMut` safety invariant is established because the
- // `ring` we create is a dereferencable slice for lifetime '_.
+ // `ring` we create is a dereferenceable slice for lifetime '_.
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
unsafe { IterMut::new(ring, self.tail, self.head, PhantomData) }
}
/// Returns a pair of slices which contain, in order, the contents of the
- /// `VecDeque`.
+ /// deque.
///
/// If [`make_contiguous`] was previously called, all elements of the
- /// `VecDeque` will be in the first slice and the second slice will be empty.
+ /// deque will be in the first slice and the second slice will be empty.
///
/// [`make_contiguous`]: VecDeque::make_contiguous
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut vector = VecDeque::new();
+ /// let mut deque = VecDeque::new();
///
- /// vector.push_back(0);
- /// vector.push_back(1);
- /// vector.push_back(2);
+ /// deque.push_back(0);
+ /// deque.push_back(1);
+ /// deque.push_back(2);
///
- /// assert_eq!(vector.as_slices(), (&[0, 1, 2][..], &[][..]));
+ /// assert_eq!(deque.as_slices(), (&[0, 1, 2][..], &[][..]));
///
- /// vector.push_front(10);
- /// vector.push_front(9);
+ /// deque.push_front(10);
+ /// deque.push_front(9);
///
- /// assert_eq!(vector.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
+ /// assert_eq!(deque.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
/// ```
#[inline]
#[stable(feature = "deque_extras_15", since = "1.5.0")]
}
/// Returns a pair of slices which contain, in order, the contents of the
- /// `VecDeque`.
+ /// deque.
///
/// If [`make_contiguous`] was previously called, all elements of the
- /// `VecDeque` will be in the first slice and the second slice will be empty.
+ /// deque will be in the first slice and the second slice will be empty.
///
/// [`make_contiguous`]: VecDeque::make_contiguous
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut vector = VecDeque::new();
+ /// let mut deque = VecDeque::new();
///
- /// vector.push_back(0);
- /// vector.push_back(1);
+ /// deque.push_back(0);
+ /// deque.push_back(1);
///
- /// vector.push_front(10);
- /// vector.push_front(9);
+ /// deque.push_front(10);
+ /// deque.push_front(9);
///
- /// vector.as_mut_slices().0[0] = 42;
- /// vector.as_mut_slices().1[0] = 24;
- /// assert_eq!(vector.as_slices(), (&[42, 10][..], &[24, 1][..]));
+ /// deque.as_mut_slices().0[0] = 42;
+ /// deque.as_mut_slices().1[0] = 24;
+ /// assert_eq!(deque.as_slices(), (&[42, 10][..], &[24, 1][..]));
/// ```
#[inline]
#[stable(feature = "deque_extras_15", since = "1.5.0")]
}
}
- /// Returns the number of elements in the `VecDeque`.
+ /// Returns the number of elements in the deque.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut v = VecDeque::new();
- /// assert_eq!(v.len(), 0);
- /// v.push_back(1);
- /// assert_eq!(v.len(), 1);
+ /// let mut deque = VecDeque::new();
+ /// assert_eq!(deque.len(), 0);
+ /// deque.push_back(1);
+ /// assert_eq!(deque.len(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
count(self.tail, self.head, self.cap())
}
- /// Returns `true` if the `VecDeque` is empty.
+ /// Returns `true` if the deque is empty.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut v = VecDeque::new();
- /// assert!(v.is_empty());
- /// v.push_front(1);
- /// assert!(!v.is_empty());
+ /// let mut deque = VecDeque::new();
+ /// assert!(deque.is_empty());
+ /// deque.push_front(1);
+ /// assert!(!deque.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
(tail, head)
}
- /// Creates an iterator that covers the specified range in the `VecDeque`.
+ /// Creates an iterator that covers the specified range in the deque.
///
/// # Panics
///
/// Panics if the starting point is greater than the end point or if
- /// the end point is greater than the length of the vector.
+ /// the end point is greater than the length of the deque.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
- /// let range = v.range(2..).copied().collect::<VecDeque<_>>();
+ /// let deque: VecDeque<_> = [1, 2, 3].into();
+ /// let range = deque.range(2..).copied().collect::<VecDeque<_>>();
/// assert_eq!(range, [3]);
///
/// // A full range covers all contents
- /// let all = v.range(..);
+ /// let all = deque.range(..);
/// assert_eq!(all.len(), 3);
/// ```
#[inline]
}
}
- /// Creates an iterator that covers the specified mutable range in the `VecDeque`.
+ /// Creates an iterator that covers the specified mutable range in the deque.
///
/// # Panics
///
/// Panics if the starting point is greater than the end point or if
- /// the end point is greater than the length of the vector.
+ /// the end point is greater than the length of the deque.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
- /// for v in v.range_mut(2..) {
+ /// let mut deque: VecDeque<_> = [1, 2, 3].into();
+ /// for v in deque.range_mut(2..) {
/// *v *= 2;
/// }
- /// assert_eq!(v, vec![1, 2, 6]);
+ /// assert_eq!(deque, [1, 2, 6]);
///
/// // A full range covers all contents
- /// for v in v.range_mut(..) {
+ /// for v in deque.range_mut(..) {
/// *v *= 2;
/// }
- /// assert_eq!(v, vec![2, 4, 12]);
+ /// assert_eq!(deque, [2, 4, 12]);
/// ```
#[inline]
#[stable(feature = "deque_range", since = "1.51.0")]
let (tail, head) = self.range_tail_head(range);
// SAFETY: The internal `IterMut` safety invariant is established because the
- // `ring` we create is a dereferencable slice for lifetime '_.
+ // `ring` we create is a dereferenceable slice for lifetime '_.
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
unsafe { IterMut::new(ring, tail, head, PhantomData) }
}
/// Creates a draining iterator that removes the specified range in the
- /// `VecDeque` and yields the removed items.
+ /// deque and yields the removed items.
///
/// Note 1: The element range is removed even if the iterator is not
/// consumed until the end.
/// # Panics
///
/// Panics if the starting point is greater than the end point or if
- /// the end point is greater than the length of the vector.
+ /// the end point is greater than the length of the deque.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
- /// let drained = v.drain(2..).collect::<VecDeque<_>>();
+ /// let mut deque: VecDeque<_> = [1, 2, 3].into();
+ /// let drained = deque.drain(2..).collect::<VecDeque<_>>();
/// assert_eq!(drained, [3]);
- /// assert_eq!(v, [1, 2]);
+ /// assert_eq!(deque, [1, 2]);
///
/// // A full range clears all contents
- /// v.drain(..);
- /// assert!(v.is_empty());
+ /// deque.drain(..);
+ /// assert!(deque.is_empty());
/// ```
#[inline]
#[stable(feature = "drain", since = "1.6.0")]
unsafe { Drain::new(drain_head, head, iter, deque) }
}
- /// Clears the `VecDeque`, removing all values.
+ /// Clears the deque, removing all values.
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut v = VecDeque::new();
- /// v.push_back(1);
- /// v.clear();
- /// assert!(v.is_empty());
+ /// let mut deque = VecDeque::new();
+ /// deque.push_back(1);
+ /// deque.clear();
+ /// assert!(deque.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
self.truncate(0);
}
- /// Returns `true` if the `VecDeque` contains an element equal to the
+ /// Returns `true` if the deque contains an element equal to the
/// given value.
///
/// # Examples
/// ```
/// use std::collections::VecDeque;
///
- /// let mut vector: VecDeque<u32> = VecDeque::new();
+ /// let mut deque: VecDeque<u32> = VecDeque::new();
///
- /// vector.push_back(0);
- /// vector.push_back(1);
+ /// deque.push_back(0);
+ /// deque.push_back(1);
///
- /// assert_eq!(vector.contains(&1), true);
- /// assert_eq!(vector.contains(&10), false);
+ /// assert_eq!(deque.contains(&1), true);
+ /// assert_eq!(deque.contains(&10), false);
/// ```
#[stable(feature = "vec_deque_contains", since = "1.12.0")]
pub fn contains(&self, x: &T) -> bool
a.contains(x) || b.contains(x)
}
- /// Provides a reference to the front element, or `None` if the `VecDeque` is
+ /// Provides a reference to the front element, or `None` if the deque is
/// empty.
///
/// # Examples
}
/// Provides a mutable reference to the front element, or `None` if the
- /// `VecDeque` is empty.
+ /// deque is empty.
///
/// # Examples
///
self.get_mut(0)
}
- /// Provides a reference to the back element, or `None` if the `VecDeque` is
+ /// Provides a reference to the back element, or `None` if the deque is
/// empty.
///
/// # Examples
}
/// Provides a mutable reference to the back element, or `None` if the
- /// `VecDeque` is empty.
+ /// deque is empty.
///
/// # Examples
///
self.get_mut(self.len().wrapping_sub(1))
}
- /// Removes the first element and returns it, or `None` if the `VecDeque` is
+ /// Removes the first element and returns it, or `None` if the deque is
/// empty.
///
/// # Examples
}
}
- /// Removes the last element from the `VecDeque` and returns it, or `None` if
+ /// Removes the last element from the deque and returns it, or `None` if
/// it is empty.
///
/// # Examples
}
}
- /// Prepends an element to the `VecDeque`.
+ /// Prepends an element to the deque.
///
/// # Examples
///
}
}
- /// Appends an element to the back of the `VecDeque`.
+ /// Appends an element to the back of the deque.
///
/// # Examples
///
self.tail <= self.head
}
- /// Removes an element from anywhere in the `VecDeque` and returns it,
+ /// Removes an element from anywhere in the deque and returns it,
/// replacing it with the first element.
///
/// This does not preserve ordering, but is *O*(1).
self.pop_front()
}
- /// Removes an element from anywhere in the `VecDeque` and returns it, replacing it with the
- /// last element.
+ /// Removes an element from anywhere in the deque and returns it,
+ /// replacing it with the last element.
///
/// This does not preserve ordering, but is *O*(1).
///
self.pop_back()
}
- /// Inserts an element at `index` within the `VecDeque`, shifting all elements with indices
- /// greater than or equal to `index` towards the back.
+ /// Inserts an element at `index` within the deque, shifting all elements
+ /// with indices greater than or equal to `index` towards the back.
///
/// Element at index 0 is the front of the queue.
///
/// # Panics
///
- /// Panics if `index` is greater than `VecDeque`'s length
+ /// Panics if `index` is greater than deque's length
///
/// # Examples
///
}
}
- /// Removes and returns the element at `index` from the `VecDeque`.
+ /// Removes and returns the element at `index` from the deque.
/// Whichever end is closer to the removal point will be moved to make
/// room, and all the affected elements will be moved to new positions.
/// Returns `None` if `index` is out of bounds.
elem
}
- /// Splits the `VecDeque` into two at the given index.
+ /// Splits the deque into two at the given index.
///
/// Returns a newly allocated `VecDeque`. `self` contains elements `[0, at)`,
- /// and the returned `VecDeque` contains elements `[at, len)`.
+ /// and the returned deque contains elements `[at, len)`.
///
/// Note that the capacity of `self` does not change.
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut buf: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
+ /// let mut buf: VecDeque<_> = [1, 2, 3].into();
/// let buf2 = buf.split_off(1);
/// assert_eq!(buf, [1]);
/// assert_eq!(buf2, [2, 3]);
/// ```
/// use std::collections::VecDeque;
///
- /// let mut buf: VecDeque<_> = vec![1, 2].into_iter().collect();
- /// let mut buf2: VecDeque<_> = vec![3, 4].into_iter().collect();
+ /// let mut buf: VecDeque<_> = [1, 2].into();
+ /// let mut buf2: VecDeque<_> = [3, 4].into();
/// buf.append(&mut buf2);
/// assert_eq!(buf, [1, 2, 3, 4]);
/// assert_eq!(buf2, []);
pub fn retain<F>(&mut self, mut f: F)
where
F: FnMut(&T) -> bool,
+ {
+ self.retain_mut(|elem| f(elem));
+ }
+
+ /// Retains only the elements specified by the predicate.
+ ///
+ /// In other words, remove all elements `e` such that `f(&e)` returns false.
+ /// This method operates in place, visiting each element exactly once in the
+ /// original order, and preserves the order of the retained elements.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(vec_retain_mut)]
+ ///
+ /// use std::collections::VecDeque;
+ ///
+ /// let mut buf = VecDeque::new();
+ /// buf.extend(1..5);
+ /// buf.retain_mut(|x| if *x % 2 == 0 {
+ /// *x += 1;
+ /// true
+ /// } else {
+ /// false
+ /// });
+ /// assert_eq!(buf, [3, 5]);
+ /// ```
+ #[unstable(feature = "vec_retain_mut", issue = "90829")]
+ pub fn retain_mut<F>(&mut self, mut f: F)
+ where
+ F: FnMut(&mut T) -> bool,
{
let len = self.len();
let mut idx = 0;
// Stage 1: All values are retained.
while cur < len {
- if !f(&self[cur]) {
+ if !f(&mut self[cur]) {
cur += 1;
break;
}
}
// Stage 2: Swap retained value into current idx.
while cur < len {
- if !f(&self[cur]) {
+ if !f(&mut self[cur]) {
cur += 1;
continue;
}
cur += 1;
idx += 1;
}
- // Stage 3: Trancate all values after idx.
+ // Stage 3: Truncate all values after idx.
if cur != idx {
self.truncate(idx);
}
debug_assert!(!self.is_full());
}
- /// Modifies the `VecDeque` in-place so that `len()` is equal to `new_len`,
+ /// Modifies the deque in-place so that `len()` is equal to `new_len`,
/// either by removing excess elements from the back or by appending
/// elements generated by calling `generator` to the back.
///
///
/// Once the internal storage is contiguous, the [`as_slices`] and
/// [`as_mut_slices`] methods will return the entire contents of the
- /// `VecDeque` in a single slice.
+ /// deque in a single slice.
///
/// [`as_slices`]: VecDeque::as_slices
/// [`as_mut_slices`]: VecDeque::as_mut_slices
}
}
- /// Binary searches this sorted `VecDeque` for a given element.
+ /// Binary searches the sorted deque for a given element.
///
/// If the value is found then [`Result::Ok`] is returned, containing the
/// index of the matching element. If there are multiple matches, then any
/// ```
/// use std::collections::VecDeque;
///
- /// let deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
+ /// let deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
///
/// assert_eq!(deque.binary_search(&13), Ok(9));
/// assert_eq!(deque.binary_search(&4), Err(7));
/// assert!(matches!(r, Ok(1..=4)));
/// ```
///
- /// If you want to insert an item to a sorted `VecDeque`, while maintaining
+ /// If you want to insert an item to a sorted deque, while maintaining
/// sort order:
///
/// ```
/// use std::collections::VecDeque;
///
- /// let mut deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
+ /// let mut deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
/// let num = 42;
/// let idx = deque.binary_search(&num).unwrap_or_else(|x| x);
/// deque.insert(idx, num);
self.binary_search_by(|e| e.cmp(x))
}
- /// Binary searches this sorted `VecDeque` with a comparator function.
+ /// Binary searches the sorted deque with a comparator function.
///
/// The comparator function should implement an order consistent
- /// with the sort order of the underlying `VecDeque`, returning an
- /// order code that indicates whether its argument is `Less`,
- /// `Equal` or `Greater` than the desired target.
+ /// with the sort order of the deque, returning an order code that
+ /// indicates whether its argument is `Less`, `Equal` or `Greater`
+ /// than the desired target.
///
/// If the value is found then [`Result::Ok`] is returned, containing the
/// index of the matching element. If there are multiple matches, then any
/// ```
/// use std::collections::VecDeque;
///
- /// let deque: VecDeque<_> = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
+ /// let deque: VecDeque<_> = [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55].into();
///
/// assert_eq!(deque.binary_search_by(|x| x.cmp(&13)), Ok(9));
/// assert_eq!(deque.binary_search_by(|x| x.cmp(&4)), Err(7));
}
}
- /// Binary searches this sorted `VecDeque` with a key extraction function.
+ /// Binary searches the sorted deque with a key extraction function.
///
- /// Assumes that the `VecDeque` is sorted by the key, for instance with
+ /// Assumes that the deque is sorted by the key, for instance with
/// [`make_contiguous().sort_by_key()`] using the same key extraction function.
///
/// If the value is found then [`Result::Ok`] is returned, containing the
/// ```
/// use std::collections::VecDeque;
///
- /// let deque: VecDeque<_> = vec![(0, 0), (2, 1), (4, 1), (5, 1),
+ /// let deque: VecDeque<_> = [(0, 0), (2, 1), (4, 1), (5, 1),
/// (3, 1), (1, 2), (2, 3), (4, 5), (5, 8), (3, 13),
/// (1, 21), (2, 34), (4, 55)].into();
///
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
/// (all odd numbers are at the start, all even at the end).
///
- /// If this deque is not partitioned, the returned result is unspecified and meaningless,
+ /// If the deque is not partitioned, the returned result is unspecified and meaningless,
/// as this method performs a kind of binary search.
///
/// See also [`binary_search`], [`binary_search_by`], and [`binary_search_by_key`].
/// ```
/// use std::collections::VecDeque;
///
- /// let deque: VecDeque<_> = vec![1, 2, 3, 3, 5, 6, 7].into();
+ /// let deque: VecDeque<_> = [1, 2, 3, 3, 5, 6, 7].into();
/// let i = deque.partition_point(|&x| x < 5);
///
/// assert_eq!(i, 4);
}
impl<T: Clone, A: Allocator> VecDeque<T, A> {
- /// Modifies the `VecDeque` in-place so that `len()` is equal to new_len,
+ /// Modifies the deque in-place so that `len()` is equal to new_len,
/// either by removing excess elements from the back or by appending clones of `value`
/// to the back.
///
type Item = T;
type IntoIter = IntoIter<T, A>;
- /// Consumes the `VecDeque` into a front-to-back iterator yielding elements by
+ /// Consumes the deque into a front-to-back iterator yielding elements by
/// value.
fn into_iter(self) -> IntoIter<T, A> {
IntoIter::new(self)