| 2871 | */ |
| 2872 | template <class DataType> |
| 2873 | void QCPDataContainer<DataType>::add(const QCPDataContainer<DataType> &data) |
| 2874 | { |
| 2875 | if (data.isEmpty()) |
| 2876 | return; |
| 2877 | |
| 2878 | const int n = data.size(); |
| 2879 | const int oldSize = size(); |
| 2880 | |
| 2881 | if (oldSize > 0 && !qcpLessThanSortKey<DataType>(*constBegin(), *(data.constEnd()-1))) // prepend if new data keys are all smaller than or equal to existing ones |
| 2882 | { |
| 2883 | if (mPreallocSize < n) |
| 2884 | preallocateGrow(n); |
| 2885 | mPreallocSize -= n; |
| 2886 | std::copy(data.constBegin(), data.constEnd(), begin()); |
| 2887 | } else // don't need to prepend, so append and merge if necessary |
| 2888 | { |
| 2889 | mData.resize(mData.size()+n); |
| 2890 | std::copy(data.constBegin(), data.constEnd(), end()-n); |
| 2891 | if (oldSize > 0 && !qcpLessThanSortKey<DataType>(*(constEnd()-n-1), *(constEnd()-n))) // if appended range keys aren't all greater than existing ones, merge the two partitions |
| 2892 | std::inplace_merge(begin(), end()-n, end(), qcpLessThanSortKey<DataType>); |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | /*! |
| 2897 | Adds the provided data points in \a data to the current data. |