Skip to main content

malachite_nz/integer_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::integer::Integer;
10use crate::integer_vector::IntegerVector;
11
12impl Extend<Integer> for IntegerVector {
13    /// Appends the elements produced by an iterator to the end of an [`IntegerVector`], 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_nz::integer::Integer;
28    /// use malachite_nz::integer_vector::IntegerVector;
29    ///
30    /// let mut v = IntegerVector::from_str("(1, 2)").unwrap();
31    /// v.extend([-3, 4].map(Integer::from));
32    /// assert_eq!(v.to_string(), "(1, 2, -3, 4)");
33    /// ```
34    #[inline]
35    fn extend<I: IntoIterator<Item = Integer>>(&mut self, xs: I) {
36        self.elements.extend(xs);
37    }
38}