↰ Return to documentation for file (include/networkit/structures/Cover.hpp)
/*
* Cover.hpp
*
* Created on: 03.10.2013
* Author: cls
*/
#ifndef NETWORKIT_STRUCTURES_COVER_HPP_
#define NETWORKIT_STRUCTURES_COVER_HPP_
#include <map>
#include <set>
#include <vector>
#include <networkit/Globals.hpp>
#include <networkit/structures/GenericPartition.hpp>
namespace NetworKit {
template <IntegralValue IndexType>
class GenericCover final {
public:
GenericCover();
GenericCover(IndexType z);
GenericCover(const GenericPartition<IndexType> &p);
inline std::set<IndexType> &operator[](const IndexType &e) { return this->data[e]; }
inline const std::set<IndexType> &operator[](const IndexType &e) const { return this->data[e]; }
inline std::set<IndexType> subsetsOf(IndexType e) const {
// TODO: assert (e < this->numberOfElements());
return this->data[e];
}
bool contains(IndexType e) const;
bool inSameSubset(IndexType e1, IndexType e2) const;
std::set<IndexType> getMembers(IndexType s) const;
void addToSubset(IndexType s, IndexType e);
void removeFromSubset(IndexType s, IndexType e);
void moveToSubset(IndexType s, IndexType e);
IndexType toSingleton(IndexType e);
void allToSingletons();
void mergeSubsets(IndexType s, IndexType t);
IndexType upperBound() const;
IndexType lowerBound() const;
std::vector<count> subsetSizes() const;
std::map<IndexType, count> subsetSizeMap() const;
count numberOfSubsets() const;
count numberOfElements() const;
IndexType extend();
std::set<IndexType> getSubsetIds() const;
void setUpperBound(IndexType upper);
template <typename Callback>
void forEntries(Callback func) const;
template <typename Callback>
void parallelForEntries(Callback handle) const;
private:
IndexType z;
IndexType omega;
std::vector<std::set<IndexType>> data;
inline IndexType newSubsetId() {
++omega;
IndexType s = omega;
return s;
}
};
template <IntegralValue IndexType>
template <typename Callback>
inline void GenericCover<IndexType>::forEntries(Callback handle) const {
for (IndexType e = 0; e <= this->z; e += 1) {
handle(e, data[e]);
}
}
template <IntegralValue IndexType>
template <typename Callback>
inline void GenericCover<IndexType>::parallelForEntries(Callback handle) const {
#pragma omp parallel for
for (omp_index e = 0; e <= static_cast<omp_index>(this->z); e += 1) {
handle(static_cast<IndexType>(e), data[static_cast<IndexType>(e)]);
}
}
using Cover = GenericCover<index>;
} /* namespace NetworKit */
#include <networkit/structures/CoverImpl.hpp>
#endif // NETWORKIT_STRUCTURES_COVER_HPP_