29 template<
template<
typename,
typename...>
class ContainerType,
30 typename EleType,
typename... Types,
typename... OuterTypes>
31 void enum_permu(ContainerType<ContainerType<EleType, Types...>, OuterTypes...>& permutations,
32 ContainerType<EleType, Types...>& L,
33 ContainerType<EleType, Types...>& R)
37 permutations.emplace_back(R);
41 size_t size = L.size();
44 R.emplace_back(EleType{});
53 auto r_pop_back = [&R](
auto ptr) { R.pop_back(); };
55 using r_type_t = std::remove_reference_t<
decltype(R)>;
58 std::unique_ptr<r_type_t,
decltype(r_pop_back)>
59 clean_up(&R, r_pop_back);
61 for(
size_t i_th = 0; i_th < size; ++i_th)
67 copied_L.erase(copied_L.begin()+i_th);
78 template<
typename NRType>
82 using container_t = std::vector;
88 set_t L; L.reserve(n);
89 for(
size_t i = 0; i < (size_t)n; ++i)
92 set_t R; R.reserve(n);
102 template<
typename CallbackType,
template<
typename,
typename...>
class ContainerType,
103 typename EleType,
typename... Types>
105 ContainerType<EleType, Types...>& L, ContainerType<EleType, Types...>& R)
113 size_t size = L.size();
116 R.emplace_back(EleType{});
125 auto r_pop_back = [&R](
auto ptr) { R.pop_back(); };
127 using r_type_t = std::remove_reference_t<
decltype(R)>;
130 std::unique_ptr<r_type_t,
decltype(r_pop_back)>
131 clean_up(&R, r_pop_back);
133 for(
size_t i_th = 0; i_th < size; ++i_th)
139 copied_L.erase(copied_L.begin()+i_th);
145 enum_permu(std::forward<CallbackType>(callback), copied_L, R);
150 template<
typename CallbackType,
typename NRType>
154 using container_t = std::vector;
160 set_t L; L.reserve(n);
161 for(
size_t i = 0; i < (size_t)n; ++i)
164 set_t R; R.reserve(n);
166 enum_permu(std::forward<CallbackType>(callback), L, R);
170 template<
typename CallbackType,
template<
typename,
typename...>
class ContainerType,
171 typename EleType,
typename... Types>
173 ContainerType<EleType, Types...>& L, ContainerType<EleType, Types...>& R)
175 using set_t = ContainerType<EleType, Types...>;
183 size_t size = L.size();
186 R.emplace_back(EleType{});
195 auto r_pop_back = [&R](
auto ptr) { R.pop_back(); };
197 using r_type_t = std::remove_reference_t<
decltype(R)>;
200 std::unique_ptr<r_type_t,
decltype(r_pop_back)>
201 clean_up(&R, r_pop_back);
203 using future_t = std::future<void>;
204 using futures_t = std::vector<future_t>;
208 for(
size_t i_th = 0; i_th < size; ++i_th)
214 copied_L.erase(copied_L.begin()+i_th);
221 enum_permu(tb, std::forward<CallbackType>(callback), copied_L, R);
229 futures.emplace_back(std::async(std::launch::async,
go_parallel));
234 for(
auto& f: futures)
241 template<
typename CallbackType,
typename NRType>
245 using container_t = std::vector;
251 set_t L; L.reserve(n);
252 for(
size_t i = 0; i < (size_t)n; ++i)
255 set_t R; R.reserve(n);
257 enum_permu(tb, std::forward<CallbackType>(callback), L, R);
271 for(
auto& p: permutations)
278template<
typename ThreadFactorType>
288 auto callback_parallel = [&tb, &
output](
auto p)
292 std::unique_lock<std::mutex> lock(tb.mutex);
299 auto callback_sequential = [&
output](
auto p)
319int main(
int argc,
char* argv[])
323 auto factor = atoi(argv[1]);
324 auto n = atoi(argv[2]);
326 stream <<
"Using " <<
factor* std::thread::hardware_concurrency()
int main(int argc, char *argv[])
void performance_test_build_permutations(ThreadFactorType factor, int n)
void test_build_permutations(int n)
void go_parallel(Policy &&policy, IteratorBegin &&begin, IteratorEnd &&end, Callback &&callback)
std::deque< element_t > set_t
std::deque< set_t > sets_t
std::string elapsed_time(bool bReset=true, TimeUnit dummy_time=TimeUnit{}) const
Implements random number generator and stop watch.
enable_if_all_in_list_t< types::type_list_t< Type1, Type2 >, integral_list_t, ReturnType > npr(Type1 nn, Type2 rr)
Stream output operators are defined.
Implements set operations.
Type to string name conversions are defined.
typename SetTagType::set_t set_t
typename SetTagType::sets_t sets_t
auto build_permutations(NRType n)
void enum_permu(ContainerType< ContainerType< EleType, Types... >, OuterTypes... > &permutations, ContainerType< EleType, Types... > &L, ContainerType< EleType, Types... > &R)
std::atomic< int > current_thread_count
Stream output operators << are implemented.
Implements set operations.