↰ Return to documentation for file (include/networkit/auxiliary/SetIntersector.hpp
)
/*
* SetIntersector.hpp
*
* Created on: 14.05.2014
* Author: Henning
*/
#ifndef NETWORKIT_AUXILIARY_SET_INTERSECTOR_HPP_
#define NETWORKIT_AUXILIARY_SET_INTERSECTOR_HPP_
#include <cstdint>
#include <set>
#include <span>
#include <vector>
namespace Aux {
template <class T>
class SetIntersector {
public:
SetIntersector(T upperBound);
std::set<T> intersect(std::span<const T> A, std::span<const T> B);
private:
std::vector<bool> bv;
uint64_t n;
};
} // namespace Aux
template <class T>
inline Aux::SetIntersector<T>::SetIntersector(T upperBound) : n(upperBound) {
bv.resize(n, false);
}
template <class T>
inline std::set<T> Aux::SetIntersector<T>::intersect(std::span<const T> A, std::span<const T> B) {
std::span<const T> smaller = (A.size() <= B.size()) ? A : B;
std::span<const T> larger = (A.size() <= B.size()) ? B : A;
for (auto entry : smaller) {
bv[entry] = true;
}
std::set<T> result;
for (auto entry : larger) {
if (bv[entry]) {
result.insert(entry);
}
}
for (auto entry : smaller) {
bv[entry] = false;
}
return result;
}
#endif // NETWORKIT_AUXILIARY_SET_INTERSECTOR_HPP_