Skip to main content

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