Skip to main content

malachite_base/unsigned_vector/
extend.rs

1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::num::basic::unsigneds::PrimitiveUnsigned;
10use crate::unsigned_vector::UnsignedVector;
11
12impl<T: PrimitiveUnsigned> Extend<T> for UnsignedVector<T> {
13    /// Appends the elements produced by an iterator to the end of an [`UnsignedVector`], increasing
14    /// its dimension by their number.
15    ///
16    /// # Worst-case complexity
17    /// $T(n) = O(n)$
18    ///
19    /// $M(n) = O(n)$
20    ///
21    /// where $T$ is time, $M$ is additional memory, and $n$ is `self.dimension()` plus the number
22    /// of elements produced, not counting the cost of producing them.
23    ///
24    /// # Examples
25    /// ```
26    /// use core::str::FromStr;
27    /// use malachite_base::unsigned_vector::UnsignedVector;
28    ///
29    /// let mut v = UnsignedVector::<u8>::from_str("(1, 2)").unwrap();
30    /// v.extend([3, 4]);
31    /// assert_eq!(v.to_string(), "(1, 2, 3, 4)");
32    /// ```
33    #[inline]
34    fn extend<I: IntoIterator<Item = T>>(&mut self, xs: I) {
35        self.elements.extend(xs);
36    }
37}