Run clang-format
This commit is contained in:
@@ -1,45 +1,45 @@
|
||||
template<typename Iterator,typename MatchType>
|
||||
Iterator parallel_find_impl(Iterator first,Iterator last,MatchType match,
|
||||
std::atomic<bool>& done)
|
||||
template <typename Iterator, typename MatchType>
|
||||
Iterator
|
||||
parallel_find_impl(Iterator first,
|
||||
Iterator last,
|
||||
MatchType match,
|
||||
std::atomic<bool>& done)
|
||||
{
|
||||
try
|
||||
{
|
||||
unsigned long const length=std::distance(first,last);
|
||||
unsigned long const min_per_thread=25;
|
||||
if(length<(2*min_per_thread))
|
||||
{
|
||||
for(;(first!=last) && !done.load();++first)
|
||||
{
|
||||
if(*first==match)
|
||||
{
|
||||
done=true;
|
||||
return first;
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
else
|
||||
{
|
||||
Iterator const mid_point=first+(length/2);
|
||||
std::future<Iterator> async_result=
|
||||
std::async(¶llel_find_impl<Iterator,MatchType>,
|
||||
mid_point,last,match,std::ref(done));
|
||||
Iterator const direct_result=
|
||||
parallel_find_impl(first,mid_point,match,done);
|
||||
return (direct_result==mid_point)?
|
||||
async_result.get():direct_result;
|
||||
try {
|
||||
unsigned long const length = std::distance(first, last);
|
||||
unsigned long const min_per_thread = 25;
|
||||
if (length < (2 * min_per_thread)) {
|
||||
for (; (first != last) && !done.load(); ++first) {
|
||||
if (*first == match) {
|
||||
done = true;
|
||||
return first;
|
||||
}
|
||||
}
|
||||
return last;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
done=true;
|
||||
throw;
|
||||
else {
|
||||
Iterator const mid_point = first + (length / 2);
|
||||
std::future<Iterator> async_result =
|
||||
std::async(¶llel_find_impl<Iterator, MatchType>,
|
||||
mid_point,
|
||||
last,
|
||||
match,
|
||||
std::ref(done));
|
||||
Iterator const direct_result =
|
||||
parallel_find_impl(first, mid_point, match, done);
|
||||
return (direct_result == mid_point) ? async_result.get() : direct_result;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
done = true;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Iterator,typename MatchType>
|
||||
Iterator parallel_find(Iterator first,Iterator last,MatchType match)
|
||||
template <typename Iterator, typename MatchType>
|
||||
Iterator
|
||||
parallel_find(Iterator first, Iterator last, MatchType match)
|
||||
{
|
||||
std::atomic<bool> done(false);
|
||||
return parallel_find_impl(first,last,match,done);
|
||||
std::atomic<bool> done(false);
|
||||
return parallel_find_impl(first, last, match, done);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user