From d62e1fd90931ee50c22620a935bc1534551a8170 Mon Sep 17 00:00:00 2001 From: Francisco Tapia Date: Tue, 27 Feb 2024 20:23:31 +0100 Subject: [PATCH 01/21] adding support -fno-exception --- .vscode/settings.json | 5 + benchmark/parallel/benchmark_numbers.cpp | 244 ++++--- benchmark/parallel/benchmark_objects.cpp | 608 ++++++++---------- benchmark/parallel/benchmark_strings.cpp | 316 ++++----- benchmark/parallel/file_generator.cpp | 6 +- .../parallel/runCLANG_benchmark_numbers.sh | 4 +- .../parallel/runCLANG_benchmark_objects.sh | 4 +- .../parallel/runCLANG_benchmark_strings.sh | 4 +- .../parallel/runGCC_benchmark_numbers.sh | 4 +- .../parallel/runGCC_benchmark_objects.sh | 4 +- .../parallel/runGCC_benchmark_strings.sh | 4 +- benchmark/single/benchmark_numbers.cpp | 196 +++--- benchmark/single/benchmark_objects.cpp | 547 ++++++++-------- benchmark/single/benchmark_strings.cpp | 326 +++++----- benchmark/single/file_generator.cpp | 6 +- .../single/runCLANG_benchmark_numbers.sh | 4 +- .../single/runCLANG_benchmark_objects.sh | 4 +- .../single/runCLANG_benchmark_strings.sh | 4 +- benchmark/single/runGCC_benchmark_numbers.sh | 4 +- benchmark/single/runGCC_benchmark_objects.sh | 4 +- benchmark/single/runGCC_benchmark_strings.sh | 4 +- include/boost/sort/common/indirect.hpp | 2 +- include/boost/sort/common/merge_block.hpp | 27 +- include/boost/sort/common/range.hpp | 5 +- include/boost/sort/common/rearrange.hpp | 3 +- include/boost/sort/common/sort_basic.hpp | 19 +- include/boost/sort/common/util/merge.hpp | 43 +- .../flat_stable_sort/flat_stable_sort.hpp | 27 +- .../boost/sort/insert_sort/insert_sort.hpp | 3 +- 29 files changed, 1209 insertions(+), 1222 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ef83f48 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "develop" + ] +} \ No newline at end of file diff --git a/benchmark/parallel/benchmark_numbers.cpp b/benchmark/parallel/benchmark_numbers.cpp index edf139b..5883ca4 100644 --- a/benchmark/parallel/benchmark_numbers.cpp +++ b/benchmark/parallel/benchmark_numbers.cpp @@ -50,8 +50,7 @@ void Generator_reverse_sorted (void); void Generator_reverse_sorted_end (size_t n_last); void Generator_reverse_sorted_middle (size_t n_last); -template -int Test (std::vector &B, compare comp = compare ()); +void Test (std::vector &B); int main (int argc, char *argv[]) { @@ -66,205 +65,203 @@ int main (int argc, char *argv[]) cout << "************************************************************\n"; cout << std::endl; - cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; - cout<<"[ 3 ] parallel_stable_sort\n\n"; - cout<<" | | | |\n"; - cout<<" | [ 1 ]| [ 2 ]| [ 3 ]|\n"; - cout<<"--------------------+------+------+------+\n"; + cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; + cout << "[ 3 ] parallel_stable_sort\n\n"; + cout << " | | | |\n"; + cout << " | [ 1 ]| [ 2 ]| [ 3 ]|\n"; + cout << "--------------------+------+------+------+\n"; std::string empty_line = " | | | |\n"; - cout<<"random |"; + cout << "random |"; Generator_random (); - cout< A; + vector A; A.reserve (NELEM); A.clear (); if (fill_vector_uint64 ("input.bin", A, NELEM) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - Test> (A); -} -; -void -Generator_sorted (void) + Test (A); +}; +void Generator_sorted (void) { - vector A; - + std::vector A; A.reserve (NELEM); A.clear (); - for (size_t i = 0; i < NELEM; ++i) + for (uint64_t i = 0; i < NELEM; ++i) A.push_back (i); - Test> (A); - -} - -void Generator_sorted_end (size_t n_last) + Test (A); +}; +void Generator_sorted_end (uint64_t n_last) { - vector A; + std::vector A; A.reserve (NELEM); A.clear (); if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; std::sort (A.begin (), A.begin () + NELEM); - - Test> (A); - -} -; -void Generator_sorted_middle (size_t n_last) + Test (A); +}; +void Generator_sorted_middle (uint64_t n_middle) { - vector A, B, C; - A.reserve (NELEM); - A.clear (); - if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) + assert (n_middle > 1 && NELEM >= (n_middle -1)); + std::vector A, aux; + A.reserve (NELEM + n_middle); + aux.reserve (n_middle); + + if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for (size_t i = NELEM; i < A.size (); ++i) - B.push_back (std::move (A[i])); - A.resize ( NELEM); - for (size_t i = 0; i < (NELEM >> 1); ++i) - std::swap (A[i], A[NELEM - 1 - i]); - - std::sort (A.begin (), A.end ()); - size_t step = NELEM / n_last + 1; - size_t pos = 0; - - for (size_t i = 0; i < B.size (); ++i, pos += step) + for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]); + + std::sort (A.begin () + n_middle, A.end ()); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + uint64_t step = NELEM / (n_middle - 1); + A [0] = aux [0]; + uint64_t pos_read = n_middle, pos_write = 1; + + for (uint64_t i = 1; i < n_middle; ++i) { - C.push_back (B[i]); - for (size_t k = 0; k < step; ++k) - C.push_back (A[pos + k]); + for (uint64_t k = 0 ; k < step; ++k) + A [pos_write ++] = A [pos_read ++]; + A [pos_write ++] = aux [i]; }; - while (pos < A.size ()) - C.push_back (A[pos++]); - A = C; - Test> (A); -} -; + aux.clear (); + aux.reserve (0); + Test (A); +}; void Generator_reverse_sorted (void) { - vector A; - + std::vector A; A.reserve (NELEM); A.clear (); - for (size_t i = NELEM; i > 0; --i) + for (uint64_t i = NELEM; i > 0; --i) A.push_back (i); - Test> (A); -} -void Generator_reverse_sorted_end (size_t n_last) + Test (A); +}; +void Generator_reverse_sorted_end (uint64_t n_last) { - vector A; + std::vector A; A.reserve (NELEM); A.clear (); if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; std::sort (A.begin (), A.begin () + NELEM); - for (size_t i = 0; i < (NELEM >> 1); ++i) - std::swap (A[i], A[NELEM - 1 - i]); + for (uint64_t i = 0; i < (NELEM >> 1); ++i) + std::swap (A [i], A [NELEM - 1 - i]); - Test> (A); + Test (A); } -void Generator_reverse_sorted_middle (size_t n_last) +void Generator_reverse_sorted_middle (uint64_t n_middle) { - vector A, B, C; - A.reserve (NELEM); - A.clear (); - if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) + assert (n_middle > 1 && NELEM >= (n_middle -1)); + std::vector A, aux; + A.reserve (NELEM + n_middle); + aux.reserve (n_middle); + + if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for (size_t i = NELEM; i < A.size (); ++i) - B.push_back (std::move (A[i])); - A.resize ( NELEM); - for (size_t i = 0; i < (NELEM >> 1); ++i) - std::swap (A[i], A[NELEM - 1 - i]); - - std::sort (A.begin (), A.end ()); - size_t step = NELEM / n_last + 1; - size_t pos = 0; - - for (size_t i = 0; i < B.size (); ++i, pos += step) + for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]); + + std::sort (A.begin () + n_middle, A.end ()); + uint64_t pos1 = n_middle, pos2 = A.size () - 1; + for (uint64_t i = 0; i < (NELEM >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + uint64_t step = NELEM / (n_middle - 1); + A [0] = aux [0]; + uint64_t pos_read = n_middle, pos_write = 1; + + for (uint64_t i = 1; i < n_middle; ++i) { - C.push_back (B[i]); - for (size_t k = 0; k < step; ++k) - C.push_back (A[pos + k]); + for (uint64_t k = 0 ; k < step; ++k) + A [pos_write ++] = A [pos_read ++]; + A [pos_write ++] = aux [i]; }; - while (pos < A.size ()) - C.push_back (A[pos++]); - A = C; - Test> (A); + aux.clear (); + aux.reserve (0); + Test (A); }; - -template -int Test (std::vector &B, compare comp) -{ //---------------------------- begin -------------------------------- +void Test (std::vector &B) +{ + //---------------------------- begin -------------------------------- + std::less comp ; double duration; time_point start, finish; - std::vector A (B); - std::vector V; + std::vector A (B); + std::vector V; //-------------------------------------------------------------------- A = B; @@ -291,11 +288,10 @@ int Test (std::vector &B, compare comp) //----------------------------------------------------------------------- // printing the vector //----------------------------------------------------------------------- - std::cout< #include #include "boost/sort/common/int_array.hpp" - #include -#define NELEM 100000000 -#define NMAXSTRING 10000000 - using namespace std; namespace bsc = boost::sort::common; namespace bsp = boost::sort; @@ -45,52 +41,38 @@ using bsc::int_array; using bsc::H_comp; using bsc::L_comp; - - template -void Generator_random(uint64_t N); +void Generator_random (uint64_t N); template -void Generator_sorted(uint64_t N); -template -void Generator_sorted_end(uint64_t N, size_t n_last ); +void Generator_sorted (uint64_t N); template -void Generator_sorted_middle(uint64_t N, size_t n_last ); +void Generator_sorted_end (uint64_t N, size_t n_last); template -void Generator_reverse_sorted(uint64_t N); +void Generator_sorted_middle (uint64_t N, size_t n_middle); template -void Generator_reverse_sorted_end(uint64_t N, size_t n_last ); +void Generator_reverse_sorted (uint64_t N); template -void Generator_reverse_sorted_middle(uint64_t N, size_t n_last ); - -template < class IA > -struct H_rightshift { - inline uint64_t operator()(const IA& A1, unsigned offset) { - return A1.counter() >> offset; - } -}; +void Generator_reverse_sorted_end (uint64_t N, size_t n_last); -template < class IA > -struct L_rightshift { - inline uint64_t operator()(const IA& A1, unsigned offset) { - return A1.M[0] >> offset; - } -}; +template +void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle); -template -int Test(std::vector &B, rightshift shift, compare comp, std::vector & V ); +template +void Test (std::vector &B, compare comp, std::vector & V ); template -void Test_size ( uint64_t N); +void Test_size (uint64_t N); -void Print_vectors ( std::vector & V1, std::vector & V2); +void Print_vectors (std::vector &V1, std::vector & V2); int main(int argc, char *argv[]) { + const uint64_t NELEM = 100000000; cout << "\n\n"; cout << "************************************************************\n"; cout << "** **\n"; @@ -172,320 +154,349 @@ int main(int argc, char *argv[]) template void Test_size ( uint64_t N) { - cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; - cout<<"[ 3 ] parallel_stable_sort\n\n"; + cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; + cout << "[ 3 ] parallel_stable_sort\n\n"; cout << " | [ 1 ] | [ 2 ] | [ 3 ] |\n"; cout << " | H L | H L | H L |\n"; cout << "--------------------+-----------+-----------+-----------+\n"; std::string empty_line = " | | | |\n"; - cout<<"random |"; - Generator_random(N); + cout << "random |"; + Generator_random (N); - cout<(N); + cout << empty_line; + cout << "sorted |"; + Generator_sorted (N); - cout<<"sorted + 0.1% end |"; - Generator_sorted_end(N, N / 1000); + cout << "sorted + 0.1% end |"; + Generator_sorted_end (N, N / 1000); - cout<<"sorted + 1% end |"; - Generator_sorted_end(N, N / 100); + cout << "sorted + 1% end |"; + Generator_sorted_end< IA> (N, N / 100); - cout<<"sorted + 10% end |"; - Generator_sorted_end(N, N / 10); + cout << "sorted + 10% end |"; + Generator_sorted_end (N, N / 10); - cout<(N, N / 1000); + cout << empty_line; + cout << "sorted + 0.1% mid |"; + Generator_sorted_middle (N, N / 1000); - cout<<"sorted + 1% mid |"; - Generator_sorted_middle(N, N / 100); + cout << "sorted + 1% mid |"; + Generator_sorted_middle (N, N / 100); - cout<<"sorted + 10% mid |"; - Generator_sorted_middle(N, N / 10); + cout << "sorted + 10% mid |"; + Generator_sorted_middle (N, N / 10); - cout<(N); + cout << empty_line; + cout << "reverse sorted |"; + Generator_reverse_sorted (N); - cout<<"rv sorted + 0.1% end|"; - Generator_reverse_sorted_end(N, N / 1000); + cout << "rv sorted + 0.1% end|"; + Generator_reverse_sorted_end (N, N / 1000); - cout<<"rv sorted + 1% end|"; - Generator_reverse_sorted_end(N, N / 100); + cout << "rv sorted + 1% end|"; + Generator_reverse_sorted_end (N, N / 100); - cout<<"rv sorted + 10% end|"; - Generator_reverse_sorted_end(N, N / 10); + cout << "rv sorted + 10% end|"; + Generator_reverse_sorted_end (N, N / 10); - cout<(N, N / 1000); + cout << empty_line; + cout << "rv sorted + 0.1% mid|"; + Generator_reverse_sorted_middle (N, N / 1000); - cout<<"rv sorted + 1% mid|"; - Generator_reverse_sorted_middle(N, N / 100); + cout << "rv sorted + 1% mid|"; + Generator_reverse_sorted_middle (N, N / 100); - cout<<"rv sorted + 10% mid|"; - Generator_reverse_sorted_middle(N, N / 10); - cout<< "--------------------+-----------+-----------+-----------+\n"; - cout< (N, N / 10); + cout << "--------------------+-----------+-----------+-----------+\n"; + cout << endl << endl << endl; } void Print_vectors ( std::vector & V1, std::vector & V2) { assert ( V1.size() == V2.size()); - std::cout< -void Generator_random(uint64_t N) +void Generator_random (uint64_t N) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; - - gen.reset(); - A.clear(); - for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); - - Test(A, H_rightshift(), H_comp(), V1); - - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; + + gen.reset (); + A.clear (); + for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate(gen)); + + Test (A, H_comp (), V1); + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; + template void Generator_sorted(uint64_t N) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; - gen.reset(); - A.clear(); - for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); + gen.reset (); + A.clear (); + for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen)); - std::sort( A.begin() , A.end(),H_comp() ); - Test(A, H_rightshift(), H_comp(), V1); + std::sort (A.begin (), A.end (), H_comp ()); + Test (A, H_comp (), V1); - std::sort( A.begin() , A.end(),L_comp() ); - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + std::sort (A.begin (), A.end (), L_comp ()); + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; template -void Generator_sorted_end(uint64_t N, size_t n_last ) +void Generator_sorted_end (uint64_t N, size_t n_last ) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; - gen.reset(); - A.clear(); + gen.reset (); + A.clear (); for (uint32_t i = 0; i < (N + n_last); i++) - A.emplace_back(IA::generate(gen)); - std::sort ( A.begin() , A.begin() + N ,H_comp()); + A.emplace_back (IA::generate (gen)); + + std::sort (A.begin (), A.begin () + N, H_comp ()); - Test(A, H_rightshift(), H_comp(),V1); - std::sort ( A.begin() , A.begin() + N ,L_comp()); + Test (A, H_comp (), V1); + std::sort (A.begin (), A.begin () + N, L_comp ()); - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; template -void Generator_sorted_middle(uint64_t N, size_t n_last ) +void Generator_sorted_middle (uint64_t N, size_t n_middle ) { - bsc::uint64_file_generator gen("input.bin"); - std::vector V1, V2 ; - vector A; - A.reserve(N + n_last); - - { A.clear() ; - gen.reset(); - vector B, C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); - - std::sort ( C.begin() , C.end() ,H_comp()); - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + assert (n_middle > 1 && N >= (n_middle -1)); + bsc::uint64_file_generator gen ("input.bin"); + + std::vector V1, V2; // vector with the times used + vector A, aux; + A.reserve (N + n_middle); + aux.reserve (n_middle); + + //----------------------------------------------------------------------- + // H _ C O M P + //----------------------------------------------------------------------- + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), H_comp ()); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, H_rightshift(), H_comp(), V1); - - { A.clear() ; - gen.reset(); - vector B,C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); + Test (A, H_comp (), V1); - C.resize ( N); - - std::sort ( C.begin() , C.end() ,L_comp()); - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + //---------------------------------------------------------------------- + // L _ C O M P + //----------------------------------------------------------------------- + gen.reset (); + A.clear (); + A.reserve (N + n_middle); + aux.clear (); + aux.reserve (n_middle); + + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), L_comp ()); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + pos_read = n_middle; + pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; template -void Generator_reverse_sorted(uint64_t N) +void Generator_reverse_sorted (uint64_t N) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; - - gen.reset(); - A.clear(); - for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); - - std::sort( A.begin() , A.end(),H_comp() ); - for ( size_t i = 0; i < (A.size() >>1) ; ++i) - std::swap ( A[i], A[A.size() - i -1 ]); - - Test(A, H_rightshift(), H_comp(), V1); - - std::sort( A.begin() , A.end(),L_comp() ); - for ( size_t i = 0; i < (A.size() >>1) ; ++i) - std::swap ( A[i], A[A.size() - i -1 ]); - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; + + gen.reset (); + A.clear (); + for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen)); + + std::sort (A.begin (), A.end (), H_comp ()); + for (size_t i = 0; i < (A.size () >>1); ++i) + std::swap (A [i], A [A.size () - i - 1]); + + Test (A, H_comp (), V1); + + std::sort (A.begin (), A.end (), L_comp ()); + for (size_t i = 0; i < (A.size () >> 1); ++i) + std::swap (A [i], A [A.size() - i - 1]); + + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; + template -void Generator_reverse_sorted_end(uint64_t N, size_t n_last ) +void Generator_reverse_sorted_end (uint64_t N, size_t n_last ) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; - gen.reset(); - A.clear(); + gen.reset (); + A.clear (); for (uint32_t i = 0; i < (N + n_last); i++) - A.emplace_back(IA::generate(gen)); - std::sort ( A.begin() , A.begin() + N ,H_comp()); - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( A[i], A[N-1-i]); - - Test(A, H_rightshift(), H_comp(), V1); - std::sort ( A.begin() , A.begin() + N ,L_comp()); - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( A[i], A[N-1-i]); - - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + A.emplace_back (IA::generate (gen)); + + std::sort (A.begin (), A.begin () + N , H_comp ()); + for (size_t i =0 ; i < (N >> 1); ++i) + std::swap (A [i], A [N - 1 - i]); + + Test (A, H_comp (), V1); + std::sort (A.begin (), A.begin () + N, L_comp ()); + for (size_t i = 0; i < (N >> 1); ++i) + std::swap (A [i], A [N - 1 - i]); + + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; + template -void Generator_reverse_sorted_middle(uint64_t N, size_t n_last ) +void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle ) { - bsc::uint64_file_generator gen("input.bin"); - std::vector V1, V2 ; - vector A; - A.reserve(N + n_last); - - { A.clear() ; - gen.reset(); - vector B,C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); - - std::sort ( C.begin() , C.end() ,H_comp()); - - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( C[i], C[N-1-i]); - - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++ ] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + assert (n_middle > 1 && N >= (n_middle -1)); + bsc::uint64_file_generator gen ("input.bin"); + + std::vector V1, V2; // vector with the times used + vector A, aux; + A.reserve (N + n_middle); + aux.reserve (n_middle); + + //----------------------------------------------------------------------- + // H _ C O M P + //----------------------------------------------------------------------- + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), H_comp ()); + uint64_t pos1 = n_middle, pos2 = A.size () - 1; + for (uint64_t i = 0; i < (N >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, H_rightshift(), H_comp(), V1); + Test (A, H_comp (), V1); - { A.clear() ; - gen.reset(); - vector B,C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); - - std::sort ( C.begin() , C.end() ,L_comp()); - - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( C[i], C[N-1-i]); - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++ ] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + //---------------------------------------------------------------------- + // L _ C O M P + //----------------------------------------------------------------------- + gen.reset (); + A.clear (); + A.reserve (N + n_middle); + aux.clear (); + aux.reserve (n_middle); + + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), L_comp ()); + pos1 = n_middle; + pos2 = A.size () - 1; + for (uint64_t i = 0; i < (N >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + pos_read = n_middle; + pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + Test (A, L_comp (), V2); + Print_vectors (V1, V2) ; }; -template -int Test (std::vector &B, rightshift shift, compare comp,std::vector &V) +template +void Test (std::vector &B, compare comp, std::vector &V) { //---------------------------- begin -------------------------------- double duration; time_point start, finish; @@ -514,52 +525,5 @@ int Test (std::vector &B, rightshift shift, compare comp,std::vector finish = now (); duration = subtract_time (finish, start); V.push_back (duration); - //cout << duration << " secs\n"; -/* - A = B; - start = now (); - spinsort (A.begin (), A.end (), comp); - finish = now (); - duration = subtract_time (finish, start); - V.push_back (duration); - - A = B; - start = now (); - timsort (A.begin (), A.end (), comp); - finish = now (); - duration = subtract_time (finish, start); - V.push_back (duration); - - A = B; - //cout << "Boost spreadsort : "; - int sorted_count = 0; - for (unsigned i = 0; i + 1 < A.size(); ++i) - { - if (comp(A[i], A[i+1])) - { - sorted_count++; - }; - }; - start = now (); - boost::sort::spreadsort::integer_sort (A.begin (), A.end (), shift, comp); - finish = now (); - duration = subtract_time (finish, start); - int identical = 0; - for (unsigned i = 0; i + 1 < A.size(); ++i) - { - if (A[i].counter() != sorted[i].counter()) - { - cout << "incorrect!" << std::endl; - } - if (!comp(A[i], A[i+1]) && !comp(A[i+1], A[i])) - { - identical++; - }; - }; - // cout << "identical: " << identical << " pre-sorted: " << sorted_count << std::endl; - V.push_back (duration); - //cout << duration << " secs\n"; -*/ - return 0; }; diff --git a/benchmark/parallel/benchmark_strings.cpp b/benchmark/parallel/benchmark_strings.cpp index 1f23821..8f861a1 100644 --- a/benchmark/parallel/benchmark_strings.cpp +++ b/benchmark/parallel/benchmark_strings.cpp @@ -40,18 +40,17 @@ using bsc::subtract_time; void Generator_random (void); -void Generator_sorted(void); -void Generator_sorted_end(size_t n_last); -void Generator_sorted_middle (size_t n_last); -void Generator_reverse_sorted(void); -void Generator_reverse_sorted_end(size_t n_last); -void Generator_reverse_sorted_middle(size_t n_last); +void Generator_sorted (void); +void Generator_sorted_end( size_t n_last); +void Generator_sorted_middle (size_t n_middle); +void Generator_reverse_sorted (void); +void Generator_reverse_sorted_end (size_t n_last); +void Generator_reverse_sorted_middle (size_t n_middle); -template -int Test(std::vector &B, compare comp = compare()); +void Test (std::vector &B); -int main(int argc, char *argv[]) +int main(int argc, char *argv []) { cout << "\n\n"; cout << "************************************************************\n"; @@ -64,212 +63,223 @@ int main(int argc, char *argv[]) cout << "************************************************************\n"; cout << std::endl; - cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; - cout<<"[ 3 ] parallel_stable_sort\n\n"; - cout<<" | | | |\n"; - cout<<" | [ 1 ]| [ 2 ]| [ 3 ]|\n"; - cout<<"--------------------+------+------+------+\n"; + cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; + cout << "[ 3 ] parallel_stable_sort\n\n"; + cout << " | | | |\n"; + cout << " | [ 1 ]| [ 2 ]| [ 3 ]|\n"; + cout << "--------------------+------+------+------+\n"; std::string empty_line = " | | | |\n"; - cout<<"random |"; + cout << "random |"; Generator_random (); - cout< A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - Test>(A); - + Test (A); }; -void Generator_sorted(void) +void Generator_sorted (void) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort( A.begin() , A.end() ); - Test>(A); + std::sort (A.begin (), A.end ()); + Test (A); }; -void Generator_sorted_end(size_t n_last) +void Generator_sorted_end (size_t n_last) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING+ n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort (A.begin() , A.begin() + NMAXSTRING ); - Test>(A); + std::sort (A.begin (), A.begin () + NMAXSTRING ); + Test (A); }; -void Generator_sorted_middle(size_t n_last) +void Generator_sorted_middle (size_t n_middle) { - std::vector A,B,C; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) + assert (n_middle > 1 && NMAXSTRING >= (n_middle -1)); + vector A, aux; + A.reserve (NMAXSTRING + n_middle); + aux.reserve (n_middle); + + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) - B.push_back ( std::move ( A[i])); - A.resize ( NMAXSTRING); - std::sort (A.begin() , A.end() ); - size_t step = NMAXSTRING /n_last +1 ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i, pos += step) - { C.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - C.push_back ( A[pos + k] ); + for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end ()); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = NMAXSTRING / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - while ( pos < A.size() ) C.push_back ( A[pos++]); - A = C ; - - Test>(A); + aux.clear (); + aux.reserve (0); + Test (A); }; - -void Generator_reverse_sorted(void) +void Generator_reverse_sorted (void) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) + std::vector A; + A.reserve (NMAXSTRING); { - std::cout << "Error in the input file\n"; - return; + std::vector B; + B.reserve (NMAXSTRING); + if (bsc::fill_vector_string ("input.bin", B, NMAXSTRING) != 0) + { + std::cout << "Error in the input file\n"; + std::exit (EXIT_FAILURE); + }; + std::sort (B.begin(), B.end()); + A.clear (); + for (size_t i = 0; i < NMAXSTRING; ++i) + A.push_back (B [NMAXSTRING - 1 - i]); }; - std::sort( A.begin() , A.end()); - size_t nmid = (A.size() >>1), nlast = A.size() -1 ; - for (size_t i = 0 ; i < nmid ;++i) - std::swap ( A[i], A [nlast -i]); - - Test>(A); - + Test (A); }; -void Generator_reverse_sorted_end(size_t n_last) +void Generator_reverse_sorted_end (size_t n_last) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort (A.begin() , A.begin() + NMAXSTRING ); - for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i) - std::swap ( A[i], A[NMAXSTRING - 1 - i]); - - Test>(A); + std::sort (A.begin (), A.begin () + NMAXSTRING); + for (size_t i = 0; i < (NMAXSTRING >> 1); ++i) + std::swap (A [i], A [NMAXSTRING - 1 - i]); + Test (A); }; -void Generator_reverse_sorted_middle(size_t n_last) +void Generator_reverse_sorted_middle (size_t n_middle) { - std::vector A,B,C; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) + assert (n_middle > 1 && NMAXSTRING >= (n_middle -1)); + vector A, aux; + A.reserve (NMAXSTRING + n_middle); + aux.reserve (n_middle); + + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) - B.push_back ( std::move ( A[i])); - A.resize ( NMAXSTRING); - - std::sort (A.begin() , A.end() ); - for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i) - std::swap ( A[i], A[NMAXSTRING - 1 - i]); - - size_t step = NMAXSTRING /n_last +1 ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i, pos += step) - { C.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - C.push_back ( A[pos + k] ); + for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end ()); + + size_t pos1 = n_middle, pos2 = A.size () - 1; + for (size_t i = 0; i < (NMAXSTRING >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = NMAXSTRING / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - while ( pos < A.size() ) - C.push_back ( A[pos++]); - A = C ; - - Test>(A); + aux.clear (); + aux.reserve (0); + Test (A); }; - -template -int Test (std::vector &B, compare comp) +void Test (std::vector &B) { //---------------------------- begin -------------------------------- + std::less comp; double duration; time_point start, finish; - std::vector A (B); - std::vector V; + std::vector A (B); + std::vector V; //-------------------------------------------------------------------- A = B; @@ -296,11 +306,11 @@ int Test (std::vector &B, compare comp) //----------------------------------------------------------------------- // printing the vector //----------------------------------------------------------------------- - std::cout< -int Test (std::vector &B, compare comp = compare ()); +void Test (const std::vector &B); int main (int argc, char *argv[]) { @@ -129,34 +128,28 @@ int main (int argc, char *argv[]) cout< A; + vector A; A.reserve (NELEM); A.clear (); if (fill_vector_uint64 ("input.bin", A, NELEM) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - Test> (A); -} -; -void -Generator_sorted (void) + Test (A); +}; +void Generator_sorted (void) { vector A; - A.reserve (NELEM); A.clear (); - for (size_t i = 0; i < NELEM; ++i) + for (uint64_t i = 0; i < NELEM; ++i) A.push_back (i); - Test> (A); - -} - -void Generator_sorted_end (size_t n_last) + Test (A); +}; +void Generator_sorted_end (uint64_t n_last) { vector A; A.reserve (NELEM); @@ -164,112 +157,115 @@ void Generator_sorted_end (size_t n_last) if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; std::sort (A.begin (), A.begin () + NELEM); - - Test> (A); - -} -; -void Generator_sorted_middle (size_t n_last) + Test (A); +}; +void Generator_sorted_middle (uint64_t n_middle) { - vector A, B, C; - A.reserve (NELEM); - A.clear (); - if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) + assert (n_middle > 1 && NELEM >= (n_middle -1)); + vector A, aux; + A.reserve (NELEM + n_middle); + aux.reserve (n_middle); + + if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for (size_t i = NELEM; i < A.size (); ++i) - B.push_back (std::move (A[i])); - A.resize ( NELEM); - for (size_t i = 0; i < (NELEM >> 1); ++i) - std::swap (A[i], A[NELEM - 1 - i]); - - std::sort (A.begin (), A.end ()); - size_t step = NELEM / n_last + 1; - size_t pos = 0; - - for (size_t i = 0; i < B.size (); ++i, pos += step) + for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]); + + std::sort (A.begin () + n_middle, A.end ()); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + uint64_t step = NELEM / (n_middle - 1); + A [0] = aux [0]; + uint64_t pos_read = n_middle, pos_write = 1; + + for (uint64_t i = 1; i < n_middle; ++i) { - C.push_back (B[i]); - for (size_t k = 0; k < step; ++k) - C.push_back (A[pos + k]); + for (uint64_t k = 0 ; k < step; ++k) + A [pos_write ++] = A [pos_read ++]; + A [pos_write ++] = aux [i]; }; - while (pos < A.size ()) - C.push_back (A[pos++]); - A = C; - Test> (A); -} -; + aux.clear (); + aux.reserve (0); + Test (A); +}; void Generator_reverse_sorted (void) { vector A; - A.reserve (NELEM); A.clear (); - for (size_t i = NELEM; i > 0; --i) + for (uint64_t i = NELEM; i > 0; --i) A.push_back (i); - Test> (A); -} -void Generator_reverse_sorted_end (size_t n_last) + Test (A); +}; +void Generator_reverse_sorted_end (uint64_t n_last) { - vector A; + vector A; A.reserve (NELEM); A.clear (); if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; std::sort (A.begin (), A.begin () + NELEM); - for (size_t i = 0; i < (NELEM >> 1); ++i) - std::swap (A[i], A[NELEM - 1 - i]); + for (uint64_t i = 0; i < (NELEM >> 1); ++i) + std::swap (A [i], A [NELEM - 1 - i]); - Test> (A); + Test (A); } -void Generator_reverse_sorted_middle (size_t n_last) +void Generator_reverse_sorted_middle (uint64_t n_middle) { - vector A, B, C; - A.reserve (NELEM); - A.clear (); - if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) + assert (n_middle > 1 && NELEM >= (n_middle -1)); + vector A, aux; + A.reserve (NELEM + n_middle); + aux.reserve (n_middle); + + if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for (size_t i = NELEM; i < A.size (); ++i) - B.push_back (std::move (A[i])); - A.resize ( NELEM); - for (size_t i = 0; i < (NELEM >> 1); ++i) - std::swap (A[i], A[NELEM - 1 - i]); - - std::sort (A.begin (), A.end ()); - size_t step = NELEM / n_last + 1; - size_t pos = 0; - - for (size_t i = 0; i < B.size (); ++i, pos += step) + for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [i]); + + std::sort (A.begin () + n_middle, A.end ()); + uint64_t pos1 = n_middle, pos2 = A.size () - 1; + for (uint64_t i = 0; i < (NELEM >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + uint64_t step = NELEM / (n_middle - 1); + A [0] = aux [0]; + uint64_t pos_read = n_middle, pos_write = 1; + + for (uint64_t i = 1; i < n_middle; ++i) { - C.push_back (B[i]); - for (size_t k = 0; k < step; ++k) - C.push_back (A[pos + k]); + for (uint64_t k = 0 ; k < step; ++k) + A [pos_write ++] = A [pos_read ++]; + A [pos_write ++] = aux [i]; }; - while (pos < A.size ()) - C.push_back (A[pos++]); - A = C; - Test> (A); + aux.clear (); + aux.reserve (0); + Test (A); }; - - -template -int Test (std::vector &B, compare comp) -{ //---------------------------- begin -------------------------------- +void Test (const std::vector &B) +{ + //---------------------------- begin -------------------------------- + std::less comp ; double duration; time_point start, finish; - std::vector A (B); - std::vector V; + std::vector A (B); + std::vector V; //-------------------------------------------------------------------- A = B; @@ -307,7 +303,6 @@ int Test (std::vector &B, compare comp) duration = subtract_time (finish, start); V.push_back (duration); - A = B; start = now (); spreadsort (A.begin (), A.end ()); @@ -318,11 +313,10 @@ int Test (std::vector &B, compare comp) //----------------------------------------------------------------------- // printing the vector //----------------------------------------------------------------------- - std::cout< #include #include "boost/sort/common/int_array.hpp" - #include - -#define NELEM 100000000 -#define NMAXSTRING 10000000 - using namespace std; namespace bsort = boost::sort; namespace bsc = bsort::common; @@ -54,49 +49,55 @@ using bsort::pdqsort; template -void Generator_random(uint64_t N); +void Generator_random (uint64_t N); template -void Generator_sorted(uint64_t N); +void Generator_sorted (uint64_t N); template -void Generator_sorted_end(uint64_t N, size_t n_last ); +void Generator_sorted_end (uint64_t N, size_t n_last ); template -void Generator_sorted_middle(uint64_t N, size_t n_last ); +void Generator_sorted_middle (uint64_t N, size_t n_middle ); template -void Generator_reverse_sorted(uint64_t N); +void Generator_reverse_sorted (uint64_t N); template -void Generator_reverse_sorted_end(uint64_t N, size_t n_last ); +void Generator_reverse_sorted_end (uint64_t N, size_t n_last ); template -void Generator_reverse_sorted_middle(uint64_t N, size_t n_last ); +void Generator_reverse_sorted_middle (uint64_t N, size_t n_midlle ); -template < class IA > -struct H_rightshift { - inline uint64_t operator()(const IA& A1, unsigned offset) { - return A1.counter() >> offset; - } +template +struct H_rightshift +{ + inline uint64_t operator () (const IA& A1, unsigned offset) + { + return A1.counter () >> offset; + }; }; -template < class IA > -struct L_rightshift { - inline uint64_t operator()(const IA& A1, unsigned offset) { - return A1.M[0] >> offset; - } +template +struct L_rightshift +{ + inline uint64_t operator () (const IA& A1, unsigned offset) + { + return A1.M[0] >> offset; + }; }; template -int Test(std::vector &B, rightshift shift, compare comp, std::vector & V ); +int Test (std::vector< IA> &B, rightshift shift, + compare comp, std::vector & V ); template -void Test_size ( uint64_t N); +void Test_size (uint64_t N); -void Print_vectors ( std::vector & V1, std::vector & V2); +void Print_vectors ( std::vector &V1, std::vector &V2); -int main(int argc, char *argv[]) +int main(int argc, char *argv []) { + const uint64_t NELEM = 100000000; cout << "\n\n"; cout << "************************************************************\n"; cout << "** **\n"; @@ -130,7 +131,7 @@ int main(int argc, char *argv[]) cout << "** **\n"; cout << "************************************************************\n"; - Test_size >(NELEM); + Test_size >(NELEM); //----------------------------------------------------------------------- // I N T _ A R R A Y < 4 > @@ -140,7 +141,7 @@ int main(int argc, char *argv[]) cout << " "<<(NELEM >>2)<<" OBJECTS UINT64_T [4]\n"; cout << "** **\n"; cout << "************************************************************\n"; - Test_size >(NELEM >> 2); + Test_size >(NELEM >> 2); //----------------------------------------------------------------------- // I N T _ A R R A Y < 8 > @@ -150,7 +151,7 @@ int main(int argc, char *argv[]) cout << " "<<(NELEM >>3)<<" OBJECTS UINT64_T [8]\n"; cout << "** **\n"; cout << "************************************************************\n"; - Test_size >(NELEM >> 3); + Test_size >(NELEM >> 3); //----------------------------------------------------------------------- // I N T _ A R R A Y < 1 6 > @@ -160,7 +161,7 @@ int main(int argc, char *argv[]) cout << " "<<(NELEM >>4)<<" OBJECTS UINT64_T [16]\n"; cout << "** **\n"; cout << "************************************************************\n"; - Test_size >(NELEM >> 4); + Test_size >(NELEM >> 4); //----------------------------------------------------------------------- // I N T _ A R R A Y < 6 4 > @@ -170,13 +171,13 @@ int main(int argc, char *argv[]) cout << " "<< (NELEM >>6)<<" OBJECTS UINT64_T [64]\n"; cout << "** **\n"; cout << "************************************************************\n"; - Test_size >(NELEM >> 6); + Test_size >(NELEM >> 6); return 0; } template -void Test_size ( uint64_t N) +void Test_size (uint64_t N) { cout<<"\n"; cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n"; @@ -197,317 +198,349 @@ void Test_size ( uint64_t N) " | | | |\n"; cout<<"random |"; - Generator_random(N); + Generator_random (N); cout<(N); + Generator_sorted (N); cout<<"sorted + 0.1% end |"; - Generator_sorted_end(N, N / 1000); + Generator_sorted_end (N, N / 1000); cout<<"sorted + 1% end |"; - Generator_sorted_end(N, N / 100); + Generator_sorted_end (N, N / 100); cout<<"sorted + 10% end |"; - Generator_sorted_end(N, N / 10); + Generator_sorted_end (N, N / 10); cout<(N, N / 1000); + Generator_sorted_middle (N, N / 1000); cout<<"sorted + 1% mid |"; - Generator_sorted_middle(N, N / 100); + Generator_sorted_middle (N, N / 100); cout<<"sorted + 10% mid |"; - Generator_sorted_middle(N, N / 10); + Generator_sorted_middle (N, N / 10); cout<(N); + Generator_reverse_sorted (N); cout<<"rv sorted + 0.1% end|"; - Generator_reverse_sorted_end(N, N / 1000); + Generator_reverse_sorted_end (N, N / 1000); cout<<"rv sorted + 1% end|"; - Generator_reverse_sorted_end(N, N / 100); + Generator_reverse_sorted_end (N, N / 100); cout<<"rv sorted + 10% end|"; - Generator_reverse_sorted_end(N, N / 10); + Generator_reverse_sorted_end (N, N / 10); cout<(N, N / 1000); + Generator_reverse_sorted_middle (N, N / 1000); cout<<"rv sorted + 1% mid|"; - Generator_reverse_sorted_middle(N, N / 100); + Generator_reverse_sorted_middle (N, N / 100); cout<<"rv sorted + 10% mid|"; - Generator_reverse_sorted_middle(N, N / 10); - cout<< "--------------------+-----------+-----------+-----------+"; + Generator_reverse_sorted_middle (N, N / 10); + cout << "--------------------+-----------+-----------+-----------+"; cout << "-----------+-----------+-----------+\n"; cout< & V1, std::vector & V2) { - assert ( V1.size() == V2.size()); - std::cout< -void Generator_random(uint64_t N) +void Generator_random (uint64_t N) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; - - gen.reset(); - A.clear(); - for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); - - Test(A, H_rightshift(), H_comp(), V1); - - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; + + gen.reset (); + A.clear (); + for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate(gen)); + + Test(A, H_rightshift (), H_comp (), V1); + Test(A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; + template void Generator_sorted(uint64_t N) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; - gen.reset(); - A.clear(); - for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); + gen.reset (); + A.clear (); + for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen)); - std::sort( A.begin() , A.end(),H_comp() ); - Test(A, H_rightshift(), H_comp(), V1); + std::sort (A.begin (), A.end (), H_comp ()); + Test (A, H_rightshift (), H_comp (), V1); - std::sort( A.begin() , A.end(),L_comp() ); - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + std::sort (A.begin (), A.end (), L_comp ()); + Test (A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; template -void Generator_sorted_end(uint64_t N, size_t n_last ) +void Generator_sorted_end (uint64_t N, size_t n_last ) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; - gen.reset(); - A.clear(); + gen.reset (); + A.clear (); for (uint32_t i = 0; i < (N + n_last); i++) - A.emplace_back(IA::generate(gen)); - std::sort ( A.begin() , A.begin() + N ,H_comp()); + A.emplace_back (IA::generate (gen)); + + std::sort (A.begin (), A.begin () + N, H_comp ()); - Test(A, H_rightshift(), H_comp(),V1); - std::sort ( A.begin() , A.begin() + N ,L_comp()); + Test (A, H_rightshift (), H_comp (), V1); + std::sort (A.begin (), A.begin () + N, L_comp ()); - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + Test (A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; template -void Generator_sorted_middle(uint64_t N, size_t n_last ) +void Generator_sorted_middle (uint64_t N, size_t n_middle ) { - bsc::uint64_file_generator gen("input.bin"); - std::vector V1, V2 ; - vector A; - A.reserve(N + n_last); - - { A.clear() ; - gen.reset(); - vector B, C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); - - std::sort ( C.begin() , C.end() ,H_comp()); - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + assert (n_middle > 1 && N >= (n_middle -1)); + bsc::uint64_file_generator gen ("input.bin"); + + std::vector V1, V2; // vector with the times used + vector A, aux; + A.reserve (N + n_middle); + aux.reserve (n_middle); + + //----------------------------------------------------------------------- + // H _ C O M P + //----------------------------------------------------------------------- + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), H_comp ()); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, H_rightshift(), H_comp(), V1); - - { A.clear() ; - gen.reset(); - vector B,C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); + Test (A, H_rightshift (), H_comp (), V1); - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); - - std::sort ( C.begin() , C.end() ,L_comp()); - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + //---------------------------------------------------------------------- + // L _ C O M P + //----------------------------------------------------------------------- + gen.reset (); + A.clear (); + A.reserve (N + n_middle); + aux.clear (); + aux.reserve (n_middle); + + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), L_comp ()); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + pos_read = n_middle; + pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + + Test (A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; template -void Generator_reverse_sorted(uint64_t N) +void Generator_reverse_sorted (uint64_t N) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; - - gen.reset(); - A.clear(); - for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); - - std::sort( A.begin() , A.end(),H_comp() ); - for ( size_t i = 0; i < (A.size() >>1) ; ++i) - std::swap ( A[i], A[A.size() - i -1 ]); - - Test(A, H_rightshift(), H_comp(), V1); - - std::sort( A.begin() , A.end(),L_comp() ); - for ( size_t i = 0; i < (A.size() >>1) ; ++i) - std::swap ( A[i], A[A.size() - i -1 ]); - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; + + gen.reset (); + A.clear (); + for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen)); + + std::sort (A.begin (), A.end (), H_comp ()); + for (size_t i = 0; i < (A.size () >>1); ++i) + std::swap (A [i], A [A.size () - i - 1]); + + Test (A, H_rightshift (), H_comp (), V1); + + std::sort (A.begin (), A.end (), L_comp ()); + for (size_t i = 0; i < (A.size () >> 1); ++i) + std::swap (A [i], A [A.size() - i - 1]); + + Test (A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; + template -void Generator_reverse_sorted_end(uint64_t N, size_t n_last ) +void Generator_reverse_sorted_end (uint64_t N, size_t n_last ) { - bsc::uint64_file_generator gen("input.bin"); - vector A; - A.reserve(N); - std::vector V1, V2 ; + bsc::uint64_file_generator gen ("input.bin"); + vector A; + A.reserve (N); + std::vector V1, V2 ; - gen.reset(); - A.clear(); + gen.reset (); + A.clear (); for (uint32_t i = 0; i < (N + n_last); i++) - A.emplace_back(IA::generate(gen)); - std::sort ( A.begin() , A.begin() + N ,H_comp()); - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( A[i], A[N-1-i]); - - Test(A, H_rightshift(), H_comp(), V1); - std::sort ( A.begin() , A.begin() + N ,L_comp()); - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( A[i], A[N-1-i]); - - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + A.emplace_back (IA::generate (gen)); + + std::sort (A.begin (), A.begin () + N , H_comp ()); + for (size_t i =0 ; i < (N >> 1); ++i) + std::swap (A [i], A [N - 1 - i]); + + Test (A, H_rightshift (), H_comp (), V1); + std::sort (A.begin (), A.begin () + N, L_comp ()); + for (size_t i = 0; i < (N >> 1); ++i) + std::swap (A [i], A [N - 1 - i]); + + Test (A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; + template -void Generator_reverse_sorted_middle(uint64_t N, size_t n_last ) +void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle ) { - bsc::uint64_file_generator gen("input.bin"); - std::vector V1, V2 ; - vector A; - A.reserve(N + n_last); - - { A.clear() ; - gen.reset(); - vector B,C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); - - std::sort ( C.begin() , C.end() ,H_comp()); - - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( C[i], C[N-1-i]); - - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++ ] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + assert (n_middle > 1 && N >= (n_middle -1)); + bsc::uint64_file_generator gen ("input.bin"); + + std::vector V1, V2; // vector with the times used + vector A, aux; + A.reserve (N + n_middle); + aux.reserve (n_middle); + + //----------------------------------------------------------------------- + // H _ C O M P + //----------------------------------------------------------------------- + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), H_comp ()); + uint64_t pos1 = n_middle, pos2 = A.size () - 1; + for (uint64_t i = 0; i < (N >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, H_rightshift(), H_comp(), V1); - - { A.clear() ; - gen.reset(); - vector B,C; - C.reserve(N + n_last); - B.reserve ( n_last); - for (uint32_t i = 0; i < (N + n_last); i++) - C.emplace_back(IA::generate(gen)); - - for ( size_t i = N ; i < C.size() ; ++i) - B.push_back ( std::move ( C[i])); - - C.resize ( N); + Test (A, H_rightshift (), H_comp (), V1); - std::sort ( C.begin() , C.end() ,L_comp()); - - for ( size_t i =0 ; i < (N>>1); ++i) - std::swap ( C[i], C[N-1-i]); - size_t step = N /n_last ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i) - { A.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - A.push_back ( C[pos++ ] ); - }; - while ( pos < C.size() ) - A.push_back ( C[pos++]); + //---------------------------------------------------------------------- + // L _ C O M P + //----------------------------------------------------------------------- + gen.reset (); + A.clear (); + A.reserve (N + n_middle); + aux.clear (); + aux.reserve (n_middle); + + for (uint32_t i = 0; i < (N + n_middle); i++) + A.emplace_back (IA::generate (gen)); + + for (size_t i = 0; i < n_middle; ++i) + aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end (), L_comp ()); + pos1 = n_middle; + pos2 = A.size () - 1; + for (uint64_t i = 0; i < (N >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + step = N / (n_middle - 1); + A [0] = std::move (aux [0]); + pos_read = n_middle; + pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - Test(A, L_rightshift(), L_comp(), V2); - Print_vectors ( V1, V2 ) ; + Test (A, L_rightshift (), L_comp (), V2); + Print_vectors (V1, V2) ; }; -template -int Test (std::vector &B, rightshift shift, compare comp,std::vector &V) +template +int Test (std::vector &B, rightshift shift, + compare comp, std::vector &V) { //---------------------------- begin -------------------------------- double duration; time_point start, finish; - std::vector A (B); - V.clear() ; + std::vector A (B); + V.clear () ; //-------------------------------------------------------------------- A = B; diff --git a/benchmark/single/benchmark_strings.cpp b/benchmark/single/benchmark_strings.cpp index df63f8f..7332f36 100644 --- a/benchmark/single/benchmark_strings.cpp +++ b/benchmark/single/benchmark_strings.cpp @@ -47,18 +47,17 @@ using bsort::spreadsort::spreadsort; using bsort::pdqsort; void Generator_random (void); -void Generator_sorted(void); -void Generator_sorted_end(size_t n_last); +void Generator_sorted (void); +void Generator_sorted_end (size_t n_last); void Generator_sorted_middle (size_t n_last); -void Generator_reverse_sorted(void); -void Generator_reverse_sorted_end(size_t n_last); -void Generator_reverse_sorted_middle(size_t n_last); +void Generator_reverse_sorted (void); +void Generator_reverse_sorted_end (size_t n_last); +void Generator_reverse_sorted_middle (size_t n_last); -template -int Test(std::vector &B, compare comp = compare()); +int Test (std::vector &B); -int main(int argc, char *argv[]) +int main (int argc, char *argv []) { cout << "\n\n"; cout << "************************************************************\n"; @@ -72,232 +71,224 @@ int main(int argc, char *argv[]) cout << "************************************************************\n"; cout << std::endl; - cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n"; - cout<<"[ 4 ] spinsort [ 5 ] flat_stable_sort [ 6 ] spreadsort\n\n"; - cout<<" | | | | | | |\n"; - cout<<" | [ 1 ]| [ 2 ]| [ 3 ]| [ 4 ]| [ 5 ]| [ 6 ]|\n"; - cout<<"--------------------+------+------+------+------+------+------+\n"; + cout << "[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort\n"; + cout << "[ 4 ] spinsort [ 5 ] flat_stable_sort [ 6 ] spreadsort\n\n"; + cout << " | | | | | | |\n"; + cout << " | [ 1 ]| [ 2 ]| [ 3 ]| [ 4 ]| [ 5 ]| [ 6 ]|\n"; + cout << "--------------------+------+------+------+------+------+------+\n"; std::string empty_line = " | | | | | | |\n"; - cout<<"random |"; + cout << "random |"; Generator_random (); - cout< A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - Test>(A); - + Test (A); }; -void Generator_sorted(void) +void Generator_sorted (void) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort( A.begin() , A.end() ); - Test>(A); + std::sort (A.begin (), A.end ()); + Test (A); }; -void Generator_sorted_end(size_t n_last) +void Generator_sorted_end (size_t n_last) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING+ n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort (A.begin() , A.begin() + NMAXSTRING ); - Test>(A); + std::sort (A.begin (), A.begin () + NMAXSTRING ); + Test (A); }; -void Generator_sorted_middle(size_t n_last) +void Generator_sorted_middle (size_t n_middle) { - std::vector A,B,C; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) + assert (n_middle > 1 && NMAXSTRING >= (n_middle -1)); + vector A, aux; + A.reserve (NMAXSTRING + n_middle); + aux.reserve (n_middle); + + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) - B.push_back ( std::move ( A[i])); - A.resize ( NMAXSTRING); - std::sort (A.begin() , A.end() ); - size_t step = NMAXSTRING /n_last +1 ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i, pos += step) - { C.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - C.push_back ( A[pos + k] ); + for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end ()); + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = NMAXSTRING / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - while ( pos < A.size() ) C.push_back ( A[pos++]); - A = C ; - - Test>(A); + aux.clear (); + aux.reserve (0); + Test (A); }; - -void Generator_reverse_sorted(void) +void Generator_reverse_sorted (void) { - - std::vector A; - A.reserve(NMAXSTRING); + std::vector A; + A.reserve (NMAXSTRING); { - std::vector B; - B.reserve(NMAXSTRING); - if (bsc::fill_vector_string("input.bin", B, NMAXSTRING) != 0) + std::vector B; + B.reserve (NMAXSTRING); + if (bsc::fill_vector_string ("input.bin", B, NMAXSTRING) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort(B.begin(), B.end()); - A.clear(); + std::sort (B.begin(), B.end()); + A.clear (); for (size_t i = 0; i < NMAXSTRING; ++i) - A.push_back(B[NMAXSTRING - 1 - i]); - }; - Test>(A); - -/* - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) - { - std::cout << "Error in the input file\n"; - return; + A.push_back (B [NMAXSTRING - 1 - i]); }; - std::sort( A.begin() , A.end()); - size_t nmid = (A.size() >>1), nlast = A.size() -1 ; - for (size_t i = 0 ; i < nmid ;++i) - std::swap ( A[i], A [nlast -i]); - - Test>(A); -*/ + Test (A); }; -void Generator_reverse_sorted_end(size_t n_last) +void Generator_reverse_sorted_end (size_t n_last) { - std::vector A; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) + std::vector A; + A.reserve (NMAXSTRING); + A.clear (); + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_last) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - std::sort (A.begin() , A.begin() + NMAXSTRING ); - for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i) - std::swap ( A[i], A[NMAXSTRING - 1 - i]); - - Test>(A); + std::sort (A.begin (), A.begin () + NMAXSTRING); + for (size_t i = 0; i < (NMAXSTRING >> 1); ++i) + std::swap (A [i], A [NMAXSTRING - 1 - i]); + Test (A); }; -void Generator_reverse_sorted_middle(size_t n_last) +void Generator_reverse_sorted_middle (size_t n_middle) { - std::vector A,B,C; - A.reserve(NMAXSTRING); - A.clear(); - if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) + assert (n_middle > 1 && NMAXSTRING >= (n_middle -1)); + vector A, aux; + A.reserve (NMAXSTRING + n_middle); + aux.reserve (n_middle); + + if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0) { std::cout << "Error in the input file\n"; - return; + std::exit (EXIT_FAILURE); }; - for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) - B.push_back ( std::move ( A[i])); - A.resize ( NMAXSTRING); - - std::sort (A.begin() , A.end() ); - for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i) - std::swap ( A[i], A[NMAXSTRING - 1 - i]); - - size_t step = NMAXSTRING /n_last +1 ; - size_t pos = 0 ; - - for ( size_t i =0 ; i < B.size() ; ++i, pos += step) - { C.push_back ( B[i]); - for ( size_t k = 0 ; k < step ; ++k ) - C.push_back ( A[pos + k] ); + for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i])); + + std::sort (A.begin () + n_middle, A.end ()); + + size_t pos1 = n_middle, pos2 = A.size () - 1; + for (size_t i = 0; i < (NMAXSTRING >> 1); ++i) + std::swap (A [pos1 ++], A [pos2 --]); + + //------------------------------------------------------------------------ + // To insert n_middle elements, must have (n_middle - 1) intervals between + // them. The size of the interval is step + // The elements after the last element of aux don't need to be moved + //------------------------------------------------------------------------- + size_t step = NMAXSTRING / (n_middle - 1); + A [0] = std::move (aux [0]); + size_t pos_read = n_middle, pos_write = 1; + + for (size_t i = 1; i < n_middle; ++i) + { + for (size_t k = 0 ; k < step; ++k) + A [pos_write ++] = std::move (A [pos_read ++]); + A [pos_write ++] = std::move (aux [i]); }; - while ( pos < A.size() ) - C.push_back ( A[pos++]); - A = C ; - - Test>(A); + aux.clear (); + aux.reserve (0); + Test (A); }; - -template -int Test (std::vector &B, compare comp) -{ //---------------------------- begin ----------------------------- +int Test (std::vector &B) +{ + //---------------------------- begin ----------------------------- + std::less comp; double duration; time_point start, finish; - std::vector A (B); - std::vector V; - + std::vector A (B); + std::vector V; A = B; start = now (); @@ -344,11 +335,12 @@ int Test (std::vector &B, compare comp) //----------------------------------------------------------------------- // printing the vector //----------------------------------------------------------------------- - std::cout< &index) while (pos_in_vector < nelem) { - while (pos_in_vector < nelem and + while (pos_in_vector < nelem && (size_t(index[pos_in_vector] - global_first)) == pos_in_vector) { ++pos_in_vector; diff --git a/include/boost/sort/common/merge_block.hpp b/include/boost/sort/common/merge_block.hpp index 1a7eb90..919aa75 100644 --- a/include/boost/sort/common/merge_block.hpp +++ b/include/boost/sort/common/merge_block.hpp @@ -14,7 +14,6 @@ #ifndef __BOOST_SORT_COMMON_MERGE_BLOCK_HPP #define __BOOST_SORT_COMMON_MERGE_BLOCK_HPP -#include #include #include #include @@ -126,7 +125,7 @@ struct merge_block ~ merge_block() { - if (ptr_circ != nullptr and owned) + if (ptr_circ != nullptr && owned) { delete ptr_circ; ptr_circ = nullptr; @@ -171,7 +170,7 @@ struct merge_block //------------------------------------------------------------------------- bool is_tail(size_t pos) const { - return (pos == (nblock - 1) and ntail != 0); + return (pos == (nblock - 1) && ntail != 0); }; //------------------------------------------------------------------------- // function : @@ -223,10 +222,10 @@ template void merge_block ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) { - assert((itx_last - itx_mid) >= 0 and (itx_mid - itx_first) >= 0); + assert((itx_last - itx_mid) >= 0 && (itx_mid - itx_first) >= 0); size_t nelemA = (itx_mid - itx_first), nelemB = (itx_last - itx_mid); - if (nelemA == 0 or nelemB == 0) return; + if (nelemA == 0 || nelemB == 0) return; //------------------------------------------------------------------- // Create two index with the position of the blocks to merge @@ -244,17 +243,17 @@ ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) Iter_t itA = global_range.first, itB = global_range.first; bool validA = false, validB = false; - while (itxA != indexA.end() and itxB != indexB.end()) + while (itxA != indexA.end() && itxB != indexB.end()) { //---------------------------------------------------------------- // Load valid ranges from the itxA and ItxB positions //---------------------------------------------------------------- - if (not validA) + if (! validA) { rngA = get_range(*itxA); itA = rngA.first; validA = true; }; - if (not validB) + if (! validB) { rngB = get_range(*itxB); itB = rngB.first; @@ -266,7 +265,7 @@ ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) //---------------------------------------------------------------- if (ptr_circ->size() == 0) { - if (not cmp(*rngB.front(), *rngA.back())) + if (! cmp(*rngB.front(), *rngA.back())) { *(itx_out++) = *(itxA++); validA = false; @@ -274,7 +273,7 @@ ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) }; if (cmp(*rngB.back(), *rngA.front())) { - if (not is_tail(*itxB)) + if (! is_tail(*itxB)) *(itx_out++) = *itxB; else ptr_circ->push_move_back(rngB.first, rngB.size()); ++itxB; @@ -295,7 +294,7 @@ ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) } else { // rngB is finished - if (not is_tail(*itxB)) + if (! is_tail(*itxB)) { ptr_circ->pop_move_front(rngB.first, rngB.size()); *(itx_out++) = *itxB; @@ -315,7 +314,7 @@ ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) else { // The list B is finished rngA = get_range(*itxA); - if (ntail != 0 and indexB.back() == (nblock - 1)) // exist tail + if (ntail != 0 && indexB.back() == (nblock - 1)) // exist tail { // add the tail block to indexA, and shift the element indexA.push_back(indexB.back()); size_t numA = size_t(itA - rngA.first); @@ -341,7 +340,7 @@ template void merge_block ::move_range_pos_backward(it_index itx_first, it_index itx_last, size_t npos) { - assert((itx_last - itx_first) >= 0 and npos <= BLOCK_SIZE); + assert((itx_last - itx_first) >= 0 && npos <= BLOCK_SIZE); //-------------------------------------------------------------------- // Processing the last block. Must be ready fore to accept npos @@ -391,7 +390,7 @@ ::rearrange_with_index(void) pos_ini = 0; while (pos_ini < nelem) { - while (pos_ini < nelem and index[pos_ini] == pos_ini) + while (pos_ini < nelem && index[pos_ini] == pos_ini) ++pos_ini; if (pos_ini == nelem) return; pos_dest = pos_src = pos_ini; diff --git a/include/boost/sort/common/range.hpp b/include/boost/sort/common/range.hpp index 73dbd5a..859bf75 100644 --- a/include/boost/sort/common/range.hpp +++ b/include/boost/sort/common/range.hpp @@ -13,7 +13,6 @@ #ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP #define __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP -#include #include #include #include @@ -235,7 +234,7 @@ inline bool is_mergeable_stable(const range &src1, //------------------------------------------------------------------------ // Code //------------------------------------------------------------------------ - return not comp(*(src1.back()), *(src2.front())); + return ! comp(*(src1.back()), *(src2.front())); }; // //----------------------------------------------------------------------------- @@ -380,7 +379,7 @@ static void merge_flow(range rng1, range rbuf, //------------------------------------------------------------------------- range rbx(rbuf); range rx1(rng1), rx2(rng2); - assert(rbx.size() == rx1.size() and rx1.size() == rx2.size()); + assert(rbx.size() == rx1.size() && rx1.size() == rx2.size()); while (rx1.first != rx1.last) { *(rx1.first++) = (cmp(*rbx.first, *rx2.first)) ? diff --git a/include/boost/sort/common/rearrange.hpp b/include/boost/sort/common/rearrange.hpp index d32db09..687de29 100644 --- a/include/boost/sort/common/rearrange.hpp +++ b/include/boost/sort/common/rearrange.hpp @@ -13,7 +13,6 @@ #ifndef __BOOST_SORT_COMMON_REARRANGE_HPP #define __BOOST_SORT_COMMON_REARRANGE_HPP -#include #include #include #include @@ -83,7 +82,7 @@ void rearrange(Iter_data global_first, Iter_index itx_first, pos_ini = 0; while (pos_ini < nelem) { - while (pos_ini < nelem and pos(index[pos_ini]) == pos_ini) + while (pos_ini < nelem && pos(index[pos_ini]) == pos_ini) ++pos_ini; if (pos_ini == nelem) return; pos_dest = pos_src = pos_ini; diff --git a/include/boost/sort/common/sort_basic.hpp b/include/boost/sort/common/sort_basic.hpp index 35121ae..74a5b99 100644 --- a/include/boost/sort/common/sort_basic.hpp +++ b/include/boost/sort/common/sort_basic.hpp @@ -13,7 +13,6 @@ #ifndef __BOOST_SORT_COMMON_SORT_BASIC_HPP #define __BOOST_SORT_COMMON_SORT_BASIC_HPP -#include #include #include #include @@ -56,7 +55,7 @@ inline Iter_t is_stable_sorted_forward (Iter_t first, Iter_t last, #endif if ((last - first) < 2) return first; Iter_t it2 = first + 1; - for (Iter_t it1 = first; it2 != last and not comp(*it2, *it1); it1 = it2++); + for (Iter_t it1 = first; it2 != last && ! comp(*it2, *it1); it1 = it2++); return it2; } //----------------------------------------------------------------------------- @@ -79,7 +78,7 @@ inline Iter_t is_reverse_stable_sorted_forward(Iter_t first, Iter_t last, #endif if ((last - first) < 2) return first; Iter_t it2 = first + 1; - for (Iter_t it1 = first; it2 != last and comp(*it2, *it1); it1 = it2++); + for (Iter_t it1 = first; it2 != last && comp(*it2, *it1); it1 = it2++); return it2; }; //----------------------------------------------------------------------------- @@ -105,14 +104,14 @@ size_t number_stable_sorted_forward (Iter_t first, Iter_t last, // sorted elements Iter_t it2 = first + 1; - for (Iter_t it1 = first; it2 != last and not comp(*it2, *it1); it1 = it2++); + for (Iter_t it1 = first; it2 != last && ! comp(*it2, *it1); it1 = it2++); size_t nsorted = size_t ( it2 - first); if ( nsorted != 1) return (nsorted >= min_process) ? nsorted: 0; // reverse sorted elements it2 = first + 1; - for (Iter_t it1 = first; it2 != last and comp(*it2, *it1); it1 = it2++); + for (Iter_t it1 = first; it2 != last && comp(*it2, *it1); it1 = it2++); nsorted = size_t ( it2 - first); if ( nsorted < min_process) return 0 ; @@ -140,7 +139,7 @@ inline Iter_t is_stable_sorted_backward(Iter_t first, Iter_t last, #endif if ((last - first) < 2) return first; Iter_t itaux = last - 1; - while (itaux != first and not comp(*itaux, *(itaux - 1))) {--itaux; }; + while (itaux != first && ! comp(*itaux, *(itaux - 1))) {--itaux; }; return itaux; } //----------------------------------------------------------------------------- @@ -163,7 +162,7 @@ inline Iter_t is_reverse_stable_sorted_backward (Iter_t first, Iter_t last, #endif if ((last - first) < 2) return first; Iter_t itaux = last - 1; - for (; itaux != first and comp(*itaux, *(itaux - 1)); --itaux); + for (; itaux != first && comp(*itaux, *(itaux - 1)); --itaux); return itaux; } @@ -188,13 +187,13 @@ size_t number_stable_sorted_backward (Iter_t first, Iter_t last, #endif if ((last - first) < 2) return 0; Iter_t itaux = last - 1; - while (itaux != first and not comp(*itaux, *(itaux - 1))) {--itaux; }; + while (itaux != first && ! comp(*itaux, *(itaux - 1))) {--itaux; }; size_t nsorted = size_t ( last - itaux); if ( nsorted != 1) return ( nsorted >= min_process)?nsorted: 0 ; itaux = last - 1; - for (; itaux != first and comp(*itaux, *(itaux - 1)); --itaux); + for (; itaux != first && comp(*itaux, *(itaux - 1)); --itaux); nsorted = size_t ( last - itaux); if ( nsorted < min_process) return 0 ; util::reverse ( itaux, last ); @@ -238,7 +237,7 @@ inline void internal_sort (const range &rng1, range rng2_left(rng2.first, rng2.first + nelem), rng2_right(rng2.first + nelem, rng2.last); - if (nelem <= 32 and (level & 1) == even) + if (nelem <= 32 && (level & 1) == even) { insert_sort(rng1_left.first, rng1_left.last, comp); insert_sort(rng1_right.first, rng1_right.last, comp); diff --git a/include/boost/sort/common/util/merge.hpp b/include/boost/sort/common/util/merge.hpp index 943e979..6fce04e 100644 --- a/include/boost/sort/common/util/merge.hpp +++ b/include/boost/sort/common/util/merge.hpp @@ -13,7 +13,6 @@ #ifndef __BOOST_SORT_COMMON_UTIL_MERGE_HPP #define __BOOST_SORT_COMMON_UTIL_MERGE_HPP -#include #include #include #include @@ -107,7 +106,7 @@ static Iter3_t merge(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, if (buf1 == end_buf1) return move_forward(buf_out, buf2, end_buf2); if (buf2 == end_buf2) return move_forward(buf_out, buf1, end_buf1); - if (not comp(*buf2, *(end_buf1 - 1))) + if (! comp(*buf2, *(end_buf1 - 1))) { Iter3_t mid = move_forward(buf_out, buf1, end_buf1); return move_forward(mid, buf2, end_buf2); @@ -119,9 +118,9 @@ static Iter3_t merge(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, return move_forward(mid, buf1, end_buf1); }; }; - while ((buf1 != end_buf1) and (buf2 != end_buf2)) + while ((buf1 != end_buf1) && (buf2 != end_buf2)) { - *(buf_out++) = (not comp(*buf2, *buf1)) ? + *(buf_out++) = (! comp(*buf2, *buf1)) ? std::move(*(buf1++)) : std::move(*(buf2++)); }; @@ -168,7 +167,7 @@ static Value_t *merge_construct(Iter1_t first1, const Iter1_t last1, if (first1 == last1) return move_construct(it_out, first2, last2); if (first2 == last2) return move_construct(it_out, first1, last1); - if (not comp(*first2, *(last1 - 1))) + if (! comp(*first2, *(last1 - 1))) { Value_t* mid = move_construct(it_out, first1, last1); return move_construct(mid, first2, last2); @@ -180,10 +179,10 @@ static Value_t *merge_construct(Iter1_t first1, const Iter1_t last1, return move_construct(mid, first1, last1); }; }; - while (first1 != last1 and first2 != last2) + while (first1 != last1 && first2 != last2) { construct_object((it_out++), - (not comp(*first2, *first1)) ? + (! comp(*first2, *first1)) ? std::move(*(first1++)) : std::move(*(first2++))); }; @@ -232,7 +231,7 @@ static Iter2_t merge_half(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, if (buf1 == end_buf1) return end_buf2; if (buf2 == end_buf2) return move_forward(buf_out, buf1, end_buf1); - if (not comp(*buf2, *(end_buf1 - 1))) + if (! comp(*buf2, *(end_buf1 - 1))) { move_forward(buf_out, buf1, end_buf1); return end_buf2; @@ -244,9 +243,9 @@ static Iter2_t merge_half(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, return move_forward(mid, buf1, end_buf1); }; }; - while ((buf1 != end_buf1) and (buf2 != end_buf2)) + while ((buf1 != end_buf1) && (buf2 != end_buf2)) { - *(buf_out++) = (not comp(*buf2, *buf1)) ? + *(buf_out++) = (! comp(*buf2, *buf1)) ? std::move(*(buf1++)) : std::move(*(buf2++)); }; return (buf2 == end_buf2)? move_forward(buf_out, buf1, end_buf1) : end_buf2; @@ -295,7 +294,7 @@ static Iter2_t merge_half_backward(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, if (buf1 == end_buf1) return here::move_backward(end_buf_out, buf2, end_buf2); - if (not comp(*buf2, *(end_buf1 - 1))) + if (! comp(*buf2, *(end_buf1 - 1))) { here::move_backward(end_buf_out, buf2, end_buf2); return buf1; @@ -307,10 +306,10 @@ static Iter2_t merge_half_backward(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, return here::move_backward(mid, buf2, end_buf2); }; }; - while ((buf1 != end_buf1) and (buf2 != end_buf2)) + while ((buf1 != end_buf1) && (buf2 != end_buf2)) { *(--end_buf_out) = - (not comp(*(end_buf2 - 1), *(end_buf1 - 1))) ? + (! comp(*(end_buf2 - 1), *(end_buf1 - 1))) ? std::move(*(--end_buf2)): std::move(*(--end_buf1)); }; @@ -352,19 +351,19 @@ static bool merge_uncontiguous(Iter1_t src1, const Iter1_t end_src1, //------------------------------------------------------------------------- // Code //------------------------------------------------------------------------- - if (src1 == end_src1 or src2 == end_src2 - or not comp(*src2, *(end_src1 - 1))) return true; + if (src1 == end_src1 || src2 == end_src2 + || ! comp(*src2, *(end_src1 - 1))) return true; - while (src1 != end_src1 and not comp(*src2, *src1)) + while (src1 != end_src1 && ! comp(*src2, *src1)) ++src1; Iter3_t const end_aux = aux + (end_src1 - src1); Iter2_t src2_first = src2; move_forward(aux, src1, end_src1); - while ((src1 != end_src1) and (src2 != end_src2)) + while ((src1 != end_src1) && (src2 != end_src2)) { - *(src1++) = std::move((not comp(*src2, *aux)) ? *(aux++) : *(src2++)); + *(src1++) = std::move((! comp(*src2, *aux)) ? *(aux++) : *(src2++)); } if (src2 == end_src2) @@ -409,11 +408,11 @@ static bool merge_contiguous(Iter1_t src1, Iter1_t src2, Iter1_t end_src2, //------------------------------------------------------------------------- // Code //------------------------------------------------------------------------- - if (src1 == src2 or src2 == end_src2 or not comp(*src2, *(src2 - 1))) + if (src1 == src2 || src2 == end_src2 || ! comp(*src2, *(src2 - 1))) return true; Iter1_t end_src1 = src2; - while (src1 != end_src1 and not comp(*src2, *src1)) + while (src1 != end_src1 && ! comp(*src2, *src1)) ++src1; if (src1 == end_src1) return false; @@ -460,7 +459,7 @@ static bool merge_circular(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, assert ( circ.free_size() >= size_t ((end_buf1-buf1) + (end_buf2-buf2))); #endif - if (not comp(*buf2, *(end_buf1 - 1))) + if (! comp(*buf2, *(end_buf1 - 1))) { circ.push_move_back(buf1, (end_buf1 - buf1)); it1_out = end_buf1; @@ -474,7 +473,7 @@ static bool merge_circular(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, it2_out = end_buf2; return false; } - while (buf1 != end_buf1 and buf2 != end_buf2) + while (buf1 != end_buf1 && buf2 != end_buf2) { circ.push_back(comp(*buf2, *buf1) ? std::move(*(buf2++)) : std::move(*(buf1++))); diff --git a/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp b/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp index 340b9ff..ea1155f 100644 --- a/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp +++ b/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp @@ -13,7 +13,6 @@ #ifndef __BOOST_SORT_FLAT_STABLE_SORT_HPP #define __BOOST_SORT_FLAT_STABLE_SORT_HPP -#include #include #include #include @@ -110,9 +109,10 @@ class flat_stable_sort: public bsc::merge_block //---------------------------------------------------------------------------- // //------------------------------------------------------------------------ -// function : -/// @brief : -/// @param Pos : +// @fn divide +/// @brief Divide a big list of blocks in two parts to be sorted and merged +/// @param itx_first iterator to the first element in the index +/// @param itx_last itarator to to the after the last element in the index /// @return //------------------------------------------------------------------------ template @@ -135,18 +135,17 @@ ::divide(it_index itx_first, it_index itx_last) }; // //------------------------------------------------------------------------ -// function : sort_small -/// @brief : -/// @param -/// @param -/// @param +// @fn sort_small +/// @brief sort an small number of blocks +/// @param itx_first iterator to the first element in the index +/// @param itx_last itarator to to the after the last element in the index //------------------------------------------------------------------------ template void flat_stable_sort ::sort_small(it_index itx_first, it_index itx_last) { size_t nblock = size_t(itx_last - itx_first); - assert(nblock > 0 and nblock < 5); + assert(nblock > 0 && nblock < 5); value_t *paux = ptr_circ->get_buffer(); range_it rng_data = get_group_range(*itx_first, nblock); @@ -172,7 +171,7 @@ ::sort_small(it_index itx_first, it_index itx_last) }; // //------------------------------------------------------------------------ -// function : is_sorted_forward +// @fn is_sorted_forward /// @brief : return if the data are ordered, /// @param itx_first : iterator to the first block in the index /// @param itx_last : iterator to the last block in the index @@ -213,7 +212,7 @@ ::is_sorted_forward(it_index itx_first, it_index itx_last) }; // //------------------------------------------------------------------------ -// function : is_sorted_backward +// @fn is_sorted_backward /// @brief : return if the data are ordered, /// @param itx_first : iterator to the first block in the index /// @param itx_last : iterator to the last block in the index @@ -260,7 +259,7 @@ namespace bscu = boost::sort::common::util; namespace flat = boost::sort::flat_internal; // ///--------------------------------------------------------------------------- -// function flat_stable_sort +// @fn flat_stable_sort /// @brief This class is select the block size in the block_indirect_sort /// algorithm depending of the type and size of the data to sort /// @@ -285,7 +284,7 @@ struct block_size_fss // ///--------------------------------------------------------------------------- -// function flat_stable_sort +// @fn flat_stable_sort /// @brief This class is select the block size in the flat_stable_sort /// algorithm depending of the type and size of the data to sort /// diff --git a/include/boost/sort/insert_sort/insert_sort.hpp b/include/boost/sort/insert_sort/insert_sort.hpp index e7fe6f6..068c1cf 100644 --- a/include/boost/sort/insert_sort/insert_sort.hpp +++ b/include/boost/sort/insert_sort/insert_sort.hpp @@ -13,7 +13,6 @@ #ifndef __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP #define __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP -#include #include #include #include @@ -51,7 +50,7 @@ static void insert_sort (Iter_t first, Iter_t last, value_t Aux = std::move (*it_examine); Iter_t it_insertion = it_examine; - while (it_insertion != first and comp (Aux, *(it_insertion - 1))) + while (it_insertion != first && comp (Aux, *(it_insertion - 1))) { *it_insertion = std::move (*(it_insertion - 1)); --it_insertion; From 61f794f6b2285b6a7d9a96acf58ce42e54428e9b Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Mon, 11 Mar 2024 08:38:17 -0500 Subject: [PATCH 02/21] Make the library modular usable. --- build.jam | 25 +++++++++++++++++++++++++ Jamfile.v2 => example/Jamfile.v2 | 5 ++++- test/Jamfile.v2 | 6 +++++- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 build.jam rename Jamfile.v2 => example/Jamfile.v2 (91%) diff --git a/build.jam b/build.jam new file mode 100644 index 0000000..90053df --- /dev/null +++ b/build.jam @@ -0,0 +1,25 @@ +# Copyright René Ferdinand Rivera Morell 2023 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import project ; + +project /boost/sort + : common-requirements + /boost/config//boost_config + /boost/core//boost_core + /boost/range//boost_range + /boost/static_assert//boost_static_assert + /boost/type_traits//boost_type_traits + include + ; + +explicit + [ alias boost_sort ] + [ alias all : boost_sort example test ] + ; + +call-if + : boost-library sort + ; diff --git a/Jamfile.v2 b/example/Jamfile.v2 similarity index 91% rename from Jamfile.v2 rename to example/Jamfile.v2 index da650b3..881d12e 100644 --- a/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -11,7 +11,10 @@ if --tune in [ modules.peek : ARGV ] properties = . release ; } -project spreadsort : source-location example : requirements ../.. ../../.. $(properties) ; +project : requirements $(properties) + /boost/algorithm//boost_algorithm + /boost/random//boost_random + ; exe spreadsort : sample.cpp ; exe alreadysorted : alreadysorted.cpp ; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1d581a8..9b8fae3 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -7,9 +7,13 @@ # # See http://www.boost.org/libs/sort for library home page. -import ../../config/checks/config : requires ; +import config : requires ; import testing ; +project : requirements + /boost/test//boost_test_exec_monitor + ; + { test-suite "sort" : [ run integer_sort_test.cpp From 05c52551f946b66add20b97ba6a816cf3649bea6 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Fri, 29 Mar 2024 21:15:59 -0500 Subject: [PATCH 03/21] Switch to library requirements instead of source. As source puts extra source in install targets. --- build.jam | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.jam b/build.jam index 90053df..99dba63 100644 --- a/build.jam +++ b/build.jam @@ -7,11 +7,11 @@ import project ; project /boost/sort : common-requirements - /boost/config//boost_config - /boost/core//boost_core - /boost/range//boost_range - /boost/static_assert//boost_static_assert - /boost/type_traits//boost_type_traits + /boost/config//boost_config + /boost/core//boost_core + /boost/range//boost_range + /boost/static_assert//boost_static_assert + /boost/type_traits//boost_type_traits include ; From b961352925b8c3f5a2ac475f2a77236668b6091f Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 4 May 2024 23:32:35 -0500 Subject: [PATCH 04/21] Add missing import-search for cconfig/predef checks. --- test/Jamfile.v2 | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 9b8fae3..933f27c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -7,6 +7,7 @@ # # See http://www.boost.org/libs/sort for library home page. +import-search /boost/config/checks ; import config : requires ; import testing ; From 52228ac8e10113077a7e9383016916e9f530e3b6 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sun, 5 May 2024 09:00:01 -0500 Subject: [PATCH 05/21] Add requires-b2 check to top-level build file. --- build.jam | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.jam b/build.jam index 99dba63..187f518 100644 --- a/build.jam +++ b/build.jam @@ -3,6 +3,8 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +require-b2 5.1 ; + import project ; project /boost/sort From e3adb39c6471c1c1ca929236ac1c342f02f0bf2f Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Fri, 14 Jun 2024 11:33:56 -0500 Subject: [PATCH 06/21] Bump B2 require to 5.2 --- build.jam | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.jam b/build.jam index 187f518..4970081 100644 --- a/build.jam +++ b/build.jam @@ -3,9 +3,7 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -require-b2 5.1 ; - -import project ; +require-b2 5.2 ; project /boost/sort : common-requirements From 65bc508b76ef960a09da1f72edb1123b3c91ec17 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 20 Jul 2024 21:25:44 -0500 Subject: [PATCH 07/21] Change all references to . --- example/Jamfile.v2 | 4 ++-- test/Jamfile.v2 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 881d12e..d088ffc 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -12,8 +12,8 @@ if --tune in [ modules.peek : ARGV ] } project : requirements $(properties) - /boost/algorithm//boost_algorithm - /boost/random//boost_random + /boost/algorithm//boost_algorithm + /boost/random//boost_random ; exe spreadsort : sample.cpp ; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 933f27c..56b4226 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,7 +12,7 @@ import config : requires ; import testing ; project : requirements - /boost/test//boost_test_exec_monitor + /boost/test//boost_test_exec_monitor ; { From e6f9ca6ef8eef413df8c97d1a488d3a68dc1b399 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 20 Jul 2024 22:52:05 -0500 Subject: [PATCH 08/21] Update copyright dates. --- build.jam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.jam b/build.jam index 4970081..d1ec57f 100644 --- a/build.jam +++ b/build.jam @@ -1,4 +1,4 @@ -# Copyright René Ferdinand Rivera Morell 2023 +# Copyright René Ferdinand Rivera Morell 2023-2024 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) From 968b47368013f8392a232a53bd1f3202bcb65bce Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Tue, 23 Jul 2024 22:34:24 -0500 Subject: [PATCH 09/21] Move inter-lib dependencies to a project variable and into the build targets. --- build.jam | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build.jam b/build.jam index d1ec57f..45f2631 100644 --- a/build.jam +++ b/build.jam @@ -5,21 +5,24 @@ require-b2 5.2 ; +constant boost_dependencies : + /boost/config//boost_config + /boost/core//boost_core + /boost/range//boost_range + /boost/static_assert//boost_static_assert + /boost/type_traits//boost_type_traits ; + project /boost/sort : common-requirements - /boost/config//boost_config - /boost/core//boost_core - /boost/range//boost_range - /boost/static_assert//boost_static_assert - /boost/type_traits//boost_type_traits include ; explicit - [ alias boost_sort ] + [ alias boost_sort : : : : $(boost_dependencies) ] [ alias all : boost_sort example test ] ; call-if : boost-library sort ; + From 9640167bf88dcd2577dad60ae0ebf6f342157b2b Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 10:05:33 -0500 Subject: [PATCH 10/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 224 ++++++--------------------------------- 1 file changed, 34 insertions(+), 190 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 368d074..7b6aa4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,200 +17,44 @@ jobs: fail-fast: false matrix: include: - - name: "TOOLSET=gcc CXXSTD=03,11 Job 0" - buildtype: "boost" - packages: "" - packages_to_remove: "" - os: "ubuntu-20.04" - container: "ubuntu:16.04" - cxx: "g++" - sources: "" - llvm_os: "" - llvm_ver: "" - toolset: "gcc" - cxxstd: "03,11" - - name: "TOOLSET=clang CXXSTD=03,11,14,1z Job 1" - buildtype: "boost" - packages: "libstdc++-4.9-dev clang" - packages_to_remove: "" - os: "ubuntu-20.04" - container: "ubuntu:16.04" - cxx: "clang++" - sources: "" - llvm_os: "" - llvm_ver: "" + - name: "g++13" + os: ubuntu-latest + packages: "g++-13" + toolset: "gcc-13" + - name: "clang-17" + os: ubuntu-latest + packages: "clang-17" + toolset: "clang-17" + - name: "xcode" + os: macos-latest toolset: "clang" - cxxstd: "03,11,14,1z" - - runs-on: ${{ matrix.os }} - container: ${{ matrix.container }} - + runs-on: ${{matrix.os}} steps: - - name: Check if running in container - if: matrix.container != '' - run: echo "GHA_CONTAINER=${{ matrix.container }}" >> $GITHUB_ENV - - name: If running in container, upgrade packages - if: matrix.container != '' - run: | - apt-get -o Acquire::Retries=3 update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && apt-get -o Acquire::Retries=3 install -y sudo software-properties-common wget curl apt-transport-https make apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf automake g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3 ccache libpython-dev - sudo apt-add-repository ppa:git-core/ppa - sudo apt-get -o Acquire::Retries=3 update && apt-get -o Acquire::Retries=3 -y install git - python_version=$(python3 -c 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))') - sudo wget https://bootstrap.pypa.io/pip/$python_version/get-pip.py - sudo python3 get-pip.py - sudo /usr/local/bin/pip install cmake - - - uses: actions/checkout@v2 - - - name: linux - shell: bash - env: - CXX: ${{ matrix.cxx }} - SOURCES: ${{ matrix.sources }} - LLVM_OS: ${{ matrix.llvm_os }} - LLVM_VER: ${{ matrix.llvm_ver }} - PACKAGES: ${{ matrix.packages }} - PACKAGES_TO_REMOVE: ${{ matrix.packages_to_remove }} - JOB_BUILDTYPE: ${{ matrix.buildtype }} - TOOLSET: ${{ matrix.toolset }} - CXXSTD: ${{ matrix.cxxstd }} - TRAVIS_BRANCH: ${{ github.base_ref }} - TRAVIS_OS_NAME: "linux" + - uses: actions/checkout@main + - name: Install + if: matrix.packages + run: sudo apt install ${{matrix.packages}} + - name: Setup run: | - echo '==================================> SETUP' - echo '==================================> PACKAGES' - set -e - if [ -n "$PACKAGES_TO_REMOVE" ]; then sudo apt-get purge -y $PACKAGES_TO_REMOVE; fi - echo ">>>>> APT: REPO.." - for i in {1..3}; do sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test" && break || sleep 2; done - - if test -n "${LLVM_OS}" ; then - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - if test -n "${LLVM_VER}" ; then - sudo -E apt-add-repository "deb http://apt.llvm.org/${LLVM_OS}/ llvm-toolchain-${LLVM_OS}-${LLVM_VER} main" - else - # Snapshot (i.e. trunk) build of clang - sudo -E apt-add-repository "deb http://apt.llvm.org/${LLVM_OS}/ llvm-toolchain-${LLVM_OS} main" - fi - fi - echo ">>>>> APT: UPDATE.." - sudo -E apt-get -o Acquire::Retries=3 update - if test -n "${SOURCES}" ; then - echo ">>>>> APT: INSTALL SOURCES.." - for SOURCE in $SOURCES; do - sudo -E apt-add-repository ppa:$SOURCE - done - fi - echo ">>>>> APT: INSTALL ${PACKAGES}.." - sudo -E DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=3 -y --no-install-suggests --no-install-recommends install ${PACKAGES} - - echo '==================================> INSTALL AND COMPILE' - set -e - export TRAVIS_BUILD_DIR=$(pwd) - export TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')} - export VCS_COMMIT_ID=$GITHUB_SHA - export GIT_COMMIT=$GITHUB_SHA - export REPO_NAME=$(basename $GITHUB_REPOSITORY) - export USER=$(whoami) - export CC=${CC:-gcc} - export PATH=~/.local/bin:/usr/local/bin:$PATH - - if [ "$JOB_BUILDTYPE" == "boost" ]; then - - echo '==================================> INSTALL' - - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true + echo GITHUB_BASE_REF: $GITHUB_BASE_REF + echo GITHUB_REF: $GITHUB_REF + REF=${GITHUB_BASE_REF:-$GITHUB_REF} + REF=${REF#refs/heads/} + echo REF: $REF + BOOST_BRANCH=develop && ( test "${GITHUB_REF_NAME}" == "master" || test "${GITHUB_REF_NAME}" == "modular" ) && BOOST_BRANCH=${GITHUB_REF_NAME} || true + BOOST_GIT=https://github.com/${GITHUB_REPOSITORY/sort/boost}.git + echo BOOST_GIT: ${BOOST_GIT} + echo BOOST_BRANCH: ${BOOST_BRANCH} cd .. - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root + git clone -b "${BOOST_BRANCH}" --depth 1 "${BOOST_GIT}" boost-root cd boost-root - git submodule update --init tools/build - git submodule update --init libs/config - git submodule update --init tools/boostdep - cp -r $TRAVIS_BUILD_DIR/* libs/sort - python tools/boostdep/depinst/depinst.py sort + git submodule update --init --jobs 3 tools/boostdep libs/assert libs/config libs/core libs/sort + python tools/boostdep/depinst/depinst.py -X test -g "--jobs 3" sort + rm -rf libs/sort/* + cp -r $GITHUB_WORKSPACE/* libs/sort ./bootstrap.sh - ./b2 headers - - echo '==================================> SCRIPT' - - ./b2 libs/sort/test toolset=$TOOLSET cxxstd=$CXXSTD - - fi - osx: - strategy: - fail-fast: false - matrix: - include: - - name: "TOOLSET=clang CXXSTD=03,11,14,1z Job 2" - buildtype: "boost" - packages: "" - os: "macos-12" - cxx: "clang++" - sources: "" - llvm_os: "" - llvm_ver: "" - xcode_version: 14.2 - toolset: "clang" - cxxstd: "03,11,14,1z" - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v2 - - - name: Set DEVELOPER_DIR - if: matrix.xcode_version != '' - run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer" >> $GITHUB_ENV - - name: Test DEVELOPER_DIR - run: echo $DEVELOPER_DIR - - - name: "osx" - shell: bash - env: - CXX: ${{ matrix.cxx }} - SOURCES: ${{ matrix.sources }} - LLVM_OS: ${{ matrix.llvm_os }} - LLVM_VER: ${{ matrix.llvm_ver }} - PACKAGES: ${{ matrix.packages }} - JOB_BUILDTYPE: ${{ matrix.buildtype }} - TOOLSET: ${{ matrix.toolset }} - CXXSTD: ${{ matrix.cxxstd }} - TRAVIS_BRANCH: ${{ github.base_ref }} - TRAVIS_OS_NAME: "osx" + ./b2 -d0 headers + - name: Test run: | - echo '==================================> SETUP' - set -e - sudo mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools.bck - echo '==================================> PACKAGES' - echo '==================================> INSTALL AND COMPILE' - set -e - export TRAVIS_BUILD_DIR=$(pwd) - export TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')} - export VCS_COMMIT_ID=$GITHUB_SHA - export GIT_COMMIT=$GITHUB_SHA - export REPO_NAME=$(basename $GITHUB_REPOSITORY) - export USER=$(whoami) - export CC=${CC:-gcc} - export PATH=~/.local/bin:/usr/local/bin:$PATH - - if [ "$JOB_BUILDTYPE" == "boost" ]; then - - echo '==================================> INSTALL' - - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true - cd .. - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root - cd boost-root - git submodule update --init tools/build - git submodule update --init libs/config - git submodule update --init tools/boostdep - cp -r $TRAVIS_BUILD_DIR/* libs/sort - python tools/boostdep/depinst/depinst.py sort - ./bootstrap.sh - ./b2 headers - - echo '==================================> SCRIPT' - - ./b2 libs/sort/test toolset=$TOOLSET cxxstd=$CXXSTD - - fi + cd ../boost-root + ./b2 -j3 libs/sort/test toolset=${{matrix.toolset}} cxxstd=11,14,17,20 From d1d38301a465edc43af79cce09922c5e66ca8a70 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 10:12:13 -0500 Subject: [PATCH 11/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b6aa4a..59df5a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: fail-fast: false matrix: include: - - name: "g++13" + - name: "g++-13" os: ubuntu-latest packages: "g++-13" toolset: "gcc-13" @@ -33,7 +33,10 @@ jobs: - uses: actions/checkout@main - name: Install if: matrix.packages - run: sudo apt install ${{matrix.packages}} + run: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y + sudo apt-get -o Acquire::Retries=3 update -y + sudo apt-get -o Acquire::Retries=3 -y install ${{matrix.packages}} - name: Setup run: | echo GITHUB_BASE_REF: $GITHUB_BASE_REF @@ -48,7 +51,7 @@ jobs: cd .. git clone -b "${BOOST_BRANCH}" --depth 1 "${BOOST_GIT}" boost-root cd boost-root - git submodule update --init --jobs 3 tools/boostdep libs/assert libs/config libs/core libs/sort + git submodule update --init --jobs 3 tools/boostdep libs/assert libs/config libs/core libs/test libs/sort python tools/boostdep/depinst/depinst.py -X test -g "--jobs 3" sort rm -rf libs/sort/* cp -r $GITHUB_WORKSPACE/* libs/sort From 61b3613abced857ac034867db1b96deccd67d787 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 10:13:17 -0500 Subject: [PATCH 12/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59df5a5..38de644 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,10 @@ jobs: os: ubuntu-latest packages: "g++-13" toolset: "gcc-13" - - name: "clang-17" + - name: "clang-16" os: ubuntu-latest - packages: "clang-17" - toolset: "clang-17" + packages: "clang-16" + toolset: "clang-16" - name: "xcode" os: macos-latest toolset: "clang" From 5da7ff37ed6ac414481616c67181852ab80f1d8e Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 10:15:05 -0500 Subject: [PATCH 13/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38de644..110a885 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,7 @@ jobs: git clone -b "${BOOST_BRANCH}" --depth 1 "${BOOST_GIT}" boost-root cd boost-root git submodule update --init --jobs 3 tools/boostdep libs/assert libs/config libs/core libs/test libs/sort + python tools/boostdep/depinst/depinst.py -X test -g "--jobs 3" test python tools/boostdep/depinst/depinst.py -X test -g "--jobs 3" sort rm -rf libs/sort/* cp -r $GITHUB_WORKSPACE/* libs/sort From 5827c482355fde79ade207094382bbaa33a1e094 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 10:51:29 -0500 Subject: [PATCH 14/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 110a885..1b87c82 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,10 @@ jobs: os: ubuntu-latest packages: "g++-13" toolset: "gcc-13" - - name: "clang-16" + - name: "clang-18" os: ubuntu-latest - packages: "clang-16" - toolset: "clang-16" + packages: "llvm-toolchain-18" + toolset: "clang-18" - name: "xcode" os: macos-latest toolset: "clang" From c3294fcce902c947a4a00b0f4f7752c1ab284548 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 11:03:57 -0500 Subject: [PATCH 15/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b87c82..dbb3014 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: toolset: "gcc-13" - name: "clang-18" os: ubuntu-latest - packages: "llvm-toolchain-18" + packages: "llvm-18" toolset: "clang-18" - name: "xcode" os: macos-latest From f07ab48f1d6ca08e59524e371fa2a5b8860d12f2 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 11:06:43 -0500 Subject: [PATCH 16/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbb3014..3d99b7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,10 @@ jobs: os: ubuntu-latest packages: "g++-13" toolset: "gcc-13" - - name: "clang-18" + - name: "clang-15" os: ubuntu-latest - packages: "llvm-18" - toolset: "clang-18" + packages: "llvm-toolchain-15" + toolset: "clang-15" - name: "xcode" os: macos-latest toolset: "clang" From 8a2c4b655d18438b896db79835ab0404e9c9630a Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 11:19:44 -0500 Subject: [PATCH 17/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d99b7a..b20576c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: toolset: "gcc-13" - name: "clang-15" os: ubuntu-latest - packages: "llvm-toolchain-15" + packages: "clang-15" toolset: "clang-15" - name: "xcode" os: macos-latest From c99bf6a41e7c2b4a10f3ae24a3cb2e9cedb2b367 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 11:20:38 -0500 Subject: [PATCH 18/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b20576c..dc298f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,6 @@ jobs: - name: Install if: matrix.packages run: | - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo apt-get -o Acquire::Retries=3 update -y sudo apt-get -o Acquire::Retries=3 -y install ${{matrix.packages}} - name: Setup From b4fadedfcfdfbf2d885793deb2b7125d05a3bcbb Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sat, 3 Aug 2024 11:33:46 -0500 Subject: [PATCH 19/21] Try and fix GHA setup. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc298f8..b20576c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: - name: Install if: matrix.packages run: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y sudo apt-get -o Acquire::Retries=3 update -y sudo apt-get -o Acquire::Retries=3 -y install ${{matrix.packages}} - name: Setup From df2e184e142579e212f51b94f948145bd3f9cdd3 Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Sat, 26 Aug 2023 16:48:00 +1000 Subject: [PATCH 20/21] Remove unnecessary semicolons for gcc --pedantic mode --- .../blk_detail/backbone.hpp | 20 ++--- .../block_indirect_sort/blk_detail/block.hpp | 28 +++--- .../blk_detail/merge_blocks.hpp | 46 +++++----- .../blk_detail/move_blocks.hpp | 26 +++--- .../blk_detail/parallel_sort.hpp | 24 +++--- .../block_indirect_sort.hpp | 38 ++++---- include/boost/sort/common/stack_cnc.hpp | 10 +-- include/boost/sort/common/util/algorithm.hpp | 28 +++--- include/boost/sort/common/util/atomic.hpp | 20 ++--- .../sort/common/util/circular_buffer.hpp | 86 +++++++++---------- include/boost/sort/common/util/insert.hpp | 16 ++-- include/boost/sort/common/util/merge.hpp | 58 ++++++------- include/boost/sort/common/util/search.hpp | 52 +++++------ include/boost/sort/common/util/traits.hpp | 8 +- 14 files changed, 230 insertions(+), 230 deletions(-) diff --git a/include/boost/sort/block_indirect_sort/blk_detail/backbone.hpp b/include/boost/sort/block_indirect_sort/blk_detail/backbone.hpp index df98efc..19e7f94 100644 --- a/include/boost/sort/block_indirect_sort/blk_detail/backbone.hpp +++ b/include/boost/sort/block_indirect_sort/blk_detail/backbone.hpp @@ -107,7 +107,7 @@ struct backbone block_t get_block (size_t pos) const { return block_t (global_range.first + (pos * Block_size)); - }; + } //------------------------------------------------------------------------- // function : get_range /// @brief obtain the range in the position pos @@ -120,7 +120,7 @@ struct backbone Iter_t it2 = (pos == (nblock - 1)) ? global_range.last : it1 + Block_size; return range_it (it1, it2); - }; + } //------------------------------------------------------------------------- // function : get_range_buf /// @brief obtain the auxiliary buffer of the thread @@ -128,7 +128,7 @@ struct backbone range_buf get_range_buf ( ) const { return range_buf (buf, buf + Block_size); - }; + } //------------------------------------------------------------------------- // function : exec @@ -144,7 +144,7 @@ struct backbone { buf = ptr_buf; exec (counter); - }; + } void exec (atomic_t &counter); @@ -192,7 +192,7 @@ ::backbone (Iter_t first, Iter_t last, Compare comp) range_tail.first = (ntail == 0) ? last : (first + ((nblock - 1) * Block_size)); range_tail.last = last; -}; +} // //------------------------------------------------------------------------- // function : exec @@ -208,12 +208,12 @@ void backbone< Block_size, Iter_t, Compare >::exec (atomic_t &counter) { if (works.pop_move_back (func_exec)) func_exec ( ); else std::this_thread::yield ( ); - }; -}; + } +} // //**************************************************************************** -}; // End namespace blk_detail -}; // End namespace sort -}; // End namespace boost +} // End namespace blk_detail +} // End namespace sort +} // End namespace boost //**************************************************************************** #endif diff --git a/include/boost/sort/block_indirect_sort/blk_detail/block.hpp b/include/boost/sort/block_indirect_sort/blk_detail/block.hpp index c7a2571..b9a353e 100644 --- a/include/boost/sort/block_indirect_sort/blk_detail/block.hpp +++ b/include/boost/sort/block_indirect_sort/blk_detail/block.hpp @@ -44,7 +44,7 @@ class block_pos public: //----------------------------- FUNCTIONS ------------------------------ - block_pos (void) : num (0){}; + block_pos (void) : num (0){} // //------------------------------------------------------------------------- // function : block_pos @@ -55,35 +55,35 @@ class block_pos block_pos (size_t position, bool side = false) { num = (position << 1) + ((side) ? 1 : 0); - }; + } // //------------------------------------------------------------------------- // function : pos /// @brief obtain the position stored inside the block_pos /// @return position //------------------------------------------------------------------------- - size_t pos (void) const { return (num >> 1); }; + size_t pos (void) const { return (num >> 1); } // //------------------------------------------------------------------------- // function : pos /// @brief store a position inside the block_pos /// @param position : value to store //------------------------------------------------------------------------- - void set_pos (size_t position) { num = (position << 1) + (num & 1); }; + void set_pos (size_t position) { num = (position << 1) + (num & 1); } // //------------------------------------------------------------------------- // function : side /// @brief obtain the side stored inside the block_pos /// @return bool value //------------------------------------------------------------------------- - bool side (void) const { return ((num & 1) != 0); }; + bool side (void) const { return ((num & 1) != 0); } // //------------------------------------------------------------------------- // function : side /// @brief store a bool value the block_pos /// @param sd : bool value to store //------------------------------------------------------------------------- - void set_side (bool sd) { num = (num & ~1) + ((sd) ? 1 : 0); }; + void set_side (bool sd) { num = (num & ~1) + ((sd) ? 1 : 0); } }; // end struct block_pos // @@ -105,7 +105,7 @@ struct block /// @brief constructor from an iterator to the first element of the block /// @param it : iterator to the first element of the block //------------------------------------------------------------------------- - block (Iter_t it) : first (it){}; + block (Iter_t it) : first (it){} //------------------------------------------------------------------------- // function : get_range @@ -115,7 +115,7 @@ struct block range< Iter_t > get_range (void) { return range_it (first, first + Block_size); - }; + } }; // end struct block @@ -133,7 +133,7 @@ bool compare_block (block< Block_size, Iter_t > block1, Compare cmp = Compare ( )) { return cmp (*block1.first, *block2.first); -}; +} // ///--------------------------------------------------------------------------- /// @struct compare_block_pos @@ -155,7 +155,7 @@ struct compare_block_pos /// @param cmp : comparison operator //------------------------------------------------------------------------- compare_block_pos (Iter_t g_first, Compare cmp) - : global_first (g_first), comp (cmp){}; + : global_first (g_first), comp (cmp){} // //------------------------------------------------------------------------- // function : operator () @@ -168,14 +168,14 @@ struct compare_block_pos { return comp (*(global_first + (block_pos1.pos ( ) * Block_size)), *(global_first + (block_pos2.pos ( ) * Block_size))); - }; + } }; // end struct compare_block_pos //**************************************************************************** -}; // End namespace blk_detail -}; // End namespace sort -}; // End namespace boost +} // End namespace blk_detail +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/block_indirect_sort/blk_detail/merge_blocks.hpp b/include/boost/sort/block_indirect_sort/blk_detail/merge_blocks.hpp index 8f260a5..0517401 100644 --- a/include/boost/sort/block_indirect_sort/blk_detail/merge_blocks.hpp +++ b/include/boost/sort/block_indirect_sort/blk_detail/merge_blocks.hpp @@ -108,7 +108,7 @@ struct merge_blocks catch (std::bad_alloc &) { error = true; - }; + } } bscu::atomic_sub (counter, 1); }; @@ -143,7 +143,7 @@ struct merge_blocks catch (std::bad_alloc &) { error = true; - }; + } } bscu::atomic_sub (counter, 1); }; @@ -195,12 +195,12 @@ ::merge_blocks( backbone_t &bkb, size_t pos_index1, size_t pos_index2, for (size_t i = pos_index1; i < pos_index2; ++i) { vpos1.emplace_back(bk.index[i].pos(), true); - }; + } for (size_t i = pos_index2; i < pos_index3; ++i) { vpos2.emplace_back(bk.index[i].pos(), false); - }; + } //------------------------------------------------------------------- // tail process //------------------------------------------------------------------- @@ -210,7 +210,7 @@ ::merge_blocks( backbone_t &bkb, size_t pos_index1, size_t pos_index2, tail_process(vpos1, vpos2); nblock1 = vpos1.size(); nblock2 = vpos2.size(); - }; + } compare_block_pos_t cmp_blk(bk.global_range.first, bk.cmp); if (bk.error) return; @@ -256,9 +256,9 @@ ::tail_process( std::vector &vblkpos1, { vblkpos2.emplace_back(posback1, false); vblkpos1.pop_back(); - }; - }; - }; + } + } + } } // @@ -278,7 +278,7 @@ ::cut_range(range_pos rng_input) { merge_range_pos(rng_input); return; - }; + } atomic_t counter(0); size_t npart = (rng_input.size() + Group_size - 1) / Group_size; @@ -294,7 +294,7 @@ ::cut_range(range_pos rng_input) and bk.index[pos - 1].side() == bk.index[pos].side()) { ++pos; - }; + } if (pos < pos_last) { merge_uncontiguous(bk.get_range(bk.index[pos - 1].pos()), @@ -306,9 +306,9 @@ ::cut_range(range_pos rng_input) { range_pos rng_aux(pos_ini, pos); function_merge_range_pos(rng_aux, counter, bk.error); - }; + } pos_ini = pos; - }; + } bk.exec(counter); // wait until finish all the ranges } @@ -337,7 +337,7 @@ ::merge_range_pos(range_pos rng_input) bsc::merge_flow(rng_prev, rbuf, rng_posx, bk.cmp); rng_prev = rng_posx; - }; + } move_forward(rng_posx, rbuf); } // @@ -384,7 +384,7 @@ ::extract_ranges(range_pos range_input) side_posx = bp_posx.side(); mergeable = (side_max != side_posx and is_mergeable(rng_max, rng_posx, bk.cmp)); - }; + } if (bk.error) return; if (final or not mergeable) { @@ -398,14 +398,14 @@ ::extract_ranges(range_pos range_input) else { function_merge_range_pos(rp_final, counter, bk.error); - }; - }; + } + } posx_ini = posx; if (not final) { rng_max = rng_posx; side_max = side_posx; - }; + } } else { @@ -413,16 +413,16 @@ ::extract_ranges(range_pos range_input) { rng_max = rng_posx; side_max = side_posx; - }; - }; - }; + } + } + } bk.exec(counter); } // //**************************************************************************** -}; // End namespace blk_detail -}; // End namespace sort -}; // End namespace boost +} // End namespace blk_detail +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp b/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp index 71a6488..e633e71 100644 --- a/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp +++ b/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp @@ -95,7 +95,7 @@ struct move_blocks catch (std::bad_alloc &) { error = true; - }; + } } bscu::atomic_sub (counter, 1); }; @@ -130,13 +130,13 @@ struct move_blocks catch (std::bad_alloc &) { error = true; - }; + } } bscu::atomic_sub (counter, 1); }; bk.works.emplace_back(f1); } - ; + //--------------------------------------------------------------------------- }; // end of struct move_blocks //--------------------------------------------------------------------------- @@ -172,7 +172,7 @@ ::move_blocks(backbone_t &bkb) : bk(bkb) and bk.index[pos_index_ini].pos() == pos_index_ini) { ++pos_index_ini; - }; + } if (pos_index_ini == bk.index.size()) break; @@ -187,7 +187,7 @@ ::move_blocks(backbone_t &bkb) : bk(bkb) bk.index[pos_index_dest].set_pos(pos_index_dest); pos_index_dest = pos_index_src; - }; + } bk.index[pos_index_dest].set_pos(pos_index_dest); vsequence.push_back(sequence); @@ -199,8 +199,8 @@ ::move_blocks(backbone_t &bkb) : bk(bkb) else { function_move_long_sequence(vsequence.back(), counter, bk.error); - }; - }; + } + } bk.exec(counter); } ; @@ -228,9 +228,9 @@ ::move_sequence(const std::vector &init_sequence) range_it range1(range2); range2 = bk.get_range(pos_range2); move_forward(range1, range2); - }; + } move_forward(range2, rbuf); -}; +} // //------------------------------------------------------------------------- // function : move_long_sequence @@ -264,7 +264,7 @@ ::move_long_sequence(const std::vector &init_sequence) sequence.assign(it_pos, it_pos + size_part); index_seq.emplace_back(*(it_pos + size_part - 1)); function_move_sequence(sequence, son_counter, bk.error); - }; + } sequence.assign(it_pos, init_sequence.end()); index_seq.emplace_back(init_sequence.back()); @@ -277,9 +277,9 @@ ::move_long_sequence(const std::vector &init_sequence) // //**************************************************************************** -}; // End namespace blk_detail -}; // End namespace sort -}; // End namespace boost +} // End namespace blk_detail +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/block_indirect_sort/blk_detail/parallel_sort.hpp b/include/boost/sort/block_indirect_sort/blk_detail/parallel_sort.hpp index 69dfa5b..afb7606 100644 --- a/include/boost/sort/block_indirect_sort/blk_detail/parallel_sort.hpp +++ b/include/boost/sort/block_indirect_sort/blk_detail/parallel_sort.hpp @@ -103,12 +103,12 @@ struct parallel_sort catch (std::bad_alloc &) { error = true; - }; - }; + } + } bscu::atomic_sub (counter, 1); }; bk.works.emplace_back(f1); - }; + } //-------------------------------------------------------------------------- };// end struct parallel_sort @@ -156,7 +156,7 @@ ::parallel_sort(backbone_t &bkbn, Iter_t first, Iter_t last) for (size_t i = 0; i < nelem2; ++i) swap(*(it1++), *(it2--)); return; - }; + } //-------------------max_per_thread --------------------------- uint32_t nbits_size = (nbits64(sizeof(value_t))) >> 1; @@ -170,12 +170,12 @@ ::parallel_sort(backbone_t &bkbn, Iter_t first, Iter_t last) { pdqsort(first, last, bk.cmp); return; - }; + } if (not bk.error) divide_sort(first, last, level); // wait until all the parts are finished bk.exec(counter); -}; +} //------------------------------------------------------------------------ // function : divide_sort @@ -201,7 +201,7 @@ ::divide_sort(Iter_t first, Iter_t last, uint32_t level) if (level == 0 or nelem < (max_per_thread)) { return pdqsort(first, last, bk.cmp); - }; + } //-------------------- pivoting ---------------------------------- pivot9(first, last, bk.cmp); @@ -218,7 +218,7 @@ ::divide_sort(Iter_t first, Iter_t last, uint32_t level) ++c_first; while (bk.cmp(val, *c_last)) --c_last; - }; + } swap(*first, *c_last); @@ -228,12 +228,12 @@ ::divide_sort(Iter_t first, Iter_t last, uint32_t level) // The first half is done by the same thread function_divide_sort(first, c_last, level - 1, counter, bk.error); -}; +} // //**************************************************************************** -};// End namespace blk_detail -};// End namespace sort -};// End namespace boost +} // End namespace blk_detail +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/block_indirect_sort/block_indirect_sort.hpp b/include/boost/sort/block_indirect_sort/block_indirect_sort.hpp index 5e03b28..331e7a6 100644 --- a/include/boost/sort/block_indirect_sort/block_indirect_sort.hpp +++ b/include/boost/sort/block_indirect_sort/block_indirect_sort.hpp @@ -144,10 +144,10 @@ struct block_indirect_sort { destroy(rglobal_buf); construct = false; - }; + } std::free (ptr); ptr = nullptr; - }; + } } // //------------------------------------------------------------------------ @@ -218,9 +218,9 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) { using std::swap; swap(*(it1++), *(it2--)); - }; + } return; - }; + } //---------------- check if only single thread ----------------------- size_t nthreadmax = nelem / (Block_size * Group_size) + 1; @@ -235,7 +235,7 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) //intro_sort (first, last, bk.cmp); pdqsort(first, last, bk.cmp); return; - }; + } //----------- creation of the temporary buffer -------------------- ptr = reinterpret_cast @@ -244,7 +244,7 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) { bk.error = true; throw std::bad_alloc(); - }; + } rglobal_buf = range_buf(ptr, ptr + (Block_size * nthread)); initialize(rglobal_buf, *first); @@ -255,7 +255,7 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) for (uint32_t i = 0; i < nthread; ++i) { vbuf[i] = ptr + (i * Block_size); - }; + } // Insert the first work in the stack bscu::atomic_write(counter, 1); @@ -280,7 +280,7 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) auto f1 = [&vbuf,i, this]( ) { bk.exec (vbuf[i], this->counter);}; vfuture[i] = std::async(std::launch::async, f1); - }; + } for (uint32_t i = 0; i < nthread; ++i) vfuture[i].get(); if (bk.error) throw std::bad_alloc(); @@ -290,7 +290,7 @@ ::block_indirect_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) destroy_all(); throw; } -}; +} // //----------------------------------------------------------------------------- // function : split_rage @@ -317,7 +317,7 @@ ::split_range(size_t pos_index1, size_t pos_index2, uint32_t level_thread) { pdqsort(first, last, bk.cmp); return; - }; + } size_t pos_index_mid = pos_index1 + (nblock >> 1); atomic_t son_counter(1); @@ -349,11 +349,11 @@ ::split_range(size_t pos_index1, size_t pos_index2, uint32_t level_thread) bk.works.emplace_back(f1); if (bk.error) return; parallel_sort_t(bk, first, mid); - }; + } bk.exec(son_counter); if (bk.error) return; merge_blocks_t(bk, pos_index1, pos_index_mid, pos_index2); -}; +} // //----------------------------------------------------------------------------- @@ -375,8 +375,8 @@ ::start_function(void) split_range(0, bk.nblock, level_thread - 1); if (bk.error) return; move_blocks_t k(bk); - }; -}; + } +} ///--------------------------------------------------------------------------- // function block_indirect_sort_call @@ -390,7 +390,7 @@ inline void block_indirect_sort_call(Iter_t first, Iter_t last, Compare cmp, uint32_t nthr) { block_indirect_sort<128, 128, Iter_t, Compare>(first, last, cmp, nthr); -}; +} template struct block_size @@ -415,11 +415,11 @@ inline void block_indirect_sort_call (Iter_t first, Iter_t last, Compare cmp, { block_indirect_sort )>::data, 64, Iter_t, Compare> (first, last, cmp, nthr); -}; +} // //**************************************************************************** -}; // End namespace blk_detail +} // End namespace blk_detail //**************************************************************************** // namespace bscu = boost::sort::common::util; @@ -503,8 +503,8 @@ void block_indirect_sort (Iter_t first, Iter_t last, Compare comp, } // //**************************************************************************** -}; // End namespace sort -}; // End namespace boost +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/stack_cnc.hpp b/include/boost/sort/common/stack_cnc.hpp index ca2039f..0121b74 100644 --- a/include/boost/sort/common/stack_cnc.hpp +++ b/include/boost/sort/common/stack_cnc.hpp @@ -73,7 +73,7 @@ class stack_cnc // function : stack_cnc /// @brief constructor //------------------------------------------------------------------------- - explicit stack_cnc(void): v_t() { }; + explicit stack_cnc(void): v_t() { } // //------------------------------------------------------------------------- @@ -86,7 +86,7 @@ class stack_cnc // function : ~stack_cnc /// @brief Destructor //------------------------------------------------------------------------- - virtual ~stack_cnc(void) { v_t.clear(); }; + virtual ~stack_cnc(void) { v_t.clear(); } //------------------------------------------------------------------------- // function : emplace_back @@ -137,8 +137,8 @@ class stack_cnc // end class stack_cnc //*************************************************************************** -};// end namespace common -};// end namespace sort -};// end namespace boost +} // end namespace common +} // end namespace sort +} // end namespace boost //*************************************************************************** #endif diff --git a/include/boost/sort/common/util/algorithm.hpp b/include/boost/sort/common/util/algorithm.hpp index abe2d99..d14fa8f 100644 --- a/include/boost/sort/common/util/algorithm.hpp +++ b/include/boost/sort/common/util/algorithm.hpp @@ -144,7 +144,7 @@ template inline void construct_object (Value_t *ptr, Args &&... args) { (::new (static_cast(ptr)) Value_t(std::forward< Args > (args)...)); -}; +} // //----------------------------------------------------------------------------- // function : destroy_object @@ -155,7 +155,7 @@ template inline void destroy_object(Value_t *ptr) { ptr->~Value_t(); -}; +} // //----------------------------------------------------------------------------- // function : initialize @@ -185,9 +185,9 @@ inline void initialize (Iter_t first, Iter_t last, Value_t & val) while (it2 != last) { construct_object(&(*(it2++)), std::move(*(it1++))); - }; + } val = std::move(*(last - 1)); -}; +} // //----------------------------------------------------------------------------- // function : move_forward @@ -216,8 +216,8 @@ inline Iter2_t move_forward (Iter2_t it_dest, Iter1_t first, Iter1_t last) { *it_dest++ = std::move(*first++); } return it_dest; +} -}; // //----------------------------------------------------------------------------- // function : move_backard @@ -244,7 +244,7 @@ inline Iter2_t move_backward(Iter2_t it_dest, Iter1_t first, Iter1_t last) { *(--it_dest) = std::move (*(--last)); } return it_dest; -}; +} // //----------------------------------------------------------------------------- @@ -271,9 +271,9 @@ inline Value_t * move_construct(Value_t *ptr, Iter_t first, Iter_t last) while (first != last) { ::new (static_cast(ptr++)) Value_t(std::move(*(first++))); - }; + } return ptr; -}; +} // //----------------------------------------------------------------------------- // function : destroy @@ -286,7 +286,7 @@ inline void destroy(Iter_t first, const Iter_t last) { while (first != last) destroy_object(&(*(first++))); -}; +} // //----------------------------------------------------------------------------- // function : reverse @@ -298,13 +298,13 @@ template inline void reverse(Iter_t first, Iter_t last) { std::reverse ( first, last); -}; +} // //**************************************************************************** -};// End namespace util -};// End namespace common -};// End namespace sort -};// End namespace boost +} // End namespace util +} // End namespace common +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/util/atomic.hpp b/include/boost/sort/common/util/atomic.hpp index 00af766..ac5d5b4 100644 --- a/include/boost/sort/common/util/atomic.hpp +++ b/include/boost/sort/common/util/atomic.hpp @@ -35,7 +35,7 @@ template inline T atomic_read(std::atomic &at_var) { return std::atomic_load_explicit < T > (&at_var, std::memory_order_acquire); -}; +} // //----------------------------------------------------------------------------- // function : atomic_add @@ -50,7 +50,7 @@ inline T atomic_add(std::atomic &at_var, T2 num) static_assert (std::is_integral< T2 >::value, "Bad parameter"); return std::atomic_fetch_add_explicit (&at_var, (T) num, std::memory_order_acq_rel); -}; +} // //----------------------------------------------------------------------------- // function : atomic_sub @@ -65,7 +65,7 @@ inline T atomic_sub(std::atomic &at_var, T2 num) static_assert (std::is_integral< T2 >::value, "Bad parameter"); return std::atomic_fetch_sub_explicit (&at_var, (T) num, std::memory_order_acq_rel); -}; +} // //----------------------------------------------------------------------------- // function : atomic_write @@ -79,21 +79,21 @@ inline void atomic_write(std::atomic &at_var, T2 num) static_assert (std::is_integral< T2 >::value, "Bad parameter"); std::atomic_store_explicit (&at_var, (T) num, std::memory_order_release); -}; +} template struct counter_guard { typedef std::atomic atomic_t; atomic_t &count; - counter_guard(atomic_t & counter): count(counter) { }; - ~counter_guard() {atomic_sub(count, 1); }; + counter_guard(atomic_t & counter): count(counter) { } + ~counter_guard() {atomic_sub(count, 1); } }; // //**************************************************************************** -};// End namespace util -};// End namespace common -};// End namespace sort -};// End namespace boost +} // End namespace util +} // End namespace common +} // End namespace sort +} // End namespace boost //**************************************************************************** #endif diff --git a/include/boost/sort/common/util/circular_buffer.hpp b/include/boost/sort/common/util/circular_buffer.hpp index 3778e66..a1471d3 100644 --- a/include/boost/sort/common/util/circular_buffer.hpp +++ b/include/boost/sort/common/util/circular_buffer.hpp @@ -73,7 +73,7 @@ struct circular_buffer { ptr = static_cast (std::malloc (NMAX * sizeof(Value_t))); if (ptr == nullptr) throw std::bad_alloc(); - }; + } // //------------------------------------------------------------------------ // function : ~circular_buffer @@ -84,7 +84,7 @@ struct circular_buffer if (initialized) { for (size_t i = 0; i < NMAX; ++i) (ptr + i)->~Value_t(); initialized = false; - }; + } std::free(static_cast (ptr)); } ; @@ -103,61 +103,61 @@ struct circular_buffer ::new (static_cast(ptr + i)) Value_t(std::move(ptr[i - 1])); val = std::move(ptr[NMAX - 1]); initialized = true; - }; + } // //------------------------------------------------------------------------ // function : destroy_all /// @brief : destroy all the objects in the internal memory //----------------------------------------------------------------------- - void destroy_all(void) { destroy(ptr, ptr + NMAX); }; + void destroy_all(void) { destroy(ptr, ptr + NMAX); } // //------------------------------------------------------------------------ // function : get_buffer /// @brief return the internal memory of the circular buffer /// @return pointer to the internal memory of the buffer //----------------------------------------------------------------------- - Value_t * get_buffer(void) { return ptr; }; + Value_t * get_buffer(void) { return ptr; } // //------------------------------------------------------------------------ // function : empty /// @brief return if the buffer is empty /// @return true : empty //----------------------------------------------------------------------- - bool empty(void) const {return (nelem == 0); }; + bool empty(void) const {return (nelem == 0); } // //------------------------------------------------------------------------ // function : full /// @brief return if the buffer is full /// @return true : full //----------------------------------------------------------------------- - bool full(void) const { return (nelem == NMAX); }; + bool full(void) const { return (nelem == NMAX); } // //------------------------------------------------------------------------ // function : size /// @brief return the number of elements stored in the buffer /// @return number of elements stored //----------------------------------------------------------------------- - size_t size(void) const { return nelem;}; + size_t size(void) const { return nelem;} // //------------------------------------------------------------------------ // function : capacity /// @brief : return the maximun capacity of the buffer /// @return number of elements //----------------------------------------------------------------------- - size_t capacity(void) const { return NMAX;}; + size_t capacity(void) const { return NMAX;} // //------------------------------------------------------------------------ // function : free_size /// @brief return the free positions in the buffer /// @return number of elements //----------------------------------------------------------------------- - size_t free_size(void) const { return (NMAX - nelem); }; + size_t free_size(void) const { return (NMAX - nelem); } // //------------------------------------------------------------------------ // function : clear /// @brief clear the buffer //----------------------------------------------------------------------- - void clear(void) { nelem = first_pos = 0; }; + void clear(void) { nelem = first_pos = 0; } // //------------------------------------------------------------------------ // function : front @@ -170,7 +170,7 @@ struct circular_buffer assert (nelem > 0); #endif return (ptr[first_pos]); - }; + } // //------------------------------------------------------------------------ // function :front @@ -183,7 +183,7 @@ struct circular_buffer assert ( nelem > 0 ); #endif return (ptr[first_pos]); - }; + } // //------------------------------------------------------------------------ // function : back @@ -196,7 +196,7 @@ struct circular_buffer assert ( nelem > 0 ); #endif return (ptr[(first_pos + nelem - 1) & MASK]); - }; + } // //------------------------------------------------------------------------ // function : back @@ -209,7 +209,7 @@ struct circular_buffer assert ( nelem > 0 ); #endif return (ptr[(first_pos + nelem - 1) & MASK]); - }; + } // //------------------------------------------------------------------------ // function : operator [] @@ -223,7 +223,7 @@ struct circular_buffer assert ( nelem > 0 ); #endif return ptr[(first_pos + pos) & MASK]; - }; + } // //------------------------------------------------------------------------ // function : operator [] @@ -238,7 +238,7 @@ struct circular_buffer assert ( nelem > 0 ); #endif return ptr[(first_pos + pos) & MASK]; - }; + } // //------------------------------------------------------------------------ // function : push_front @@ -254,7 +254,7 @@ struct circular_buffer first_pos = ((first_pos + MASK) & MASK); ptr[first_pos] = val; - }; + } // //------------------------------------------------------------------------ // function : push_front @@ -269,7 +269,7 @@ struct circular_buffer ++nelem; first_pos = ((first_pos + MASK) & MASK); ptr[first_pos] = val; - }; + } // //------------------------------------------------------------------------ // function : push_back @@ -282,7 +282,7 @@ struct circular_buffer assert ( nelem != NMAX); #endif ptr[(first_pos + (nelem++)) & MASK] = val; - }; + } // //------------------------------------------------------------------------ // function : push_back @@ -295,7 +295,7 @@ struct circular_buffer assert ( nelem != NMAX); #endif ptr[(first_pos + (nelem++)) & MASK] = std::move(val); - }; + } // //------------------------------------------------------------------------ // function : pop_front @@ -308,7 +308,7 @@ struct circular_buffer #endif --nelem; (++first_pos) &= MASK; - }; + } // //------------------------------------------------------------------------ // function : pop_back @@ -320,7 +320,7 @@ struct circular_buffer assert ( nelem > 0 ); #endif --nelem; - }; + } template void pop_copy_front(iter_t it_dest, size_t num); @@ -380,9 +380,9 @@ ::pop_copy_front(iter_t it_dest, size_t num) for (size_t i = 0; i < num; ++i) { *(it_dest++) = ptr[pos++ & MASK]; - }; + } first_pos &= MASK; -}; +} // //------------------------------------------------------------------------ // function : pop_move_front @@ -408,9 +408,9 @@ :: pop_move_front(iter_t it_dest, size_t num) for (size_t i = 0; i < num; ++i) { *(it_dest++) = std::move(ptr[pos++ & MASK]); - }; + } first_pos &= MASK; -}; +} // //------------------------------------------------------------------------ // function : pop_copy_back @@ -434,8 +434,8 @@ ::pop_copy_back(iter_t it_dest, size_t num) for (size_t i = 0; i < num; ++i) { *(it_dest++) = ptr[pos++ & MASK]; - }; -}; + } +} // //------------------------------------------------------------------------ // function : pop_move_back @@ -459,8 +459,8 @@ ::pop_move_back(iter_t it_dest, size_t num) for (size_t i = 0; i < num; ++i) { *(it_dest++) = std::move(ptr[pos++ & MASK]); - }; -}; + } +} // //------------------------------------------------------------------------ // function : push_copy_front @@ -486,8 +486,8 @@ ::push_copy_front(iter_t it_src, size_t num) for (size_t i = 0; i < num; ++i) { ptr[(pos++) & MASK] = *(it_src++); - }; -}; + } +} // //------------------------------------------------------------------------ // function : push_move_front @@ -511,8 +511,8 @@ ::push_move_front(iter_t it_src, size_t num) for (size_t i = 0; i < num; ++i) { ptr[(pos++) & MASK] = std::move(*(it_src++)); - }; -}; + } +} // //------------------------------------------------------------------------ // function : push_copy_back @@ -536,8 +536,8 @@ ::push_copy_back(iter_t it_src, size_t num) for (size_t i = 0; i < num; ++i) { ptr[(pos++) & MASK] = *(it_src++); - }; -}; + } +} // //------------------------------------------------------------------------ // function : push_move_back @@ -561,13 +561,13 @@ ::push_move_back(iter_t it_src, size_t num) for (size_t i = 0; i < num; ++i) { ptr[(pos++) & MASK] = std::move(*(it_src++)); - }; -}; + } +} //**************************************************************************** -};// End namespace util -};// End namespace common -};// End namespace sort -};// End namespace boost +} // End namespace util +} // End namespace common +} // End namespace sort +} // End namespace boost //**************************************************************************** #endif diff --git a/include/boost/sort/common/util/insert.hpp b/include/boost/sort/common/util/insert.hpp index 150ef26..451741c 100644 --- a/include/boost/sort/common/util/insert.hpp +++ b/include/boost/sort/common/util/insert.hpp @@ -91,8 +91,8 @@ static void insert_sorted(Iter1_t first, Iter1_t mid, Iter1_t last, mv_first = std::upper_bound(first, mv_last, it_aux[i - 1], comp); Iter1_t it1 = here::move_backward(mv_last + i, mv_first, mv_last); *(it1 - 1) = std::move(it_aux[i - 1]); - }; -}; + } +} template static void insert_sorted_backward(Iter1_t first, Iter1_t mid, Iter1_t last, @@ -128,15 +128,15 @@ static void insert_sorted_backward(Iter1_t first, Iter1_t mid, Iter1_t last, mv_last = std::lower_bound(mv_first, last, it_aux[i], comp); Iter1_t it1 = move_forward(mv_first - (ndata - i), mv_first, mv_last); *(it1) = std::move(it_aux[i]); - }; + } -}; +} // //**************************************************************************** -};// End namespace util -};// End namepspace common -};// End namespace sort -};// End namepspace boost +} // End namespace util +} // End namepspace common +} // End namespace sort +} // End namepspace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/util/merge.hpp b/include/boost/sort/common/util/merge.hpp index 6fce04e..446eadb 100644 --- a/include/boost/sort/common/util/merge.hpp +++ b/include/boost/sort/common/util/merge.hpp @@ -110,19 +110,19 @@ static Iter3_t merge(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, { Iter3_t mid = move_forward(buf_out, buf1, end_buf1); return move_forward(mid, buf2, end_buf2); - }; + } if (comp(*(end_buf2 - 1), *buf1)) { Iter3_t mid = move_forward(buf_out, buf2, end_buf2); return move_forward(mid, buf1, end_buf1); - }; - }; + } + } while ((buf1 != end_buf1) && (buf2 != end_buf2)) { *(buf_out++) = (! comp(*buf2, *buf1)) ? std::move(*(buf1++)) : std::move(*(buf2++)); - }; + } return (buf1 == end_buf1) ? move_forward(buf_out, buf2, end_buf2) : @@ -171,25 +171,25 @@ static Value_t *merge_construct(Iter1_t first1, const Iter1_t last1, { Value_t* mid = move_construct(it_out, first1, last1); return move_construct(mid, first2, last2); - }; + } if (comp(*(last2 - 1), *first1)) { Value_t* mid = move_construct(it_out, first2, last2); return move_construct(mid, first1, last1); - }; - }; + } + } while (first1 != last1 && first2 != last2) { construct_object((it_out++), (! comp(*first2, *first1)) ? std::move(*(first1++)) : std::move(*(first2++))); - }; + } return (first1 == last1) ? move_construct(it_out, first2, last2) : move_construct(it_out, first1, last1); -}; +} // //--------------------------------------------------------------------------- // function : merge_half @@ -235,21 +235,21 @@ static Iter2_t merge_half(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, { move_forward(buf_out, buf1, end_buf1); return end_buf2; - }; + } if (comp(*(end_buf2 - 1), *buf1)) { Iter2_t mid = move_forward(buf_out, buf2, end_buf2); return move_forward(mid, buf1, end_buf1); - }; - }; + } + } while ((buf1 != end_buf1) && (buf2 != end_buf2)) { *(buf_out++) = (! comp(*buf2, *buf1)) ? std::move(*(buf1++)) : std::move(*(buf2++)); - }; + } return (buf2 == end_buf2)? move_forward(buf_out, buf1, end_buf1) : end_buf2; -}; +} // //--------------------------------------------------------------------------- @@ -298,24 +298,24 @@ static Iter2_t merge_half_backward(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, { here::move_backward(end_buf_out, buf2, end_buf2); return buf1; - }; + } if (comp(*(end_buf2 - 1), *buf1)) { Iter1_t mid = here::move_backward(end_buf_out, buf1, end_buf1); return here::move_backward(mid, buf2, end_buf2); - }; - }; + } + } while ((buf1 != end_buf1) && (buf2 != end_buf2)) { *(--end_buf_out) = (! comp(*(end_buf2 - 1), *(end_buf1 - 1))) ? std::move(*(--end_buf2)): std::move(*(--end_buf1)); - }; + } return (buf1 == end_buf1) ? here::move_backward(end_buf_out, buf2, end_buf2) : buf1; -}; +} // //----------------------------------------------------------------------------- @@ -375,9 +375,9 @@ static bool merge_uncontiguous(Iter1_t src1, const Iter1_t end_src1, else { merge_half(aux, end_aux, src2, end_src2, src2_first, comp); - }; + } return false; -}; +} // //----------------------------------------------------------------------------- @@ -421,7 +421,7 @@ static bool merge_contiguous(Iter1_t src1, Iter1_t src2, Iter1_t end_src2, move_forward(buf, src1, end_src1); merge_half(buf, buf + nx, src2, end_src2, src1, comp); return false; -}; +} // //----------------------------------------------------------------------------- // function : merge_circular @@ -465,7 +465,7 @@ static bool merge_circular(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, it1_out = end_buf1; it2_out = buf2; return true; - }; + } if (comp(*(end_buf2 - 1), *buf1)) { circ.push_move_back(buf2, (end_buf2 - buf2)); @@ -477,18 +477,18 @@ static bool merge_circular(Iter1_t buf1, Iter1_t end_buf1, Iter2_t buf2, { circ.push_back(comp(*buf2, *buf1) ? std::move(*(buf2++)) : std::move(*(buf1++))); - }; + } it2_out = buf2; it1_out = buf1; bool ret = (buf1 == end_buf1); return ret; -}; +} // //**************************************************************************** -};// End namespace util -};// End namespace common -};// End namespace sort -};// End namespace boost +} // End namespace util +} // End namespace common +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/util/search.hpp b/include/boost/sort/common/util/search.hpp index f051666..1b86582 100644 --- a/include/boost/sort/common/util/search.hpp +++ b/include/boost/sort/common/util/search.hpp @@ -30,7 +30,7 @@ struct filter_pass const key & operator()(const T & val) const { return val; - }; + } }; // @@ -79,9 +79,9 @@ inline Iter_t internal_find_first(Iter_t first, Iter_t last, if (comp(flt(*it_out), val)) LI = it_out + 1; else LS = it_out; - }; + } return LS; -}; +} // //----------------------------------------------------------------------------- // function : internal_find_last @@ -112,9 +112,9 @@ inline Iter_t internal_find_last(Iter_t first, Iter_t last, it_out = LI + ((LS - LI + 1) >> 1); if (comp(val, flt(*it_out))) LS = it_out - 1; else LI = it_out; - }; + } return LS; -}; +} // //########################################################################### @@ -149,7 +149,7 @@ inline Iter_t find_first(Iter_t first, Iter_t last, if (first == last) return last; Iter_t LS = internal_find_first(first, last, val, comp, flt); return (comp(flt(*LS), val) or comp(val, flt(*LS))) ? last : LS; -}; +} // //----------------------------------------------------------------------------- // function : find_last @@ -174,7 +174,7 @@ inline Iter_t find_last(Iter_t first, Iter_t last, if (last == first) return last; Iter_t LS = internal_find_last(first, last, val, comp, flt); return (comp(flt(*LS), val) or comp(val, flt(*LS))) ? last : LS; -}; +} //---------------------------------------------------------------------------- // function : lower_bound @@ -196,7 +196,7 @@ inline Iter_t lower_bound(Iter_t first, Iter_t last, if (last == first) return last; Iter_t itaux = internal_find_first(first, last, val, comp, flt); return (itaux == (last - 1) and comp(flt(*itaux), val)) ? last : itaux; -}; +} //---------------------------------------------------------------------------- // function :upper_bound /// @brief return the first element greather than val.If don't exist @@ -242,7 +242,7 @@ inline std::pair equal_range(Iter_t first, Iter_t last, { return std::make_pair(lower_bound(first, last, val, comp, flt), upper_bound(first, last, val, comp, flt)); -}; +} // //----------------------------------------------------------------------------- // function : insert_first @@ -263,7 +263,7 @@ inline Iter_t insert_first(Iter_t first, Iter_t last, Filter()) { return lower_bound(first, last, val, comp, flt); -}; +} // //----------------------------------------------------------------------------- // function : insert_last @@ -285,7 +285,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, Filter()) { return upper_bound(first, last, val, comp, flt); -}; +} /* @@ -330,9 +330,9 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, while ( LI != LS) { it_out = LI + ( (LS - LI) >> 1); if ( comp ( *it_out, val)) LI = it_out + 1 ; else LS = it_out ; - }; + } return LS ; - }; + } // //----------------------------------------------------------------------------- // function : internal_find_last @@ -359,9 +359,9 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, while ( LI != LS) { it_out = LI + ( (LS - LI + 1) >> 1); if ( comp (val, *it_out)) LS = it_out - 1 ; else LI = it_out ; - }; + } return LS ; - }; + } // //########################################################################### @@ -394,7 +394,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, if ( first == last) return last ; Iter_t LS = internal_find_first ( first, last, val, comp); return (comp (*LS, val) or comp (val, *LS))?last:LS; - }; + } // //----------------------------------------------------------------------------- // function : find_last @@ -417,7 +417,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, if ( last == first ) return last ; Iter_t LS = internal_find_last (first, last, val, comp); return (comp (*LS, val) or comp (val, *LS))?last:LS ; - }; + } //---------------------------------------------------------------------------- // function : lower_bound @@ -437,7 +437,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, if ( last == first ) return last ; Iter_t itaux = internal_find_first( first, last, val,comp); return (itaux == (last - 1) and comp (*itaux, val))?last: itaux; - }; + } //---------------------------------------------------------------------------- // function :upper_bound /// @brief return the first element greather than val.If don't exist @@ -459,7 +459,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, if ( last == first ) return last ; Iter_t itaux = internal_find_last( first, last, val,comp); return ( itaux == first and comp (val,*itaux))? itaux: itaux + 1; - }; + } //---------------------------------------------------------------------------- // function :equal_range /// @brief return a pair of lower_bound and upper_bound with the value val.If @@ -478,7 +478,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, { return std::make_pair(lower_bound(first, last, val,comp), upper_bound(first, last, val,comp)); - }; + } // //----------------------------------------------------------------------------- // function : insert_first @@ -497,7 +497,7 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, Compare comp = Compare() ) { return lower_bound (first, last, val, comp); - }; + } // //----------------------------------------------------------------------------- // function : insert_last @@ -517,15 +517,15 @@ inline Iter_t insert_last(Iter_t first, Iter_t last, Compare comp = Compare()) { return upper_bound (first, last, val, comp); - }; + } */ // //**************************************************************************** -};// End namespace util -};// End namespace common -};// End namespace sort -};// End namespace boost +} // End namespace util +} // End namespace common +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/util/traits.hpp b/include/boost/sort/common/util/traits.hpp index d4237b8..f2819ea 100644 --- a/include/boost/sort/common/util/traits.hpp +++ b/include/boost/sort/common/util/traits.hpp @@ -116,9 +116,9 @@ struct constructor }; // //**************************************************************************** -};// End namespace util -};// End namespace common -};// End namespace sort -};// End namespace boost +} // End namespace util +} // End namespace common +} // End namespace sort +} // End namespace boost //**************************************************************************** #endif From d2704d4660f8b3f41d5d1cd2e97e6a538e1ff61a Mon Sep 17 00:00:00 2001 From: Nigel Stewart Date: Wed, 10 Jan 2024 14:25:08 +1000 Subject: [PATCH 21/21] Remove unnecessary semicolons for gcc --pedantic mode --- .../blk_detail/move_blocks.hpp | 2 +- include/boost/sort/common/indirect.hpp | 19 +++--- include/boost/sort/common/merge_block.hpp | 12 ++-- include/boost/sort/common/merge_four.hpp | 44 ++++++------- include/boost/sort/common/merge_vector.hpp | 16 ++--- include/boost/sort/common/pivot.hpp | 14 ++--- include/boost/sort/common/range.hpp | 44 ++++++++----- include/boost/sort/common/rearrange.hpp | 8 +-- include/boost/sort/common/sort_basic.hpp | 16 ++--- include/boost/sort/common/spinlock.hpp | 16 ++--- include/boost/sort/common/util/merge.hpp | 2 +- .../flat_stable_sort/flat_stable_sort.hpp | 20 +++--- .../boost/sort/insert_sort/insert_sort.hpp | 6 +- .../parallel_stable_sort.hpp | 14 ++--- .../boost/sort/sample_sort/sample_sort.hpp | 62 +++++++++---------- include/boost/sort/spinsort/spinsort.hpp | 21 ++++--- 16 files changed, 164 insertions(+), 152 deletions(-) diff --git a/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp b/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp index e633e71..5ed8f41 100644 --- a/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp +++ b/include/boost/sort/block_indirect_sort/blk_detail/move_blocks.hpp @@ -203,7 +203,7 @@ ::move_blocks(backbone_t &bkb) : bk(bkb) } bk.exec(counter); } -; + // //------------------------------------------------------------------------- // function : move_sequence diff --git a/include/boost/sort/common/indirect.hpp b/include/boost/sort/common/indirect.hpp index 123119a..bc1a8f2 100644 --- a/include/boost/sort/common/indirect.hpp +++ b/include/boost/sort/common/indirect.hpp @@ -79,7 +79,8 @@ void create_index(Iter_t first, Iter_t last, std::vector &index) index.clear(); index.reserve(nelem); for (; first != last; ++first) index.push_back(first); -}; +} + // //----------------------------------------------------------------------------- // function : sort_index @@ -106,7 +107,7 @@ void sort_index(Iter_t global_first, std::vector &index) (size_t(index[pos_in_vector] - global_first)) == pos_in_vector) { ++pos_in_vector; - }; + } if (pos_in_vector == nelem) return; pos_dest = pos_src = pos_in_vector; @@ -121,13 +122,13 @@ void sort_index(Iter_t global_first, std::vector &index) *it_dest = std::move(*it_src); it_dest = it_src; pos_dest = pos_src; - }; + } *it_dest = std::move(Aux); index[pos_dest] = it_dest; ++pos_in_vector; - }; -}; + } +} template > void indirect_sort(func method, Iter_t first, Iter_t last, Compare comp) @@ -141,13 +142,13 @@ void indirect_sort(func method, Iter_t first, Iter_t last, Compare comp) less_ptr_no_null index_comp(comp); method(index.begin(), index.end(), index_comp); sort_index(first, index); -}; +} // //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/merge_block.hpp b/include/boost/sort/common/merge_block.hpp index 919aa75..47cf6be 100644 --- a/include/boost/sort/common/merge_block.hpp +++ b/include/boost/sort/common/merge_block.hpp @@ -326,7 +326,7 @@ ::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) while (itxA != indexA.end()) *(itx_out++) = *(itxA++); }; -}; +} //------------------------------------------------------------------------- // function : move_range_pos_backward @@ -365,7 +365,7 @@ ::move_range_pos_backward(it_index itx_first, it_index itx_last, size_t npos) util::move_backward(it_mid2, it_mid1, rng1.last); util::move_backward(rng1.last, rng1.first, it_mid1); }; -}; +} //------------------------------------------------------------------------- // function : rearrange_with_index /// @brief rearrange the blocks with the relative positions of the index @@ -408,11 +408,11 @@ ::rearrange_with_index(void) index[pos_dest] = pos_dest; ++pos_ini; }; -}; +} //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** #endif diff --git a/include/boost/sort/common/merge_four.hpp b/include/boost/sort/common/merge_four.hpp index ce3f5e5..50cff80 100644 --- a/include/boost/sort/common/merge_four.hpp +++ b/include/boost/sort/common/merge_four.hpp @@ -57,7 +57,7 @@ inline bool less_range(Iter_t it1, uint32_t pos1, Iter_t it2, uint32_t pos2, { return (comp(*it1, *it2)) ? true : (pos2 < pos1) ? false : not (comp(*it2, *it1)); -}; +} //----------------------------------------------------------------------------- // function : full_merge4 @@ -96,17 +96,17 @@ range full_merge4(const range &rdest, for (uint32_t k = i + 1; k < nrange_input; ++k) { vrange_input[k - 1] = vrange_input[k]; - }; + } --nrange_input; - }; - }; + } + } if (nrange_input == 0) return range1_t(rdest.first, rdest.first); if (nrange_input == 1) return move_forward(rdest, vrange_input[0]); if (nrange_input == 2) { return merge(rdest, vrange_input[0], vrange_input[1], comp); - }; + } //------------------------------------------------------------------------ // Initial sort @@ -122,12 +122,12 @@ range full_merge4(const range &rdest, vrange_input[pos[0]].first, pos[0], comp)) { swap(pos[0], pos[1]); - }; + } if (npos == 4 and less_range(vrange_input[pos[3]].first, pos[3], vrange_input[pos[2]].first, pos[2], comp)) { swap(pos[3], pos[2]); - }; + } if (less_range (vrange_input[pos[2]].first, pos[2], vrange_input[pos[0]].first, pos[0], comp)) { @@ -138,12 +138,12 @@ range full_merge4(const range &rdest, vrange_input[pos[1]].first, pos[1], comp)) { swap(pos[1], pos[3]); - }; + } if (less_range (vrange_input[pos[2]].first, pos[2], vrange_input[pos[1]].first, pos[1], comp)) { swap(pos[1], pos[2]); - }; + } Iter1_t it_dest = rdest.first; while (npos > 2) @@ -173,11 +173,11 @@ range full_merge4(const range &rdest, pos[2], comp)) { swap(pos[2], pos[3]); - }; - }; - }; - }; - }; + } + } + } + } + } range1_t raux1(rdest.first, it_dest), raux2(it_dest, rdest.last); if (pos[0] < pos[1]) @@ -189,8 +189,8 @@ range full_merge4(const range &rdest, { return concat(raux1, merge (raux2, vrange_input[pos[1]], vrange_input[pos[0]], comp)); - }; -}; + } +} //----------------------------------------------------------------------------- // function : uninit_full_merge4 @@ -236,7 +236,7 @@ range uninit_full_merge4(const range &dest, if (nrange_input == 2) { return merge_construct(dest, vrange_input[0], vrange_input[1], comp); - }; + } //------------------------------------------------------------------------ // Initial sort @@ -319,13 +319,13 @@ range uninit_full_merge4(const range &dest, return concat(raux1, merge_construct(raux2, vrange_input[pos[1]], vrange_input[pos[0]], comp)); - }; -}; + } +} //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/merge_vector.hpp b/include/boost/sort/common/merge_vector.hpp index aaba93d..1657455 100644 --- a/include/boost/sort/common/merge_vector.hpp +++ b/include/boost/sort/common/merge_vector.hpp @@ -67,7 +67,7 @@ void merge_level4(range dest, std::vector > &v_input, { v_output.emplace_back(move_forward(dest, v_input[0])); return; - }; + } uint32_t nrange = v_input.size(); uint32_t pos_ini = 0; @@ -80,9 +80,9 @@ void merge_level4(range dest, std::vector > &v_input, dest.first = rz.last; pos_ini += nelem; nrange -= nelem; - }; + } return; -}; +} // //----------------------------------------------------------------------------- // function : uninit_merge_level4 @@ -129,7 +129,7 @@ void uninit_merge_level4(range dest, nrange -= nelem; }; return; -}; +} // //----------------------------------------------------------------------------- // function : merge_vector4 @@ -187,12 +187,12 @@ range merge_vector4(range range_input, }; }; return (sw) ? v_output[0] : move_forward(range_output, v_input[0]); -}; +} //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/pivot.hpp b/include/boost/sort/common/pivot.hpp index 7b10385..33ada27 100644 --- a/include/boost/sort/common/pivot.hpp +++ b/include/boost/sort/common/pivot.hpp @@ -50,7 +50,7 @@ inline Iter_t mid3 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Compare comp) if (comp (*iter_2, *iter_1)) swap ( *iter_2, *iter_1); }; return iter_2; -}; +} // //----------------------------------------------------------------------------- // function : pivot3 @@ -69,7 +69,7 @@ inline void pivot3 (Iter_t first, Iter_t last, Compare comp) auto N2 = (last - first) >> 1; Iter_t it_val = mid3 (first + 1, first + N2, last - 1, comp); swap (*first, *it_val); -}; +} // //----------------------------------------------------------------------------- @@ -96,7 +96,7 @@ inline Iter_t mid9 (Iter_t iter_1, Iter_t iter_2, Iter_t iter_3, Iter_t iter_4, return mid3 (mid3 (iter_1, iter_2, iter_3, comp), mid3 (iter_4, iter_5, iter_6, comp), mid3 (iter_7, iter_8, iter_9, comp), comp); -}; +} // //----------------------------------------------------------------------------- // function : pivot9 @@ -118,10 +118,10 @@ inline void pivot9 (Iter_t first, Iter_t last, Compare comp) first + 3 * cupo, first + 4 * cupo, first + 5 * cupo, first + 6 * cupo, first + 7 * cupo, last - 1, comp); swap (*first, *itaux); -}; +} //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** #endif diff --git a/include/boost/sort/common/range.hpp b/include/boost/sort/common/range.hpp index 859bf75..3aa8d85 100644 --- a/include/boost/sort/common/range.hpp +++ b/include/boost/sort/common/range.hpp @@ -109,7 +109,7 @@ inline range concat(const range &it1, const range &it2) { return range(it1.first, it2.last); } -; + // //----------------------------------------------------------------------------- // function : move_forward @@ -125,7 +125,8 @@ inline range move_forward(const range &dest, assert(dest.size() >= src.size()); Iter2_t it_aux = util::move_forward(dest.first, src.first, src.last); return range(dest.first, it_aux); -}; +} + // //----------------------------------------------------------------------------- // function : move_backward @@ -142,7 +143,7 @@ inline range move_backward(const range &dest, Iter2_t it_aux = util::move_backward(dest.first + src.size(), src.first, src.last); return range(dest.first, dest.src.size()); -}; +} //----------------------------------------------------------------------------- // function : uninit_move @@ -158,7 +159,8 @@ inline range move_construct(const range &dest, { Value_t *ptr_aux = util::move_construct(dest.first, src.first, src.last); return range(dest.first, ptr_aux); -}; +} + // //----------------------------------------------------------------------------- // function : destroy @@ -169,7 +171,8 @@ template inline void destroy(range rng) { util::destroy(rng.first, rng.last); -}; +} + // //----------------------------------------------------------------------------- // function : initialize @@ -183,7 +186,8 @@ inline range initialize(const range &rng, Value_t &val) { util::initialize(rng.first, rng.last, val); return rng; -}; +} + // //----------------------------------------------------------------------------- // function : is_mergeable @@ -209,7 +213,8 @@ inline bool is_mergeable(const range &src1, const range &src2, // Code //------------------------------------------------------------------------ return comp(*(src2.front()), *(src1.back())); -}; +} + // //----------------------------------------------------------------------------- // function : is_mergeable_stable @@ -235,7 +240,8 @@ inline bool is_mergeable_stable(const range &src1, // Code //------------------------------------------------------------------------ return ! comp(*(src1.back()), *(src2.front())); -}; +} + // //----------------------------------------------------------------------------- // function : merge @@ -258,7 +264,7 @@ inline range merge(const range &dest, Iter3_t it_aux = util::merge(src1.first, src1.last, src2.first, src2.last, dest.first, comp); return range(dest.first, it_aux); -}; +} //----------------------------------------------------------------------------- // function : merge_construct @@ -283,7 +289,8 @@ inline range merge_construct(const range &dest, Value_t * ptr_aux = util::merge_construct(src1.first, src1.last, src2.first, src2.last, dest.first, comp); return range(dest.first, ptr_aux); -}; +} + // //--------------------------------------------------------------------------- // function : half_merge @@ -306,7 +313,8 @@ inline range merge_half(const range &dest, Iter2_t it_aux = util::merge_half(src1.first, src1.last, src2.first, src2.last, dest.first, comp); return range(dest.first, it_aux); -}; +} + // //----------------------------------------------------------------------------- // function : merge_uncontiguous @@ -326,7 +334,8 @@ inline bool merge_uncontiguous(const range &src1, { return util::merge_uncontiguous(src1.first, src1.last, src2.first, src2.last, aux.first, comp); -}; +} + // //----------------------------------------------------------------------------- // function : merge_contiguous @@ -345,7 +354,8 @@ inline range merge_contiguous(const range &src1, { util::merge_contiguous(src1.first, src1.last, src2.last, buf.first, comp); return concat(src1, src2); -}; +} + // //----------------------------------------------------------------------------- // function : merge_flow @@ -389,12 +399,12 @@ static void merge_flow(range rng1, range rbuf, if (rx2.first == rx2.last) return; if (rbx.first == rbx.last) move_forward(rbuf, rng2); else merge_half(rbuf, rx2, rbx, cmp); -}; +} //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/rearrange.hpp b/include/boost/sort/common/rearrange.hpp index 687de29..a0cdf15 100644 --- a/include/boost/sort/common/rearrange.hpp +++ b/include/boost/sort/common/rearrange.hpp @@ -101,7 +101,7 @@ void rearrange(Iter_data global_first, Iter_index itx_first, index[pos_ini] = std::move(itx_src); ++pos_ini; }; -}; +} /* // @@ -161,9 +161,9 @@ void rearrange(Iter_data global_first, Iter_index itx_first, */ // //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namespace boost +}// End namespace common +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/sort_basic.hpp b/include/boost/sort/common/sort_basic.hpp index 74a5b99..7c4ae77 100644 --- a/include/boost/sort/common/sort_basic.hpp +++ b/include/boost/sort/common/sort_basic.hpp @@ -80,7 +80,7 @@ inline Iter_t is_reverse_stable_sorted_forward(Iter_t first, Iter_t last, Iter_t it2 = first + 1; for (Iter_t it1 = first; it2 != last && comp(*it2, *it1); it1 = it2++); return it2; -}; +} //----------------------------------------------------------------------------- // function : number_stable_sorted_forward /// @brief examine the elements in the range first, last if they are stable @@ -117,7 +117,7 @@ size_t number_stable_sorted_forward (Iter_t first, Iter_t last, if ( nsorted < min_process) return 0 ; util::reverse ( first , it2); return nsorted; -}; +} //----------------------------------------------------------------------------- // function : is_stable_sorted_backward @@ -248,7 +248,7 @@ inline void internal_sort (const range &rng1, internal_sort(rng2_right, rng1_right, comp, level + 1, even); }; merge(rng2, rng1_left, rng1_right, comp); -}; +} //----------------------------------------------------------------------------- // function : range_sort_data /// @brief this sort elements using the range_sort function and receiving a @@ -285,7 +285,7 @@ static void range_sort_data (const range & rng_data, }; internal_sort(rng_aux, rng_data, comp, 0, true); -}; +} //----------------------------------------------------------------------------- // function : range_sort_buffer /// @brief this sort elements using the range_sort function and receiving a @@ -323,11 +323,11 @@ static void range_sort_buffer(const range & rng_data, }; internal_sort(rng_data, rng_aux, comp, 0, false); -}; +} //**************************************************************************** -};// End namespace common -};// End namespace sort -};// End namepspace boost +}// End namespace common +}// End namespace sort +}// End namepspace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/common/spinlock.hpp b/include/boost/sort/common/spinlock.hpp index 5287ccb..d88796b 100644 --- a/include/boost/sort/common/spinlock.hpp +++ b/include/boost/sort/common/spinlock.hpp @@ -48,7 +48,7 @@ class spinlock_t /// @brief class constructor /// @param [in] //------------------------------------------------------------------------- - explicit spinlock_t ( ) noexcept { af.clear ( ); }; + explicit spinlock_t ( ) noexcept { af.clear ( ); } // //------------------------------------------------------------------------- // function : lock @@ -59,8 +59,8 @@ class spinlock_t while (af.test_and_set (std::memory_order_acquire)) { std::this_thread::yield ( ); - }; - }; + } + } // //------------------------------------------------------------------------- // function : try_lock @@ -71,19 +71,19 @@ class spinlock_t bool try_lock ( ) noexcept { return !af.test_and_set (std::memory_order_acquire); - }; + } // //------------------------------------------------------------------------- // function : unlock /// @brief unlock the spinlock_t //------------------------------------------------------------------------- - void unlock ( ) noexcept { af.clear (std::memory_order_release); }; + void unlock ( ) noexcept { af.clear (std::memory_order_release); } }; // E N D C L A S S S P I N L O C K // //*************************************************************************** -}; // end namespace common -}; // end namespace sort -}; // end namespace boost +} // end namespace common +} // end namespace sort +} // end namespace boost //*************************************************************************** #endif diff --git a/include/boost/sort/common/util/merge.hpp b/include/boost/sort/common/util/merge.hpp index 446eadb..8ea7ea1 100644 --- a/include/boost/sort/common/util/merge.hpp +++ b/include/boost/sort/common/util/merge.hpp @@ -128,7 +128,7 @@ static Iter3_t merge(Iter1_t buf1, const Iter1_t end_buf1, Iter2_t buf2, move_forward(buf_out, buf2, end_buf2) : move_forward(buf_out, buf1, end_buf1); } -; + // //----------------------------------------------------------------------------- // function : merge_construct diff --git a/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp b/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp index ea1155f..fe31a50 100644 --- a/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp +++ b/include/boost/sort/flat_stable_sort/flat_stable_sort.hpp @@ -132,7 +132,7 @@ ::divide(it_index itx_first, it_index itx_last) divide(itx_first, itx_first + nblock1); divide(itx_first + nblock1, itx_last); merge_range_pos(itx_first, itx_first + nblock1, itx_last); -}; +} // //------------------------------------------------------------------------ // @fn sort_small @@ -168,7 +168,7 @@ ::sort_small(it_index itx_first, it_index itx_last) range_sort_data(rng_data2, rng_aux2, cmp); range_sort_buffer(rng_data1, rng_aux1, cmp); merge_half(rng_data, rng_aux1, rng_data2, cmp); -}; +} // //------------------------------------------------------------------------ // @fn is_sorted_forward @@ -209,7 +209,7 @@ ::is_sorted_forward(it_index itx_first, it_index itx_last) merge_range_pos(itx_first, itx_first + nblock1, itx_last); }; return true; -}; +} // //------------------------------------------------------------------------ // @fn is_sorted_backward @@ -250,9 +250,9 @@ ::is_sorted_backward(it_index itx_first, it_index itx_last) merge_range_pos(itx_first, itx_first + nblock1, itx_last); }; return true; -}; +} //**************************************************************************** -};// End namespace flat_internal +}// End namespace flat_internal //**************************************************************************** // namespace bscu = boost::sort::common::util; @@ -270,7 +270,7 @@ inline void flat_stable_sort (Iter_t first, Iter_t last, Compare cmp = Compare()) { flat::flat_stable_sort (first, last, cmp); -}; +} template struct block_size_fss @@ -297,7 +297,7 @@ inline void flat_stable_sort (Iter_t first, Iter_t last, flat::flat_stable_sort )>::data> (first, last, cmp); -}; +} template > inline void indirect_flat_stable_sort (Iter_t first, Iter_t last, @@ -307,11 +307,11 @@ inline void indirect_flat_stable_sort (Iter_t first, Iter_t last, typedef common::less_ptr_no_null itx_comp; common::indirect_sort ( flat_stable_sort, first, last, comp); -}; +} //**************************************************************************** -};// End namespace sort -};// End namepspace boost +}// End namespace sort +}// End namepspace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/insert_sort/insert_sort.hpp b/include/boost/sort/insert_sort/insert_sort.hpp index 068c1cf..ba505f1 100644 --- a/include/boost/sort/insert_sort/insert_sort.hpp +++ b/include/boost/sort/insert_sort/insert_sort.hpp @@ -57,12 +57,12 @@ static void insert_sort (Iter_t first, Iter_t last, }; *it_insertion = std::move (Aux); }; -}; +} // //**************************************************************************** -}; // End namespace sort -}; // End namespace boost +} // End namespace sort +} // End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/parallel_stable_sort/parallel_stable_sort.hpp b/include/boost/sort/parallel_stable_sort/parallel_stable_sort.hpp index cd68557..37f4613 100644 --- a/include/boost/sort/parallel_stable_sort/parallel_stable_sort.hpp +++ b/include/boost/sort/parallel_stable_sort/parallel_stable_sort.hpp @@ -200,11 +200,11 @@ ::parallel_stable_sort (Iter_t first, Iter_t last, Compare comp, -}; // end of constructor +} // end of constructor // //**************************************************************************** -};// End namespace stable_detail +}// End namespace stable_detail //**************************************************************************** // @@ -237,7 +237,7 @@ void parallel_stable_sort(Iter_t first, Iter_t last) { typedef bscu::compare_iter Compare; stable_detail::parallel_stable_sort(first, last); -}; +} // //----------------------------------------------------------------------------- // function : parallel_stable_sort @@ -254,7 +254,7 @@ void parallel_stable_sort(Iter_t first, Iter_t last, uint32_t nthread) { typedef bscu::compare_iter Compare; stable_detail::parallel_stable_sort(first, last, nthread); -}; +} // //----------------------------------------------------------------------------- // function : parallel_stable_sort @@ -271,7 +271,7 @@ template (first, last, comp); -}; +} // //----------------------------------------------------------------------------- @@ -294,8 +294,8 @@ void parallel_stable_sort (Iter_t first, Iter_t last, Compare comp, } // //**************************************************************************** -};// End namespace sort -};// End namespace boost +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/sample_sort/sample_sort.hpp b/include/boost/sort/sample_sort/sample_sort.hpp index e52e2dd..095108a 100644 --- a/include/boost/sort/sample_sort/sample_sort.hpp +++ b/include/boost/sort/sample_sort/sample_sort.hpp @@ -124,22 +124,22 @@ struct sample_sort sample_sort(Iter_t first, Iter_t last) : sample_sort (first, last, Compare(), std::thread::hardware_concurrency(), - nullptr, 0) { }; + nullptr, 0) { } sample_sort(Iter_t first, Iter_t last, Compare cmp) : sample_sort(first, last, cmp, std::thread::hardware_concurrency(), - nullptr, 0) { }; + nullptr, 0) { } sample_sort(Iter_t first, Iter_t last, uint32_t num_thread) - : sample_sort(first, last, Compare(), num_thread, nullptr, 0) { }; + : sample_sort(first, last, Compare(), num_thread, nullptr, 0) { } sample_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread) - : sample_sort(first, last, cmp, num_thread, nullptr, 0) { }; + : sample_sort(first, last, cmp, num_thread, nullptr, 0) { } sample_sort(Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread, range_buf range_buf_initial) : sample_sort(first, last, cmp, num_thread, - range_buf_initial.first, range_buf_initial.size()) { }; + range_buf_initial.first, range_buf_initial.size()) { } void destroy_all(void); // @@ -148,7 +148,7 @@ struct sample_sort /// @brief destructor of the class. The utility is to destroy the temporary /// buffer used in the sorting process //----------------------------------------------------------------------------- - ~sample_sort(void) { destroy_all(); }; + ~sample_sort(void) { destroy_all(); } // //----------------------------------------------------------------------- // function : execute first @@ -161,8 +161,8 @@ struct sample_sort { uninit_merge_level4(vrange_buf_ini[job], vv_range_it[job], vv_range_buf[job], comp); - }; - }; + } + } // //----------------------------------------------------------------------- // function : execute @@ -175,8 +175,8 @@ struct sample_sort { merge_vector4(vrange_buf_ini[job], vrange_it_ini[job], vv_range_buf[job], vv_range_it[job], comp); - }; - }; + } + } // //----------------------------------------------------------------------- // function : first merge @@ -193,7 +193,7 @@ struct sample_sort }; for (uint32_t i = 0; i < nthread; ++i) vfuture[i].get(); - }; + } // //----------------------------------------------------------------------- // function : final merge @@ -206,10 +206,10 @@ struct sample_sort for (uint32_t i = 0; i < nthread; ++i) { vfuture[i] = std::async(std::launch::async, &this_t::execute, this); - }; + } for (uint32_t i = 0; i < nthread; ++i) vfuture[i].get(); - }; + } //---------------------------------------------------------------------------- }; // End class sample_sort @@ -259,7 +259,7 @@ ::sample_sort (Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread, { bss::spinsort(first, last, comp); return; - }; + } //------------------- check if sort -------------------------------------- bool sw = true; @@ -279,7 +279,7 @@ ::sample_sort (Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread, for (size_t i = 0; i < nelem2; ++i) swap(*(it1++), *(it2--)); return; - }; + } if (paux != nullptr) { @@ -296,7 +296,7 @@ ::sample_sort (Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread, if (ptr == nullptr) throw std::bad_alloc(); owner = true; global_buf = range_buf(ptr, ptr + nelem); - }; + } //------------------------------------------------------------------------ // PROCESS //------------------------------------------------------------------------ @@ -306,20 +306,20 @@ ::sample_sort (Iter_t first, Iter_t last, Compare cmp, uint32_t num_thread, } catch (std::bad_alloc &) { error = true; - }; + } if (not error) { first_merge(); construct = true; final_merge(); - }; + } if (error) { destroy_all(); throw std::bad_alloc(); - }; + } } -; + // //----------------------------------------------------------------------------- // function : destroy_all @@ -464,22 +464,22 @@ void sample_sort::initial_configuration(void) if (nelem_range != 0) { vv_range_it[k].push_back(vv_range_first[i][k]); - }; + } nelem_interval += nelem_range; - }; + } vrange_it_ini.emplace_back(it, it + nelem_interval); vrange_buf_ini.emplace_back(it_buf, it_buf + nelem_interval); it += nelem_interval; it_buf += nelem_interval; - }; + } } -; + // //**************************************************************************** } -; + // End namespace sample_detail //**************************************************************************** // @@ -505,7 +505,7 @@ void sample_sort(Iter_t first, Iter_t last) { typedef compare_iter Compare; sample_detail::sample_sort(first, last); -}; +} // //----------------------------------------------------------------------------- // function : sample_sort @@ -521,7 +521,7 @@ void sample_sort(Iter_t first, Iter_t last, uint32_t nthread) { typedef compare_iter Compare; sample_detail::sample_sort(first, last, nthread); -}; +} // //----------------------------------------------------------------------------- // function : sample_sort @@ -537,7 +537,7 @@ template * = void sample_sort(Iter_t first, Iter_t last, Compare comp) { sample_detail::sample_sort(first, last, comp); -}; +} // //----------------------------------------------------------------------------- // function : sample_sort @@ -554,11 +554,11 @@ template void sample_sort(Iter_t first, Iter_t last, Compare comp, uint32_t nthread) { sample_detail::sample_sort(first, last, comp, nthread); -}; +} // //**************************************************************************** -};// End namespace sort -};// End namespace boost +}// End namespace sort +}// End namespace boost //**************************************************************************** // #endif diff --git a/include/boost/sort/spinsort/spinsort.hpp b/include/boost/sort/spinsort/spinsort.hpp index b8d0fdf..8895877 100644 --- a/include/boost/sort/spinsort/spinsort.hpp +++ b/include/boost/sort/spinsort/spinsort.hpp @@ -134,7 +134,7 @@ static void insert_partial_sort (Iter1_t first, Iter1_t mid, Iter1_t last, *(viter[i - 1] + (i - 1)) = std::move(*(data + (i - 1))); }; } -; + //----------------------------------------------------------------------------- // function : check_stable_sort /// @brief check if the elements between first and last are osted or reverse @@ -222,7 +222,7 @@ static bool check_stable_sort(const range &rng_data, }; return true; } -; + //----------------------------------------------------------------------------- // function : range_sort /// @brief this function divide r_input in two parts, sort it,and merge moving @@ -297,7 +297,7 @@ static void range_sort(const range &range1, merge(range2, range_input1, range_input2, comp); } -; + //----------------------------------------------------------------------------- // function : sort_range_sort /// @brief this sort elements using the range_sort function and receiving a @@ -349,7 +349,7 @@ static void sort_range_sort(const range &rng_data, move_forward(rng_data, rng_buffer); }; } -; + // //############################################################################ // ## @@ -423,6 +423,7 @@ class spinsort if (owner and ptr != nullptr) std::free (ptr); }; }; + //---------------------------------------------------------------------------- // End of class spinsort //---------------------------------------------------------------------------- @@ -532,10 +533,10 @@ ::spinsort (Iter_t first, Iter_t last, Compare comp, value_t *paux, size_t naux) range_sort(range_1, range_2, comp, nlevel); merge_half(range_input, range_aux, range_2, comp); }; -}; +} //**************************************************************************** -};// End namepspace spin_detail +}// End namepspace spin_detail //**************************************************************************** // namespace bsc = boost::sort::common; @@ -552,7 +553,7 @@ template > inline void spinsort (Iter_t first, Iter_t last, Compare comp = Compare()) { spin_detail::spinsort (first, last, comp); -}; +} template > inline void indirect_spinsort (Iter_t first, Iter_t last, @@ -561,11 +562,11 @@ inline void indirect_spinsort (Iter_t first, Iter_t last, typedef typename std::vector::iterator itx_iter; typedef common::less_ptr_no_null itx_comp; common::indirect_sort (spinsort, first, last, comp); -}; +} //**************************************************************************** -};// End namespace sort -};// End namepspace boost +}// End namespace sort +}// End namepspace boost //**************************************************************************** // #endif