Commit 5cbe814e by Tobias Fuchs

algorithms_cpp: fixed cpplint warnings in MergeSort

parent 0f7719f9
...@@ -89,21 +89,21 @@ class MergeSortFunctor { ...@@ -89,21 +89,21 @@ class MergeSortFunctor {
task_l.Wait(MTAPI_INFINITE); task_l.Wait(MTAPI_INFINITE);
task_r.Wait(MTAPI_INFINITE); task_r.Wait(MTAPI_INFINITE);
ChunkDescriptor<RAI> chunk_f = partitioner_[chunk_first_]; ChunkDescriptor<RAI> ck_f = partitioner_[chunk_first_];
ChunkDescriptor<RAI> chunk_m = partitioner_[chunk_split_index + 1]; ChunkDescriptor<RAI> ck_m = partitioner_[chunk_split_index + 1];
ChunkDescriptor<RAI> chunk_l = partitioner_[chunk_last_]; ChunkDescriptor<RAI> ck_l = partitioner_[chunk_last_];
if(CloneBackToInput(depth_)) { if(CloneBackToInput(depth_)) {
// Merge from temp into input: // Merge from temp into input:
difference_type first = std::distance(global_first_, chunk_f.GetFirst()); difference_type first = std::distance(global_first_, ck_f.GetFirst());
difference_type mid = std::distance(global_first_, chunk_m.GetFirst()); difference_type mid = std::distance(global_first_, ck_m.GetFirst());
difference_type last = std::distance(global_first_, chunk_l.GetLast()); difference_type last = std::distance(global_first_, ck_l.GetLast());
SerialMerge(temp_first_ + first, temp_first_ + mid, temp_first_ + last, SerialMerge(temp_first_ + first, temp_first_ + mid, temp_first_ + last,
chunk_f.GetFirst(), ck_f.GetFirst(),
comparison_); comparison_);
} else { } else {
// Merge from input into temp: // Merge from input into temp:
SerialMerge(chunk_f.GetFirst(), chunk_m.GetFirst(), chunk_l.GetLast(), SerialMerge(ck_f.GetFirst(), ck_m.GetFirst(), ck_l.GetLast(),
temp_first_ + std::distance(global_first_, chunk_f.GetFirst()), temp_first_ + std::distance(global_first_, ck_f.GetFirst()),
comparison_); comparison_);
} }
} }
...@@ -129,31 +129,30 @@ class MergeSortFunctor { ...@@ -129,31 +129,30 @@ class MergeSortFunctor {
// Recurse further. Use binary split, ignoring chunk size as this // Recurse further. Use binary split, ignoring chunk size as this
// recursion is serial and has leaf size 1: // recursion is serial and has leaf size 1:
ChunkPartitioner<RAI> partitioner(first, last, 2); ChunkPartitioner<RAI> partitioner(first, last, 2);
ChunkDescriptor<RAI> chunk_l = partitioner[0]; ChunkDescriptor<RAI> ck_l = partitioner[0];
ChunkDescriptor<RAI> chunk_r = partitioner[1]; ChunkDescriptor<RAI> ck_r = partitioner[1];
MergeSortChunk( MergeSortChunk(
chunk_l.GetFirst(), ck_l.GetFirst(),
chunk_l.GetLast(), ck_l.GetLast(),
depth + 1); depth + 1);
MergeSortChunk( MergeSortChunk(
chunk_r.GetFirst(), ck_r.GetFirst(),
chunk_r.GetLast(), ck_r.GetLast(),
depth + 1); depth + 1);
if (CloneBackToInput(depth)) { if (CloneBackToInput(depth)) {
// Merge from temp into input: // Merge from temp into input:
difference_type d_first = std::distance(global_first_, chunk_l.GetFirst()); difference_type d_first = std::distance(global_first_, ck_l.GetFirst());
difference_type d_mid = std::distance(global_first_, chunk_r.GetFirst()); difference_type d_mid = std::distance(global_first_, ck_r.GetFirst());
difference_type d_last = std::distance(global_first_, chunk_r.GetLast()); difference_type d_last = std::distance(global_first_, ck_r.GetLast());
SerialMerge( SerialMerge(
temp_first_ + d_first, temp_first_ + d_mid, temp_first_ + d_last, temp_first_ + d_first, temp_first_ + d_mid, temp_first_ + d_last,
chunk_l.GetFirst(), ck_l.GetFirst(),
comparison_); comparison_);
} } else {
else {
// Merge from input into temp: // Merge from input into temp:
SerialMerge( SerialMerge(
chunk_l.GetFirst(), chunk_r.GetFirst(), chunk_r.GetLast(), ck_l.GetFirst(), ck_r.GetFirst(), ck_r.GetLast(),
temp_first_ + std::distance(global_first_, chunk_l.GetFirst()), temp_first_ + std::distance(global_first_, ck_l.GetFirst()),
comparison_); comparison_);
} }
} }
...@@ -226,7 +225,8 @@ void MergeSort( ...@@ -226,7 +225,8 @@ void MergeSort(
size_t block_size size_t block_size
) { ) {
typedef typename std::iterator_traits<RAI>::difference_type difference_type; typedef typename std::iterator_traits<RAI>::difference_type difference_type;
typedef internal::MergeSortFunctor<RAI, RAITemp, ComparisonFunction> functor_t; typedef internal::MergeSortFunctor<RAI, RAITemp, ComparisonFunction>
functor_t;
difference_type distance = std::distance(first, last); difference_type distance = std::distance(first, last);
if (distance == 0) { if (distance == 0) {
EMBB_THROW(embb::base::ErrorException, "Distance for ForEach is 0"); EMBB_THROW(embb::base::ErrorException, "Distance for ForEach is 0");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment