jak-project/common/util/set_util.h
Tyler Wilding 6aa15c897f
decomp: don't mutate allowed/banned object lists (#2073)
oops, leads to some very confusing behaviour
2022-12-30 23:57:01 -05:00

23 lines
483 B
C++

#pragma once
#include <unordered_set>
namespace set_util {
template <typename T>
std::unordered_set<T> intersection(std::unordered_set<T> set1, std::unordered_set<T> set2) {
if (set2.size() < set1.size()) {
auto temp = set1;
set1 = set2;
set2 = temp;
}
std::unordered_set<T> m(set1.begin(), set1.end());
std::unordered_set<T> res;
for (auto a : set2)
if (m.count(a)) {
res.insert(a);
m.erase(a);
}
return res;
}
} // namespace set_util