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 <boost/container/flat_set.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
// Using boost flat set was faster than std::set.
|
// 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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Grid, typename Rules>
|
||||||
template <typename Field, typename Rules>
|
auto all_clusters(Grid const & grid, Rules const & rules){
|
||||||
auto all_clusters(Field const & field, Rules const & rules){
|
std::vector<decltype(cluster_at(grid, std::declval<typename Grid::Position>()))> ret;
|
||||||
boost::container::flat_set<decltype(cluster_at(field, std::declval<typename Field::Position>()))> ret;
|
|
||||||
ret.reserve(10);
|
ret.reserve(10);
|
||||||
for(auto&& p : field.all_positions()){
|
auto partition = make_empty(grid, grid.all_positions());
|
||||||
if(field.empty(p)) continue;
|
auto current_p = 1;
|
||||||
ret.insert(cluster_at(field, p));
|
for(auto&& p : partition.all_positions()){
|
||||||
}
|
if(!partition.empty(p) || grid.empty(p)) continue;
|
||||||
for(auto it = ret.begin(); it != ret.end();){
|
|
||||||
if (it->size() < rules.min_cluster_size()) it = ret.erase(it);
|
auto cluster = cluster_at(grid, p);
|
||||||
else ++it;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue