/// <summary>
/// 两个vector求交集
/// </summary>
/// <returns></returns>
public:
template<typename T>
static auto
VectorIntersection(const std::vector<T> &firstVector, const std::vector<T> &secondVector) -> std::vector<T> {
std::vector<T> IntersectResult;
IntersectResult.resize(min(firstVector.size(), secondVector.size()));
typename std::vector<T>::iterator end = std::set_intersection(firstVector.begin(), firstVector.end(),
secondVector.begin(), secondVector.end(),
IntersectResult.begin());
IntersectResult.erase(end, IntersectResult.end());
return IntersectResult;
}
/// <summary>
/// 两个vector求并集
/// </summary>
/// <returns></returns>
public:
template<typename T>
static auto
VectorUnion(const std::vector<T> &firstVector, const std::vector<T> &secondVector) -> std::vector<T> {
std::vector<T> UnionResult{};
UnionResult.resize(firstVector.size() + secondVector.size());
typename std::vector<T>::iterator end = std::set_union(firstVector.begin(), firstVector.end(),
secondVector.begin(), secondVector.end(),
UnionResult.begin());
UnionResult.erase(end, UnionResult.end());
return UnionResult;
}
/// <summary>
/// 两个vector求差集
/// </summary>
/// <returns></returns>
public:
template<typename T>
static auto
VectorDifference(const std::vector<T> &firstVector, const std::vector<T> &secondVector) -> std::vector<T> {
std::vector<T> DifferenceResult{};
DifferenceResult.resize(firstVector.size());
typename std::vector<T>::iterator end = std::set_difference(firstVector.begin(), firstVector.end(),
secondVector.begin(), secondVector.end(),
DifferenceResult.begin());
DifferenceResult.erase(end, DifferenceResult.end());
return DifferenceResult;
}