File indexing completed on 2026-06-02 08:51:49
0001 #ifndef VECTOR_UTILS_H
0002 #define VECTOR_UTILS_H
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <algorithm>
0012 #include <vector>
0013
0014 #include "../beans/List.h"
0015
0016 namespace PARTONS {
0017
0018
0019
0020
0021
0022 class VectorUtils {
0023 public:
0024
0025
0026 template<typename T>
0027 static std::vector<T> intersection(std::vector<T> & lhs,
0028 std::vector<T> & rhs) {
0029 std::vector<T> result;
0030
0031 std::sort(lhs.begin(), lhs.end());
0032 std::sort(rhs.begin(), rhs.end());
0033
0034 std::set_intersection(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
0035 std::back_inserter(result));
0036
0037 return result;
0038 }
0039
0040 template<typename T>
0041 static List<T> intersection(const List<T> & lhs, const List<T> & rhs) {
0042 std::vector<T> result;
0043
0044 std::vector<T> lhsData = lhs.getData();
0045 std::vector<T> rhsData = rhs.getData();
0046
0047 std::sort(lhsData.begin(), lhsData.end());
0048 std::sort(rhsData.begin(), rhsData.end());
0049
0050 std::set_intersection(lhsData.begin(), lhsData.end(), rhsData.begin(),
0051 rhsData.end(), std::back_inserter(result));
0052
0053 return List<T>(result);
0054 }
0055 };
0056
0057 }
0058
0059 #endif