Small improvement in speed
This commit is contained in:
parent
6d2696973f
commit
5077d7e966
1 changed files with 17 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
|
||||
// Using boost flat set was faster than std::set.
|
||||
|
||||
|
@ -41,18 +42,23 @@ auto cluster_at(Field const & field, typename Field::Position const & p){
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template <typename Field, typename Rules>
|
||||
auto all_clusters(Field const & field, Rules const & rules){
|
||||
boost::container::flat_set<decltype(cluster_at(field, std::declval<typename Field::Position>()))> ret;
|
||||
template <typename Grid, typename Rules>
|
||||
auto all_clusters(Grid const & grid, Rules const & rules){
|
||||
std::vector<decltype(cluster_at(grid, std::declval<typename Grid::Position>()))> ret;
|
||||
ret.reserve(10);
|
||||
for(auto&& p : field.all_positions()){
|
||||
if(field.empty(p)) continue;
|
||||
ret.insert(cluster_at(field, p));
|
||||
}
|
||||
for(auto it = ret.begin(); it != ret.end();){
|
||||
if (it->size() < rules.min_cluster_size()) it = ret.erase(it);
|
||||
else ++it;
|
||||
auto partition = make_empty(grid, grid.all_positions());
|
||||
auto current_p = 1;
|
||||
for(auto&& p : partition.all_positions()){
|
||||
if(!partition.empty(p) || grid.empty(p)) continue;
|
||||
|
||||
auto cluster = cluster_at(grid, p);
|
||||
for(auto&& q : cluster){
|
||||
partition.get(q) = current_p;
|
||||
}
|
||||
|
||||
current_p++;
|
||||
if(cluster.size() >= rules.min_cluster_size()) ret.push_back(std::move(cluster));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Reference in a new issue