2
0
mirror of https://github.com/boostorg/sort.git synced 2026-01-19 04:42:11 +00:00

adding support -fno-exception

This commit is contained in:
Francisco Tapia
2024-02-27 20:23:31 +01:00
parent cb7df6bcb6
commit d62e1fd909
29 changed files with 1180 additions and 1193 deletions

5
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"develop"
]
}

View File

@@ -50,8 +50,7 @@ void Generator_reverse_sorted (void);
void Generator_reverse_sorted_end (size_t n_last); void Generator_reverse_sorted_end (size_t n_last);
void Generator_reverse_sorted_middle (size_t n_last); void Generator_reverse_sorted_middle (size_t n_last);
template<class IA, class compare> void Test (std::vector<uint64_t> &B);
int Test (std::vector<IA> &B, compare comp = compare ());
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
@@ -66,205 +65,203 @@ int main (int argc, char *argv[])
cout << "************************************************************\n"; cout << "************************************************************\n";
cout << std::endl; cout << std::endl;
cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
cout<<"[ 3 ] parallel_stable_sort\n\n"; cout << "[ 3 ] parallel_stable_sort\n\n";
cout<<" | | | |\n"; cout << " | | | |\n";
cout<<" | [ 1 ]| [ 2 ]| [ 3 ]|\n"; cout << " | [ 1 ]| [ 2 ]| [ 3 ]|\n";
cout<<"--------------------+------+------+------+\n"; cout << "--------------------+------+------+------+\n";
std::string empty_line = std::string empty_line =
" | | | |\n"; " | | | |\n";
cout<<"random |"; cout << "random |";
Generator_random (); Generator_random ();
cout<<empty_line; cout << empty_line;
cout<<"sorted |"; cout << "sorted |";
Generator_sorted (); Generator_sorted ();
cout<<"sorted + 0.1% end |"; cout << "sorted + 0.1% end |";
Generator_sorted_end (NELEM / 1000); Generator_sorted_end (NELEM / 1000);
cout<<"sorted + 1% end |"; cout << "sorted + 1% end |";
Generator_sorted_end (NELEM / 100); Generator_sorted_end (NELEM / 100);
cout<<"sorted + 10% end |"; cout << "sorted + 10% end |";
Generator_sorted_end (NELEM / 10); Generator_sorted_end (NELEM / 10);
cout<<empty_line; cout << empty_line;
cout<<"sorted + 0.1% mid |"; cout << "sorted + 0.1% mid |";
Generator_sorted_middle (NELEM / 1000); Generator_sorted_middle (NELEM / 1000);
cout<<"sorted + 1% mid |"; cout << "sorted + 1% mid |";
Generator_sorted_middle (NELEM / 100); Generator_sorted_middle (NELEM / 100);
cout<<"sorted + 10% mid |"; cout << "sorted + 10% mid |";
Generator_sorted_middle (NELEM / 10); Generator_sorted_middle (NELEM / 10);
cout<<empty_line; cout << empty_line;
cout<<"reverse sorted |"; cout << "reverse sorted |";
Generator_reverse_sorted (); Generator_reverse_sorted ();
cout<<"rv sorted + 0.1% end|"; cout << "rv sorted + 0.1% end|";
Generator_reverse_sorted_end (NELEM / 1000); Generator_reverse_sorted_end (NELEM / 1000);
cout<<"rv sorted + 1% end|"; cout << "rv sorted + 1% end|";
Generator_reverse_sorted_end (NELEM / 100); Generator_reverse_sorted_end (NELEM / 100);
cout<<"rv sorted + 10% end|"; cout << "rv sorted + 10% end|";
Generator_reverse_sorted_end (NELEM / 10); Generator_reverse_sorted_end (NELEM / 10);
cout<<empty_line; cout << empty_line;
cout<<"rv sorted + 0.1% mid|"; cout << "rv sorted + 0.1% mid|";
Generator_reverse_sorted_middle (NELEM / 1000); Generator_reverse_sorted_middle (NELEM / 1000);
cout<<"rv sorted + 1% mid|"; cout << "rv sorted + 1% mid|";
Generator_reverse_sorted_middle (NELEM / 100); Generator_reverse_sorted_middle (NELEM / 100);
cout<<"rv sorted + 10% mid|"; cout << "rv sorted + 10% mid|";
Generator_reverse_sorted_middle (NELEM / 10); Generator_reverse_sorted_middle (NELEM / 10);
cout<<"--------------------+------+------+------+\n"; cout << "--------------------+------+------+------+\n";
cout<<endl<<endl ; cout << endl << endl ;
return 0; return 0;
} }
void void Generator_random (void)
Generator_random (void)
{ {
vector<uint64_t> A; vector <uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
if (fill_vector_uint64 ("input.bin", A, NELEM) != 0) if (fill_vector_uint64 ("input.bin", A, NELEM) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
} };
; void Generator_sorted (void)
void
Generator_sorted (void)
{ {
vector<uint64_t> A; std::vector <uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
for (size_t i = 0; i < NELEM; ++i) for (uint64_t i = 0; i < NELEM; ++i)
A.push_back (i); A.push_back (i);
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
};
} void Generator_sorted_end (uint64_t n_last)
void Generator_sorted_end (size_t n_last)
{ {
vector<uint64_t> A; std::vector <uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin (), A.begin () + NELEM); std::sort (A.begin (), A.begin () + NELEM);
Test (A);
Test<uint64_t, std::less<uint64_t>> (A); };
void Generator_sorted_middle (uint64_t n_middle)
}
;
void Generator_sorted_middle (size_t n_last)
{ {
vector<uint64_t> A, B, C; assert (n_middle > 1 && NELEM >= (n_middle -1));
A.reserve (NELEM); std::vector <uint64_t> A, aux;
A.clear (); A.reserve (NELEM + n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) aux.reserve (n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for (size_t i = NELEM; i < A.size (); ++i) for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [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 ()); std::sort (A.begin () + n_middle, A.end ());
size_t step = NELEM / n_last + 1; //------------------------------------------------------------------------
size_t pos = 0; // 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 (size_t i = 0; i < B.size (); ++i, pos += step) for (uint64_t i = 1; i < n_middle; ++i)
{ {
C.push_back (B[i]); for (uint64_t k = 0 ; k < step; ++k)
for (size_t k = 0; k < step; ++k) A [pos_write ++] = A [pos_read ++];
C.push_back (A[pos + k]); A [pos_write ++] = aux [i];
}; };
while (pos < A.size ()) aux.clear ();
C.push_back (A[pos++]); aux.reserve (0);
A = C; Test (A);
Test<uint64_t, std::less<uint64_t>> (A); };
}
;
void Generator_reverse_sorted (void) void Generator_reverse_sorted (void)
{ {
vector<uint64_t> A; std::vector<uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
for (size_t i = NELEM; i > 0; --i) for (uint64_t i = NELEM; i > 0; --i)
A.push_back (i); A.push_back (i);
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
} };
void Generator_reverse_sorted_end (size_t n_last) void Generator_reverse_sorted_end (uint64_t n_last)
{ {
vector<uint64_t> A; std::vector <uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin (), A.begin () + NELEM); std::sort (A.begin (), A.begin () + NELEM);
for (size_t i = 0; i < (NELEM >> 1); ++i) for (uint64_t i = 0; i < (NELEM >> 1); ++i)
std::swap (A[i], A[NELEM - 1 - i]); std::swap (A [i], A [NELEM - 1 - i]);
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
} }
void Generator_reverse_sorted_middle (size_t n_last) void Generator_reverse_sorted_middle (uint64_t n_middle)
{ {
vector<uint64_t> A, B, C; assert (n_middle > 1 && NELEM >= (n_middle -1));
A.reserve (NELEM); std::vector <uint64_t> A, aux;
A.clear (); A.reserve (NELEM + n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) aux.reserve (n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for (size_t i = NELEM; i < A.size (); ++i) for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [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 ()); std::sort (A.begin () + n_middle, A.end ());
size_t step = NELEM / n_last + 1; uint64_t pos1 = n_middle, pos2 = A.size () - 1;
size_t pos = 0; 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 (size_t i = 0; i < B.size (); ++i, pos += step) for (uint64_t i = 1; i < n_middle; ++i)
{ {
C.push_back (B[i]); for (uint64_t k = 0 ; k < step; ++k)
for (size_t k = 0; k < step; ++k) A [pos_write ++] = A [pos_read ++];
C.push_back (A[pos + k]); A [pos_write ++] = aux [i];
}; };
while (pos < A.size ()) aux.clear ();
C.push_back (A[pos++]); aux.reserve (0);
A = C; Test (A);
Test<uint64_t, std::less<uint64_t>> (A);
}; };
void Test (std::vector <uint64_t> &B)
template<class IA, class compare> {
int Test (std::vector<IA> &B, compare comp) //---------------------------- begin --------------------------------
{ //---------------------------- begin -------------------------------- std::less <uint64_t> comp ;
double duration; double duration;
time_point start, finish; time_point start, finish;
std::vector<IA> A (B); std::vector <uint64_t> A (B);
std::vector<double> V; std::vector <double> V;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
A = B; A = B;
@@ -291,11 +288,10 @@ int Test (std::vector<IA> &B, compare comp)
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// printing the vector // printing the vector
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
std::cout<<std::setprecision(2)<<std::fixed; std::cout << std::setprecision (2) << std::fixed;
for ( uint32_t i =0 ; i < V.size() ; ++i) for (uint32_t i = 0; i < V.size (); ++i)
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |"; { std::cout << std::right << std::setw (5) << V [i] << " |";
}; };
std::cout<<std::endl; std::cout << std::endl;
return 0;
}; };

View File

@@ -26,12 +26,8 @@
#include <boost/sort/common/time_measure.hpp> #include <boost/sort/common/time_measure.hpp>
#include <boost/sort/common/file_vector.hpp> #include <boost/sort/common/file_vector.hpp>
#include "boost/sort/common/int_array.hpp" #include "boost/sort/common/int_array.hpp"
#include <boost/sort/sort.hpp> #include <boost/sort/sort.hpp>
#define NELEM 100000000
#define NMAXSTRING 10000000
using namespace std; using namespace std;
namespace bsc = boost::sort::common; namespace bsc = boost::sort::common;
namespace bsp = boost::sort; namespace bsp = boost::sort;
@@ -45,52 +41,38 @@ using bsc::int_array;
using bsc::H_comp; using bsc::H_comp;
using bsc::L_comp; using bsc::L_comp;
template <class IA>
void Generator_random (uint64_t N);
template <class IA> template <class IA>
void Generator_random(uint64_t N); void Generator_sorted (uint64_t N);
template <class IA> template <class IA>
void Generator_sorted(uint64_t N); void Generator_sorted_end (uint64_t N, size_t n_last);
template <class IA>
void Generator_sorted_end(uint64_t N, size_t n_last );
template <class IA> template <class IA>
void Generator_sorted_middle(uint64_t N, size_t n_last ); void Generator_sorted_middle (uint64_t N, size_t n_middle);
template <class IA> template <class IA>
void Generator_reverse_sorted(uint64_t N); void Generator_reverse_sorted (uint64_t N);
template <class IA> template <class IA>
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 <class IA> template <class IA>
void Generator_reverse_sorted_middle(uint64_t N, size_t n_last ); void Generator_reverse_sorted_middle (uint64_t N, size_t n_middle);
template < class IA > template <class IA, class compare>
struct H_rightshift { void Test (std::vector <IA> &B, compare comp, std::vector <double> & V );
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 <class IA, class rightshift, class compare>
int Test(std::vector<IA> &B, rightshift shift, compare comp, std::vector<double> & V );
template <class IA> template <class IA>
void Test_size ( uint64_t N); void Test_size (uint64_t N);
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2); void Print_vectors (std::vector<double> &V1, std::vector<double> & V2);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const uint64_t NELEM = 100000000;
cout << "\n\n"; cout << "\n\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
cout << "** **\n"; cout << "** **\n";
@@ -172,320 +154,349 @@ int main(int argc, char *argv[])
template <class IA> template <class IA>
void Test_size ( uint64_t N) void Test_size ( uint64_t N)
{ {
cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
cout<<"[ 3 ] parallel_stable_sort\n\n"; cout << "[ 3 ] parallel_stable_sort\n\n";
cout << " | [ 1 ] | [ 2 ] | [ 3 ] |\n"; cout << " | [ 1 ] | [ 2 ] | [ 3 ] |\n";
cout << " | H L | H L | H L |\n"; cout << " | H L | H L | H L |\n";
cout << "--------------------+-----------+-----------+-----------+\n"; cout << "--------------------+-----------+-----------+-----------+\n";
std::string empty_line = " | | | |\n"; std::string empty_line = " | | | |\n";
cout<<"random |"; cout << "random |";
Generator_random<IA>(N); Generator_random <IA> (N);
cout<<empty_line; cout << empty_line;
cout<<"sorted |"; cout << "sorted |";
Generator_sorted<IA>(N); Generator_sorted <IA> (N);
cout<<"sorted + 0.1% end |"; cout << "sorted + 0.1% end |";
Generator_sorted_end<IA>(N, N / 1000); Generator_sorted_end <IA> (N, N / 1000);
cout<<"sorted + 1% end |"; cout << "sorted + 1% end |";
Generator_sorted_end<IA>(N, N / 100); Generator_sorted_end< IA> (N, N / 100);
cout<<"sorted + 10% end |"; cout << "sorted + 10% end |";
Generator_sorted_end<IA>(N, N / 10); Generator_sorted_end <IA> (N, N / 10);
cout<<empty_line; cout << empty_line;
cout<<"sorted + 0.1% mid |"; cout << "sorted + 0.1% mid |";
Generator_sorted_middle<IA>(N, N / 1000); Generator_sorted_middle <IA> (N, N / 1000);
cout<<"sorted + 1% mid |"; cout << "sorted + 1% mid |";
Generator_sorted_middle<IA>(N, N / 100); Generator_sorted_middle <IA> (N, N / 100);
cout<<"sorted + 10% mid |"; cout << "sorted + 10% mid |";
Generator_sorted_middle<IA>(N, N / 10); Generator_sorted_middle <IA> (N, N / 10);
cout<<empty_line; cout << empty_line;
cout<<"reverse sorted |"; cout << "reverse sorted |";
Generator_reverse_sorted<IA>(N); Generator_reverse_sorted <IA> (N);
cout<<"rv sorted + 0.1% end|"; cout << "rv sorted + 0.1% end|";
Generator_reverse_sorted_end<IA>(N, N / 1000); Generator_reverse_sorted_end <IA> (N, N / 1000);
cout<<"rv sorted + 1% end|"; cout << "rv sorted + 1% end|";
Generator_reverse_sorted_end<IA>(N, N / 100); Generator_reverse_sorted_end <IA> (N, N / 100);
cout<<"rv sorted + 10% end|"; cout << "rv sorted + 10% end|";
Generator_reverse_sorted_end<IA>(N, N / 10); Generator_reverse_sorted_end <IA> (N, N / 10);
cout<<empty_line; cout << empty_line;
cout<<"rv sorted + 0.1% mid|"; cout << "rv sorted + 0.1% mid|";
Generator_reverse_sorted_middle<IA>(N, N / 1000); Generator_reverse_sorted_middle <IA> (N, N / 1000);
cout<<"rv sorted + 1% mid|"; cout << "rv sorted + 1% mid|";
Generator_reverse_sorted_middle<IA>(N, N / 100); Generator_reverse_sorted_middle <IA> (N, N / 100);
cout<<"rv sorted + 10% mid|"; cout << "rv sorted + 10% mid|";
Generator_reverse_sorted_middle<IA>(N, N / 10); Generator_reverse_sorted_middle <IA> (N, N / 10);
cout<< "--------------------+-----------+-----------+-----------+\n"; cout << "--------------------+-----------+-----------+-----------+\n";
cout<<endl<<endl<<endl; cout << endl << endl << endl;
} }
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2) void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2)
{ {
assert ( V1.size() == V2.size()); assert ( V1.size() == V2.size());
std::cout<<std::setprecision(2)<<std::fixed; std::cout << std::setprecision(2)<<std::fixed;
for ( uint32_t i =0 ; i < V1.size() ; ++i) for ( uint32_t i =0 ; i < V1.size() ; ++i)
{ std::cout<<std::right<<std::setw(5)<<V1[i]<<" "; { std::cout << std::right<<std::setw(5)<<V1[i]<<" ";
std::cout<<std::right<<std::setw(5)<<V2[i]<<"|"; std::cout << std::right<<std::setw(5)<<V2[i]<<"|";
}; };
std::cout<<std::endl; std::cout << std::endl;
} }
template <class IA> template <class IA>
void Generator_random(uint64_t N) void Generator_random (uint64_t N)
{ {
bsc::uint64_file_generator gen("input.bin"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate(gen));
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_comp <IA> (), V1);
Test (A, L_comp <IA> (), V2);
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Print_vectors (V1, V2) ;
Print_vectors ( V1, V2 ) ;
}; };
template <class IA> template <class IA>
void Generator_sorted(uint64_t N) void Generator_sorted(uint64_t N)
{ {
bsc::uint64_file_generator gen("input.bin"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
std::sort( A.begin() , A.end(),H_comp<IA>() ); std::sort (A.begin (), A.end (), H_comp <IA> ());
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_comp <IA> (), V1);
std::sort( A.begin() , A.end(),L_comp<IA>() ); std::sort (A.begin (), A.end (), L_comp <IA> ());
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
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"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) for (uint32_t i = 0; i < (N + n_last); i++)
A.emplace_back(IA::generate(gen)); A.emplace_back (IA::generate (gen));
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
std::sort (A.begin (), A.begin () + N, H_comp <IA> ());
Test(A, H_rightshift<IA>(), H_comp<IA>(),V1); Test (A, H_comp <IA> (), V1);
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>()); std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
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"); assert (n_middle > 1 && N >= (n_middle -1));
std::vector<double> V1, V2 ; bsc::uint64_file_generator gen ("input.bin");
vector<IA> A;
A.reserve(N + n_last); std::vector <double> V1, V2; // vector with the times used
vector <IA> 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 <IA> ());
//------------------------------------------------------------------------
// 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;
{ A.clear() ; for (size_t i = 1; i < n_middle; ++i)
gen.reset(); {
vector<IA> B, C; for (size_t k = 0 ; k < step; ++k)
C.reserve(N + n_last); A [pos_write ++] = std::move (A [pos_read ++]);
B.reserve ( n_last); A [pos_write ++] = std::move (aux [i]);
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<IA>());
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++]);
}; };
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_comp <IA> (), V1);
{ A.clear() ; //----------------------------------------------------------------------
gen.reset(); // L _ C O M P
vector<IA> B,C; //-----------------------------------------------------------------------
C.reserve(N + n_last); gen.reset ();
B.reserve ( n_last); A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) A.reserve (N + n_middle);
C.emplace_back(IA::generate(gen)); 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 <IA> ());
//------------------------------------------------------------------------
// 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 = N ; i < C.size() ; ++i) for (size_t i = 1; i < n_middle; ++i)
B.push_back ( std::move ( C[i])); {
for (size_t k = 0 ; k < step; ++k)
C.resize ( N); A [pos_write ++] = std::move (A [pos_read ++]);
A [pos_write ++] = std::move (aux [i]);
std::sort ( C.begin() , C.end() ,L_comp<IA>());
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++]);
}; };
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
Print_vectors ( V1, V2 ) ; Test (A, L_comp <IA> (), V2);
Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
void Generator_reverse_sorted(uint64_t N) void Generator_reverse_sorted (uint64_t N)
{ {
bsc::uint64_file_generator gen("input.bin"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
std::sort( A.begin() , A.end(),H_comp<IA>() ); std::sort (A.begin (), A.end (), H_comp <IA> ());
for ( size_t i = 0; i < (A.size() >>1) ; ++i) for (size_t i = 0; i < (A.size () >>1); ++i)
std::swap ( A[i], A[A.size() - i -1 ]); std::swap (A [i], A [A.size () - i - 1]);
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_comp <IA> (), V1);
std::sort( A.begin() , A.end(),L_comp<IA>() ); std::sort (A.begin (), A.end (), L_comp <IA> ());
for ( size_t i = 0; i < (A.size() >>1) ; ++i) for (size_t i = 0; i < (A.size () >> 1); ++i)
std::swap ( A[i], A[A.size() - i -1 ]); std::swap (A [i], A [A.size() - i - 1]);
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
Print_vectors ( V1, V2 ) ; Test (A, L_comp <IA> (), V2);
Print_vectors (V1, V2) ;
}; };
template <class IA>
void Generator_reverse_sorted_end(uint64_t N, size_t n_last )
{
bsc::uint64_file_generator gen("input.bin");
vector<IA> A;
A.reserve(N);
std::vector<double> V1, V2 ;
gen.reset(); template <class IA>
A.clear(); void Generator_reverse_sorted_end (uint64_t N, size_t n_last )
{
bsc::uint64_file_generator gen ("input.bin");
vector <IA> A;
A.reserve (N);
std::vector <double> V1, V2 ;
gen.reset ();
A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) for (uint32_t i = 0; i < (N + n_last); i++)
A.emplace_back(IA::generate(gen)); A.emplace_back (IA::generate (gen));
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
for ( size_t i =0 ; i < (N>>1); ++i) std::sort (A.begin (), A.begin () + N , H_comp <IA> ());
std::swap ( A[i], A[N-1-i]); for (size_t i =0 ; i < (N >> 1); ++i)
std::swap (A [i], A [N - 1 - i]);
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_comp <IA> (), V1);
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>()); std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
for ( size_t i =0 ; i < (N>>1); ++i) for (size_t i = 0; i < (N >> 1); ++i)
std::swap ( A[i], A[N-1-i]); std::swap (A [i], A [N - 1 - i]);
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
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"); assert (n_middle > 1 && N >= (n_middle -1));
std::vector<double> V1, V2 ; bsc::uint64_file_generator gen ("input.bin");
vector<IA> A;
A.reserve(N + n_last); std::vector <double> V1, V2; // vector with the times used
vector <IA> 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 <IA> ());
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;
{ A.clear() ; for (size_t i = 1; i < n_middle; ++i)
gen.reset(); {
vector<IA> B,C; for (size_t k = 0 ; k < step; ++k)
C.reserve(N + n_last); A [pos_write ++] = std::move (A [pos_read ++]);
B.reserve ( n_last); A [pos_write ++] = std::move (aux [i]);
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<IA>());
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++]);
}; };
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_comp <IA> (), V1);
{ A.clear() ; //----------------------------------------------------------------------
gen.reset(); // L _ C O M P
vector<IA> B,C; //-----------------------------------------------------------------------
C.reserve(N + n_last); gen.reset ();
B.reserve ( n_last); A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) A.reserve (N + n_middle);
C.emplace_back(IA::generate(gen)); 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 <IA> ());
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 = N ; i < C.size() ; ++i) for (size_t i = 1; i < n_middle; ++i)
B.push_back ( std::move ( C[i])); {
for (size_t k = 0 ; k < step; ++k)
C.resize ( N); A [pos_write ++] = std::move (A [pos_read ++]);
A [pos_write ++] = std::move (aux [i]);
std::sort ( C.begin() , C.end() ,L_comp<IA>());
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++]);
}; };
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template<class IA, class rightshift, class compare> template<class IA, class compare>
int Test (std::vector<IA> &B, rightshift shift, compare comp,std::vector<double> &V) void Test (std::vector <IA> &B, compare comp, std::vector <double> &V)
{ //---------------------------- begin -------------------------------- { //---------------------------- begin --------------------------------
double duration; double duration;
time_point start, finish; time_point start, finish;
@@ -514,52 +525,5 @@ int Test (std::vector<IA> &B, rightshift shift, compare comp,std::vector<double>
finish = now (); finish = now ();
duration = subtract_time (finish, start); duration = subtract_time (finish, start);
V.push_back (duration); 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;
}; };

View File

@@ -40,18 +40,17 @@ using bsc::subtract_time;
void Generator_random (void); void Generator_random (void);
void Generator_sorted(void); void Generator_sorted (void);
void Generator_sorted_end(size_t n_last); void Generator_sorted_end( size_t n_last);
void Generator_sorted_middle (size_t n_last); void Generator_sorted_middle (size_t n_middle);
void Generator_reverse_sorted(void); void Generator_reverse_sorted (void);
void Generator_reverse_sorted_end(size_t n_last); void Generator_reverse_sorted_end (size_t n_last);
void Generator_reverse_sorted_middle(size_t n_last); void Generator_reverse_sorted_middle (size_t n_middle);
template <class IA, class compare> void Test (std::vector <std::string> &B);
int Test(std::vector<IA> &B, compare comp = compare());
int main(int argc, char *argv[]) int main(int argc, char *argv [])
{ {
cout << "\n\n"; cout << "\n\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
@@ -64,212 +63,223 @@ int main(int argc, char *argv[])
cout << "************************************************************\n"; cout << "************************************************************\n";
cout << std::endl; cout << std::endl;
cout<<"[ 1 ] block_indirect_sort [ 2 ] sample_sort\n"; cout << "[ 1 ] block_indirect_sort [ 2 ] sample_sort\n";
cout<<"[ 3 ] parallel_stable_sort\n\n"; cout << "[ 3 ] parallel_stable_sort\n\n";
cout<<" | | | |\n"; cout << " | | | |\n";
cout<<" | [ 1 ]| [ 2 ]| [ 3 ]|\n"; cout << " | [ 1 ]| [ 2 ]| [ 3 ]|\n";
cout<<"--------------------+------+------+------+\n"; cout << "--------------------+------+------+------+\n";
std::string empty_line = std::string empty_line =
" | | | |\n"; " | | | |\n";
cout<<"random |"; cout << "random |";
Generator_random (); Generator_random ();
cout<<empty_line; cout << empty_line;
cout<<"sorted |"; cout << "sorted |";
Generator_sorted(); Generator_sorted ();
cout<<"sorted + 0.1% end |"; cout << "sorted + 0.1% end |";
Generator_sorted_end(NMAXSTRING / 1000); Generator_sorted_end (NMAXSTRING / 1000);
cout<<"sorted + 1% end |"; cout << "sorted + 1% end |";
Generator_sorted_end(NMAXSTRING / 100); Generator_sorted_end (NMAXSTRING / 100);
cout<<"sorted + 10% end |"; cout << "sorted + 10% end |";
Generator_sorted_end(NMAXSTRING / 10); Generator_sorted_end (NMAXSTRING / 10);
cout<<empty_line; cout << empty_line;
cout<<"sorted + 0.1% mid |"; cout << "sorted + 0.1% mid |";
Generator_sorted_middle (NMAXSTRING / 1000); Generator_sorted_middle (NMAXSTRING / 1000);
cout<<"sorted + 1% mid |"; cout << "sorted + 1% mid |";
Generator_sorted_middle (NMAXSTRING / 100); Generator_sorted_middle (NMAXSTRING / 100);
cout<<"sorted + 10% mid |"; cout << "sorted + 10% mid |";
Generator_sorted_middle (NMAXSTRING / 10 ); Generator_sorted_middle (NMAXSTRING / 10 );
cout<<empty_line; cout << empty_line;
cout<<"reverse sorted |"; cout << "reverse sorted |";
Generator_reverse_sorted(); Generator_reverse_sorted ();
cout<<"rv sorted + 0.1% end|"; cout << "rv sorted + 0.1% end|";
Generator_reverse_sorted_end(NMAXSTRING / 1000); Generator_reverse_sorted_end (NMAXSTRING / 1000);
cout<<"rv sorted + 1% end|"; cout << "rv sorted + 1% end|";
Generator_reverse_sorted_end(NMAXSTRING / 100); Generator_reverse_sorted_end (NMAXSTRING / 100);
cout<<"rv sorted + 10% end|"; cout << "rv sorted + 10% end|";
Generator_reverse_sorted_end(NMAXSTRING / 10); Generator_reverse_sorted_end (NMAXSTRING / 10);
cout<<empty_line; cout << empty_line;
cout<<"rv sorted + 0.1% mid|"; cout << "rv sorted + 0.1% mid|";
Generator_reverse_sorted_middle(NMAXSTRING / 1000); Generator_reverse_sorted_middle (NMAXSTRING / 1000);
cout<<"rv sorted + 1% mid|"; cout << "rv sorted + 1% mid|";
Generator_reverse_sorted_middle(NMAXSTRING / 100); Generator_reverse_sorted_middle (NMAXSTRING / 100);
cout<<"rv sorted + 10% mid|"; cout << "rv sorted + 10% mid|";
Generator_reverse_sorted_middle(NMAXSTRING / 10); Generator_reverse_sorted_middle (NMAXSTRING / 10);
cout<< "--------------------+------+------+------+\n"; cout << "--------------------+------+------+------+\n";
cout<<endl<<endl ; cout << endl <<endl ;
return 0; return 0;
} }
void Generator_random(void) void Generator_random (void)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
Test<std::string, std::less<std::string>>(A); Test (A);
}; };
void Generator_sorted(void) void Generator_sorted (void)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort( A.begin() , A.end() ); std::sort (A.begin (), A.end ());
Test<std::string, std::less<std::string>>(A); Test (A);
}; };
void Generator_sorted_end(size_t n_last) void Generator_sorted_end (size_t n_last)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING+ n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin() , A.begin() + NMAXSTRING ); std::sort (A.begin (), A.begin () + NMAXSTRING );
Test<std::string, std::less<std::string>>(A); Test (A);
}; };
void Generator_sorted_middle(size_t n_last) void Generator_sorted_middle (size_t n_middle)
{ {
std::vector<std::string> A,B,C; assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
A.reserve(NMAXSTRING); vector <std::string> A, aux;
A.clear(); A.reserve (NMAXSTRING + n_middle);
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) aux.reserve (n_middle);
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [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) std::sort (A.begin () + n_middle, A.end ());
{ C.push_back ( B[i]); //------------------------------------------------------------------------
for ( size_t k = 0 ; k < step ; ++k ) // To insert n_middle elements, must have (n_middle - 1) intervals between
C.push_back ( A[pos + k] ); // 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++]); aux.clear ();
A = C ; aux.reserve (0);
Test (A);
Test<std::string, std::less<std::string>>(A);
}; };
void Generator_reverse_sorted (void)
void Generator_reverse_sorted(void)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); {
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) std::vector <std::string> 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]);
};
Test (A);
};
void Generator_reverse_sorted_end (size_t n_last)
{
std::vector <std::string> 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"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort( A.begin() , A.end()); std::sort (A.begin (), A.begin () + NMAXSTRING);
size_t nmid = (A.size() >>1), nlast = A.size() -1 ; for (size_t i = 0; i < (NMAXSTRING >> 1); ++i)
for (size_t i = 0 ; i < nmid ;++i) std::swap (A [i], A [NMAXSTRING - 1 - i]);
std::swap ( A[i], A [nlast -i]);
Test<std::string, std::less<std::string>>(A);
Test (A);
}; };
void Generator_reverse_sorted_end(size_t n_last) void Generator_reverse_sorted_middle (size_t n_middle)
{ {
std::vector<std::string> A; assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
A.reserve(NMAXSTRING); vector <std::string> A, aux;
A.clear(); A.reserve (NMAXSTRING + n_middle);
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) aux.reserve (n_middle);
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; 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 < n_middle; ++i) aux.push_back (std::move (A [i]));
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i)
std::swap ( A[i], A[NMAXSTRING - 1 - i]);
Test<std::string, std::less<std::string>>(A); 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)
void Generator_reverse_sorted_middle(size_t n_last)
{
std::vector<std::string> A,B,C;
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"; for (size_t k = 0 ; k < step; ++k)
return; A [pos_write ++] = std::move (A [pos_read ++]);
A [pos_write ++] = std::move (aux [i]);
}; };
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) aux.clear ();
B.push_back ( std::move ( A[i])); aux.reserve (0);
A.resize ( NMAXSTRING); Test (A);
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] );
};
while ( pos < A.size() )
C.push_back ( A[pos++]);
A = C ;
Test<std::string, std::less<std::string>>(A);
}; };
void Test (std::vector <std::string> &B)
template<class IA, class compare>
int Test (std::vector<IA> &B, compare comp)
{ //---------------------------- begin -------------------------------- { //---------------------------- begin --------------------------------
std::less <std::string> comp;
double duration; double duration;
time_point start, finish; time_point start, finish;
std::vector<IA> A (B); std::vector <std::string> A (B);
std::vector<double> V; std::vector <double> V;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
A = B; A = B;
@@ -296,11 +306,11 @@ int Test (std::vector<IA> &B, compare comp)
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// printing the vector // printing the vector
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
std::cout<<std::setprecision(2)<<std::fixed; std::cout << std::setprecision (2) << std::fixed;
for ( uint32_t i =0 ; i < V.size() ; ++i) for (uint32_t i = 0; i < V.size (); ++i)
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |"; { std::cout << std::right << std::setw (5) << V [i] << " |";
}; };
std::cout<<std::endl; std::cout << std::endl;
return 0;
}; };

View File

@@ -25,7 +25,7 @@ namespace bsc = boost::sort::common;
void print_banner(); void print_banner();
int main(int argc, char *argv[]) int main(int argc, char *argv [])
{ //---------------------------- begin-------------------------------------- { //---------------------------- begin--------------------------------------
std::string name; std::string name;
size_t number; size_t number;
@@ -38,13 +38,13 @@ int main(int argc, char *argv[])
return 0; return 0;
}; };
name = argv[1]; name = argv[1];
number = atoi(argv[2]); number = atoi (argv[ 2]);
if (number == 0) { if (number == 0) {
cout << "error, the number can't be zero\n"; cout << "error, the number can't be zero\n";
return 0; return 0;
}; };
if (bsc::generate_file(name, number) != 0) if (bsc::generate_file (name, number) != 0)
std::cout << "Error in the file creation\n"; std::cout << "Error in the file creation\n";
return 0; return 0;
}; };

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_objects clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_objects
echo "." echo "."
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 60 minutes depending of your machine )" echo "( The time needed is around 60 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_strings g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_strings
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_numbers
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_objects g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_objects
echo "." echo "."
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 60 minutes depending of your machine )" echo "( The time needed is around 60 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -pthread -s -lpthread -o benchmark_strings g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -pthread -s -lpthread -o benchmark_strings
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -48,14 +48,13 @@ using bsort::pdqsort;
void Generator_random (void); void Generator_random (void);
void Generator_sorted (void); void Generator_sorted (void);
void Generator_sorted_end (size_t n_last); void Generator_sorted_end (uint64_t n_last);
void Generator_sorted_middle (size_t n_last); void Generator_sorted_middle (uint64_t n_middle);
void Generator_reverse_sorted (void); void Generator_reverse_sorted (void);
void Generator_reverse_sorted_end (size_t n_last); void Generator_reverse_sorted_end (uint64_t n_last);
void Generator_reverse_sorted_middle (size_t n_last); void Generator_reverse_sorted_middle (uint64_t n_middle);
template<class IA, class compare> void Test (const std::vector <uint64_t> &B);
int Test (std::vector<IA> &B, compare comp = compare ());
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
@@ -129,34 +128,28 @@ int main (int argc, char *argv[])
cout<<endl<<endl ; cout<<endl<<endl ;
return 0; return 0;
} }
void void Generator_random (void)
Generator_random (void)
{ {
vector<uint64_t> A; vector <uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
if (fill_vector_uint64 ("input.bin", A, NELEM) != 0) if (fill_vector_uint64 ("input.bin", A, NELEM) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
} };
; void Generator_sorted (void)
void
Generator_sorted (void)
{ {
vector<uint64_t> A; vector<uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
for (size_t i = 0; i < NELEM; ++i) for (uint64_t i = 0; i < NELEM; ++i)
A.push_back (i); A.push_back (i);
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
};
} void Generator_sorted_end (uint64_t n_last)
void Generator_sorted_end (size_t n_last)
{ {
vector<uint64_t> A; vector<uint64_t> A;
A.reserve (NELEM); 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) if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin (), A.begin () + NELEM); std::sort (A.begin (), A.begin () + NELEM);
Test (A);
Test<uint64_t, std::less<uint64_t>> (A); };
void Generator_sorted_middle (uint64_t n_middle)
}
;
void Generator_sorted_middle (size_t n_last)
{ {
vector<uint64_t> A, B, C; assert (n_middle > 1 && NELEM >= (n_middle -1));
A.reserve (NELEM); vector <uint64_t> A, aux;
A.clear (); A.reserve (NELEM + n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) aux.reserve (n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for (size_t i = NELEM; i < A.size (); ++i) for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [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 ()); std::sort (A.begin () + n_middle, A.end ());
size_t step = NELEM / n_last + 1; //------------------------------------------------------------------------
size_t pos = 0; // 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 (size_t i = 0; i < B.size (); ++i, pos += step) for (uint64_t i = 1; i < n_middle; ++i)
{ {
C.push_back (B[i]); for (uint64_t k = 0 ; k < step; ++k)
for (size_t k = 0; k < step; ++k) A [pos_write ++] = A [pos_read ++];
C.push_back (A[pos + k]); A [pos_write ++] = aux [i];
}; };
while (pos < A.size ()) aux.clear ();
C.push_back (A[pos++]); aux.reserve (0);
A = C; Test (A);
Test<uint64_t, std::less<uint64_t>> (A); };
}
;
void Generator_reverse_sorted (void) void Generator_reverse_sorted (void)
{ {
vector<uint64_t> A; vector<uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
for (size_t i = NELEM; i > 0; --i) for (uint64_t i = NELEM; i > 0; --i)
A.push_back (i); A.push_back (i);
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
} };
void Generator_reverse_sorted_end (size_t n_last) void Generator_reverse_sorted_end (uint64_t n_last)
{ {
vector<uint64_t> A; vector <uint64_t> A;
A.reserve (NELEM); A.reserve (NELEM);
A.clear (); A.clear ();
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin (), A.begin () + NELEM); std::sort (A.begin (), A.begin () + NELEM);
for (size_t i = 0; i < (NELEM >> 1); ++i) for (uint64_t i = 0; i < (NELEM >> 1); ++i)
std::swap (A[i], A[NELEM - 1 - i]); std::swap (A [i], A [NELEM - 1 - i]);
Test<uint64_t, std::less<uint64_t>> (A); Test (A);
} }
void Generator_reverse_sorted_middle (size_t n_last) void Generator_reverse_sorted_middle (uint64_t n_middle)
{ {
vector<uint64_t> A, B, C; assert (n_middle > 1 && NELEM >= (n_middle -1));
A.reserve (NELEM); vector <uint64_t> A, aux;
A.clear (); A.reserve (NELEM + n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_last) != 0) aux.reserve (n_middle);
if (fill_vector_uint64 ("input.bin", A, NELEM + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for (size_t i = NELEM; i < A.size (); ++i) for (uint64_t i = 0; i < n_middle; ++i) aux.push_back (A [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 ()); std::sort (A.begin () + n_middle, A.end ());
size_t step = NELEM / n_last + 1; uint64_t pos1 = n_middle, pos2 = A.size () - 1;
size_t pos = 0; 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 (size_t i = 0; i < B.size (); ++i, pos += step) for (uint64_t i = 1; i < n_middle; ++i)
{ {
C.push_back (B[i]); for (uint64_t k = 0 ; k < step; ++k)
for (size_t k = 0; k < step; ++k) A [pos_write ++] = A [pos_read ++];
C.push_back (A[pos + k]); A [pos_write ++] = aux [i];
}; };
while (pos < A.size ()) aux.clear ();
C.push_back (A[pos++]); aux.reserve (0);
A = C; Test (A);
Test<uint64_t, std::less<uint64_t>> (A);
}; };
void Test (const std::vector <uint64_t> &B)
{
template<class IA, class compare> //---------------------------- begin --------------------------------
int Test (std::vector<IA> &B, compare comp) std::less <uint64_t> comp ;
{ //---------------------------- begin --------------------------------
double duration; double duration;
time_point start, finish; time_point start, finish;
std::vector<IA> A (B); std::vector <uint64_t> A (B);
std::vector<double> V; std::vector <double> V;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
A = B; A = B;
@@ -307,7 +303,6 @@ int Test (std::vector<IA> &B, compare comp)
duration = subtract_time (finish, start); duration = subtract_time (finish, start);
V.push_back (duration); V.push_back (duration);
A = B; A = B;
start = now (); start = now ();
spreadsort (A.begin (), A.end ()); spreadsort (A.begin (), A.end ());
@@ -318,11 +313,10 @@ int Test (std::vector<IA> &B, compare comp)
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// printing the vector // printing the vector
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
std::cout<<std::setprecision(2)<<std::fixed; std::cout<<std::setprecision (2) <<std::fixed;
for ( uint32_t i =0 ; i < V.size() ; ++i) for ( uint32_t i =0 ; i < V.size () ; ++i)
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |"; {
std::cout<<std::right<<std::setw (5)<<V [i]<<" |";
}; };
std::cout<<std::endl; std::cout<<std::endl;
return 0;
}; };

View File

@@ -26,13 +26,8 @@
#include <boost/sort/common/time_measure.hpp> #include <boost/sort/common/time_measure.hpp>
#include <boost/sort/common/file_vector.hpp> #include <boost/sort/common/file_vector.hpp>
#include "boost/sort/common/int_array.hpp" #include "boost/sort/common/int_array.hpp"
#include <boost/sort/sort.hpp> #include <boost/sort/sort.hpp>
#define NELEM 100000000
#define NMAXSTRING 10000000
using namespace std; using namespace std;
namespace bsort = boost::sort; namespace bsort = boost::sort;
namespace bsc = bsort::common; namespace bsc = bsort::common;
@@ -54,49 +49,55 @@ using bsort::pdqsort;
template <class IA> template <class IA>
void Generator_random(uint64_t N); void Generator_random (uint64_t N);
template <class IA> template <class IA>
void Generator_sorted(uint64_t N); void Generator_sorted (uint64_t N);
template <class IA> template <class IA>
void Generator_sorted_end(uint64_t N, size_t n_last ); void Generator_sorted_end (uint64_t N, size_t n_last );
template <class IA> template <class IA>
void Generator_sorted_middle(uint64_t N, size_t n_last ); void Generator_sorted_middle (uint64_t N, size_t n_middle );
template <class IA> template <class IA>
void Generator_reverse_sorted(uint64_t N); void Generator_reverse_sorted (uint64_t N);
template <class IA> template <class IA>
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 <class IA> template <class IA>
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 > template <class IA>
struct H_rightshift { struct H_rightshift
inline uint64_t operator()(const IA& A1, unsigned offset) { {
return A1.counter() >> offset; inline uint64_t operator () (const IA& A1, unsigned offset)
} {
return A1.counter () >> offset;
};
}; };
template < class IA > template <class IA>
struct L_rightshift { struct L_rightshift
inline uint64_t operator()(const IA& A1, unsigned offset) { {
return A1.M[0] >> offset; inline uint64_t operator () (const IA& A1, unsigned offset)
} {
return A1.M[0] >> offset;
};
}; };
template <class IA, class rightshift, class compare> template <class IA, class rightshift, class compare>
int Test(std::vector<IA> &B, rightshift shift, compare comp, std::vector<double> & V ); int Test (std::vector< IA> &B, rightshift shift,
compare comp, std::vector <double> & V );
template <class IA> template <class IA>
void Test_size ( uint64_t N); void Test_size (uint64_t N);
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2); void Print_vectors ( std::vector <double> &V1, std::vector <double> &V2);
int main(int argc, char *argv[]) int main(int argc, char *argv [])
{ {
const uint64_t NELEM = 100000000;
cout << "\n\n"; cout << "\n\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
cout << "** **\n"; cout << "** **\n";
@@ -130,7 +131,7 @@ int main(int argc, char *argv[])
cout << "** **\n"; cout << "** **\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
Test_size<int_array<1> >(NELEM); Test_size <int_array <1> >(NELEM);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// I N T _ A R R A Y < 4 > // 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 << " "<<(NELEM >>2)<<" OBJECTS UINT64_T [4]\n";
cout << "** **\n"; cout << "** **\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
Test_size<int_array<4> >(NELEM >> 2); Test_size <int_array <4> >(NELEM >> 2);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// I N T _ A R R A Y < 8 > // 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 << " "<<(NELEM >>3)<<" OBJECTS UINT64_T [8]\n";
cout << "** **\n"; cout << "** **\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
Test_size<int_array<8> >(NELEM >> 3); Test_size <int_array <8> >(NELEM >> 3);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// I N T _ A R R A Y < 1 6 > // 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 << " "<<(NELEM >>4)<<" OBJECTS UINT64_T [16]\n";
cout << "** **\n"; cout << "** **\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
Test_size<int_array<16> >(NELEM >> 4); Test_size <int_array <16> >(NELEM >> 4);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// I N T _ A R R A Y < 6 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 << " "<< (NELEM >>6)<<" OBJECTS UINT64_T [64]\n";
cout << "** **\n"; cout << "** **\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
Test_size<int_array<64> >(NELEM >> 6); Test_size <int_array <64> >(NELEM >> 6);
return 0; return 0;
} }
template <class IA> template <class IA>
void Test_size ( uint64_t N) void Test_size (uint64_t N)
{ {
cout<<"\n"; cout<<"\n";
cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n"; cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n";
@@ -197,317 +198,349 @@ void Test_size ( uint64_t N)
" | | | |\n"; " | | | |\n";
cout<<"random |"; cout<<"random |";
Generator_random<IA>(N); Generator_random <IA> (N);
cout<<empty_line; cout<<empty_line;
cout<<"sorted |"; cout<<"sorted |";
Generator_sorted<IA>(N); Generator_sorted <IA> (N);
cout<<"sorted + 0.1% end |"; cout<<"sorted + 0.1% end |";
Generator_sorted_end<IA>(N, N / 1000); Generator_sorted_end <IA> (N, N / 1000);
cout<<"sorted + 1% end |"; cout<<"sorted + 1% end |";
Generator_sorted_end<IA>(N, N / 100); Generator_sorted_end <IA> (N, N / 100);
cout<<"sorted + 10% end |"; cout<<"sorted + 10% end |";
Generator_sorted_end<IA>(N, N / 10); Generator_sorted_end <IA> (N, N / 10);
cout<<empty_line; cout<<empty_line;
cout<<"sorted + 0.1% mid |"; cout<<"sorted + 0.1% mid |";
Generator_sorted_middle<IA>(N, N / 1000); Generator_sorted_middle <IA> (N, N / 1000);
cout<<"sorted + 1% mid |"; cout<<"sorted + 1% mid |";
Generator_sorted_middle<IA>(N, N / 100); Generator_sorted_middle <IA> (N, N / 100);
cout<<"sorted + 10% mid |"; cout<<"sorted + 10% mid |";
Generator_sorted_middle<IA>(N, N / 10); Generator_sorted_middle <IA> (N, N / 10);
cout<<empty_line; cout<<empty_line;
cout<<"reverse sorted |"; cout<<"reverse sorted |";
Generator_reverse_sorted<IA>(N); Generator_reverse_sorted <IA> (N);
cout<<"rv sorted + 0.1% end|"; cout<<"rv sorted + 0.1% end|";
Generator_reverse_sorted_end<IA>(N, N / 1000); Generator_reverse_sorted_end <IA> (N, N / 1000);
cout<<"rv sorted + 1% end|"; cout<<"rv sorted + 1% end|";
Generator_reverse_sorted_end<IA>(N, N / 100); Generator_reverse_sorted_end <IA> (N, N / 100);
cout<<"rv sorted + 10% end|"; cout<<"rv sorted + 10% end|";
Generator_reverse_sorted_end<IA>(N, N / 10); Generator_reverse_sorted_end <IA> (N, N / 10);
cout<<empty_line; cout<<empty_line;
cout<<"rv sorted + 0.1% mid|"; cout<<"rv sorted + 0.1% mid|";
Generator_reverse_sorted_middle<IA>(N, N / 1000); Generator_reverse_sorted_middle <IA> (N, N / 1000);
cout<<"rv sorted + 1% mid|"; cout<<"rv sorted + 1% mid|";
Generator_reverse_sorted_middle<IA>(N, N / 100); Generator_reverse_sorted_middle <IA> (N, N / 100);
cout<<"rv sorted + 10% mid|"; cout<<"rv sorted + 10% mid|";
Generator_reverse_sorted_middle<IA>(N, N / 10); Generator_reverse_sorted_middle <IA> (N, N / 10);
cout<< "--------------------+-----------+-----------+-----------+"; cout << "--------------------+-----------+-----------+-----------+";
cout << "-----------+-----------+-----------+\n"; cout << "-----------+-----------+-----------+\n";
cout<<endl<<endl<<endl; cout<<endl<<endl<<endl;
} }
void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2) void Print_vectors ( std::vector<double> & V1, std::vector<double> & V2)
{ {
assert ( V1.size() == V2.size()); assert ( V1.size () == V2.size ());
std::cout<<std::setprecision(2)<<std::fixed; std::cout << std::setprecision (2) << std::fixed;
for ( uint32_t i =0 ; i < V1.size() ; ++i)
{ std::cout<<std::right<<std::setw(5)<<V1[i]<<" "; for ( uint32_t i =0 ; i < V1.size () ; ++i)
std::cout<<std::right<<std::setw(5)<<V2[i]<<"|"; {
std::cout << std::right << std::setw (5) << V1 [i] << " ";
std::cout << std::right << std::setw (5) << V2 [i] <<"|";
}; };
std::cout<<std::endl; std::cout<<std::endl;
} }
template <class IA> template <class IA>
void Generator_random(uint64_t N) void Generator_random (uint64_t N)
{ {
bsc::uint64_file_generator gen("input.bin"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate(gen));
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test(A, H_rightshift <IA> (), H_comp <IA> (), V1);
Test(A, L_rightshift <IA> (), L_comp <IA> (), V2);
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Print_vectors (V1, V2) ;
Print_vectors ( V1, V2 ) ;
}; };
template <class IA> template <class IA>
void Generator_sorted(uint64_t N) void Generator_sorted(uint64_t N)
{ {
bsc::uint64_file_generator gen("input.bin"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
std::sort( A.begin() , A.end(),H_comp<IA>() ); std::sort (A.begin (), A.end (), H_comp <IA> ());
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
std::sort( A.begin() , A.end(),L_comp<IA>() ); std::sort (A.begin (), A.end (), L_comp <IA> ());
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
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"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) for (uint32_t i = 0; i < (N + n_last); i++)
A.emplace_back(IA::generate(gen)); A.emplace_back (IA::generate (gen));
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
std::sort (A.begin (), A.begin () + N, H_comp <IA> ());
Test(A, H_rightshift<IA>(), H_comp<IA>(),V1); Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>()); std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
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"); assert (n_middle > 1 && N >= (n_middle -1));
std::vector<double> V1, V2 ; bsc::uint64_file_generator gen ("input.bin");
vector<IA> A;
A.reserve(N + n_last); std::vector <double> V1, V2; // vector with the times used
vector <IA> 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 <IA> ());
//------------------------------------------------------------------------
// 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;
{ A.clear() ; for (size_t i = 1; i < n_middle; ++i)
gen.reset(); {
vector<IA> B, C; for (size_t k = 0 ; k < step; ++k)
C.reserve(N + n_last); A [pos_write ++] = std::move (A [pos_read ++]);
B.reserve ( n_last); A [pos_write ++] = std::move (aux [i]);
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<IA>());
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++]);
}; };
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
{ A.clear() ; //----------------------------------------------------------------------
gen.reset(); // L _ C O M P
vector<IA> B,C; //-----------------------------------------------------------------------
C.reserve(N + n_last); gen.reset ();
B.reserve ( n_last); A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) A.reserve (N + n_middle);
C.emplace_back(IA::generate(gen)); 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 <IA> ());
//------------------------------------------------------------------------
// 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 = N ; i < C.size() ; ++i) for (size_t i = 1; i < n_middle; ++i)
B.push_back ( std::move ( C[i])); {
for (size_t k = 0 ; k < step; ++k)
C.resize ( N); A [pos_write ++] = std::move (A [pos_read ++]);
A [pos_write ++] = std::move (aux [i]);
std::sort ( C.begin() , C.end() ,L_comp<IA>());
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++]);
}; };
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
Print_vectors ( V1, V2 ) ; Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
void Generator_reverse_sorted(uint64_t N) void Generator_reverse_sorted (uint64_t N)
{ {
bsc::uint64_file_generator gen("input.bin"); bsc::uint64_file_generator gen ("input.bin");
vector<IA> A; vector <IA> A;
A.reserve(N); A.reserve (N);
std::vector<double> V1, V2 ; std::vector <double> V1, V2 ;
gen.reset(); gen.reset ();
A.clear(); A.clear ();
for (uint32_t i = 0; i < N; i++) A.emplace_back(IA::generate(gen)); for (uint32_t i = 0; i < N; i++) A.emplace_back (IA::generate (gen));
std::sort( A.begin() , A.end(),H_comp<IA>() ); std::sort (A.begin (), A.end (), H_comp <IA> ());
for ( size_t i = 0; i < (A.size() >>1) ; ++i) for (size_t i = 0; i < (A.size () >>1); ++i)
std::swap ( A[i], A[A.size() - i -1 ]); std::swap (A [i], A [A.size () - i - 1]);
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
std::sort( A.begin() , A.end(),L_comp<IA>() ); std::sort (A.begin (), A.end (), L_comp <IA> ());
for ( size_t i = 0; i < (A.size() >>1) ; ++i) for (size_t i = 0; i < (A.size () >> 1); ++i)
std::swap ( A[i], A[A.size() - i -1 ]); std::swap (A [i], A [A.size() - i - 1]);
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2);
Print_vectors ( V1, V2 ) ; Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
Print_vectors (V1, V2) ;
}; };
template <class IA>
void Generator_reverse_sorted_end(uint64_t N, size_t n_last )
{
bsc::uint64_file_generator gen("input.bin");
vector<IA> A;
A.reserve(N);
std::vector<double> V1, V2 ;
gen.reset(); template <class IA>
A.clear(); void Generator_reverse_sorted_end (uint64_t N, size_t n_last )
{
bsc::uint64_file_generator gen ("input.bin");
vector <IA> A;
A.reserve (N);
std::vector <double> V1, V2 ;
gen.reset ();
A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) for (uint32_t i = 0; i < (N + n_last); i++)
A.emplace_back(IA::generate(gen)); A.emplace_back (IA::generate (gen));
std::sort ( A.begin() , A.begin() + N ,H_comp<IA>());
for ( size_t i =0 ; i < (N>>1); ++i) std::sort (A.begin (), A.begin () + N , H_comp <IA> ());
std::swap ( A[i], A[N-1-i]); for (size_t i =0 ; i < (N >> 1); ++i)
std::swap (A [i], A [N - 1 - i]);
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
std::sort ( A.begin() , A.begin() + N ,L_comp<IA>()); std::sort (A.begin (), A.begin () + N, L_comp <IA> ());
for ( size_t i =0 ; i < (N>>1); ++i) for (size_t i = 0; i < (N >> 1); ++i)
std::swap ( A[i], A[N-1-i]); std::swap (A [i], A [N - 1 - i]);
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template <class IA> template <class IA>
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"); assert (n_middle > 1 && N >= (n_middle -1));
std::vector<double> V1, V2 ; bsc::uint64_file_generator gen ("input.bin");
vector<IA> A;
A.reserve(N + n_last); std::vector <double> V1, V2; // vector with the times used
vector <IA> 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 <IA> ());
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;
{ A.clear() ; for (size_t i = 1; i < n_middle; ++i)
gen.reset(); {
vector<IA> B,C; for (size_t k = 0 ; k < step; ++k)
C.reserve(N + n_last); A [pos_write ++] = std::move (A [pos_read ++]);
B.reserve ( n_last); A [pos_write ++] = std::move (aux [i]);
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<IA>());
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++]);
}; };
Test(A, H_rightshift<IA>(), H_comp<IA>(), V1); Test (A, H_rightshift <IA> (), H_comp <IA> (), V1);
{ A.clear() ; //----------------------------------------------------------------------
gen.reset(); // L _ C O M P
vector<IA> B,C; //-----------------------------------------------------------------------
C.reserve(N + n_last); gen.reset ();
B.reserve ( n_last); A.clear ();
for (uint32_t i = 0; i < (N + n_last); i++) A.reserve (N + n_middle);
C.emplace_back(IA::generate(gen)); 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 <IA> ());
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 = N ; i < C.size() ; ++i) for (size_t i = 1; i < n_middle; ++i)
B.push_back ( std::move ( C[i])); {
for (size_t k = 0 ; k < step; ++k)
C.resize ( N); A [pos_write ++] = std::move (A [pos_read ++]);
A [pos_write ++] = std::move (aux [i]);
std::sort ( C.begin() , C.end() ,L_comp<IA>());
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++]);
}; };
Test(A, L_rightshift<IA>(), L_comp<IA>(), V2); Test (A, L_rightshift <IA> (), L_comp <IA> (), V2);
Print_vectors ( V1, V2 ) ; Print_vectors (V1, V2) ;
}; };
template<class IA, class rightshift, class compare> template <class IA, class rightshift, class compare>
int Test (std::vector<IA> &B, rightshift shift, compare comp,std::vector<double> &V) int Test (std::vector <IA> &B, rightshift shift,
compare comp, std::vector <double> &V)
{ //---------------------------- begin -------------------------------- { //---------------------------- begin --------------------------------
double duration; double duration;
time_point start, finish; time_point start, finish;
std::vector<IA> A (B); std::vector <IA> A (B);
V.clear() ; V.clear () ;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
A = B; A = B;

View File

@@ -47,18 +47,17 @@ using bsort::spreadsort::spreadsort;
using bsort::pdqsort; using bsort::pdqsort;
void Generator_random (void); void Generator_random (void);
void Generator_sorted(void); void Generator_sorted (void);
void Generator_sorted_end(size_t n_last); void Generator_sorted_end (size_t n_last);
void Generator_sorted_middle (size_t n_last); void Generator_sorted_middle (size_t n_last);
void Generator_reverse_sorted(void); void Generator_reverse_sorted (void);
void Generator_reverse_sorted_end(size_t n_last); void Generator_reverse_sorted_end (size_t n_last);
void Generator_reverse_sorted_middle(size_t n_last); void Generator_reverse_sorted_middle (size_t n_last);
template <class IA, class compare> int Test (std::vector <std::string> &B);
int Test(std::vector<IA> &B, compare comp = compare());
int main(int argc, char *argv[]) int main (int argc, char *argv [])
{ {
cout << "\n\n"; cout << "\n\n";
cout << "************************************************************\n"; cout << "************************************************************\n";
@@ -72,232 +71,224 @@ int main(int argc, char *argv[])
cout << "************************************************************\n"; cout << "************************************************************\n";
cout << std::endl; cout << std::endl;
cout<<"[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort \n"; cout << "[ 1 ] std::sort [ 2 ] pdqsort [ 3 ] std::stable_sort\n";
cout<<"[ 4 ] spinsort [ 5 ] flat_stable_sort [ 6 ] spreadsort\n\n"; cout << "[ 4 ] spinsort [ 5 ] flat_stable_sort [ 6 ] spreadsort\n\n";
cout<<" | | | | | | |\n"; cout << " | | | | | | |\n";
cout<<" | [ 1 ]| [ 2 ]| [ 3 ]| [ 4 ]| [ 5 ]| [ 6 ]|\n"; cout << " | [ 1 ]| [ 2 ]| [ 3 ]| [ 4 ]| [ 5 ]| [ 6 ]|\n";
cout<<"--------------------+------+------+------+------+------+------+\n"; cout << "--------------------+------+------+------+------+------+------+\n";
std::string empty_line = std::string empty_line =
" | | | | | | |\n"; " | | | | | | |\n";
cout<<"random |"; cout << "random |";
Generator_random (); Generator_random ();
cout<<empty_line; cout << empty_line;
cout<<"sorted |"; cout << "sorted |";
Generator_sorted(); Generator_sorted ();
cout<<"sorted + 0.1% end |"; cout << "sorted + 0.1% end |";
Generator_sorted_end(NMAXSTRING / 1000); Generator_sorted_end (NMAXSTRING / 1000);
cout<<"sorted + 1% end |"; cout << "sorted + 1% end |";
Generator_sorted_end(NMAXSTRING / 100); Generator_sorted_end (NMAXSTRING / 100);
cout<<"sorted + 10% end |"; cout << "sorted + 10% end |";
Generator_sorted_end(NMAXSTRING / 10); Generator_sorted_end (NMAXSTRING / 10);
cout<<empty_line; cout <<empty_line;
cout<<"sorted + 0.1% mid |"; cout << "sorted + 0.1% mid |";
Generator_sorted_middle (NMAXSTRING / 1000); Generator_sorted_middle (NMAXSTRING / 1000);
cout<<"sorted + 1% mid |"; cout << "sorted + 1% mid |";
Generator_sorted_middle (NMAXSTRING / 100); Generator_sorted_middle (NMAXSTRING / 100);
cout<<"sorted + 10% mid |"; cout << "sorted + 10% mid |";
Generator_sorted_middle (NMAXSTRING / 10 ); Generator_sorted_middle (NMAXSTRING / 10 );
cout<<empty_line; cout <<empty_line;
cout<<"reverse sorted |"; cout << "reverse sorted |";
Generator_reverse_sorted(); Generator_reverse_sorted ();
cout<<"rv sorted + 0.1% end|"; cout << "rv sorted + 0.1% end|";
Generator_reverse_sorted_end(NMAXSTRING / 1000); Generator_reverse_sorted_end (NMAXSTRING / 1000);
cout<<"rv sorted + 1% end|"; cout << "rv sorted + 1% end|";
Generator_reverse_sorted_end(NMAXSTRING / 100); Generator_reverse_sorted_end (NMAXSTRING / 100);
cout<<"rv sorted + 10% end|"; cout << "rv sorted + 10% end|";
Generator_reverse_sorted_end(NMAXSTRING / 10); Generator_reverse_sorted_end (NMAXSTRING / 10);
cout<<empty_line; cout <<empty_line;
cout<<"rv sorted + 0.1% mid|"; cout << "rv sorted + 0.1% mid|";
Generator_reverse_sorted_middle(NMAXSTRING / 1000); Generator_reverse_sorted_middle (NMAXSTRING / 1000);
cout<<"rv sorted + 1% mid|"; cout << "rv sorted + 1% mid|";
Generator_reverse_sorted_middle(NMAXSTRING / 100); Generator_reverse_sorted_middle (NMAXSTRING / 100);
cout<<"rv sorted + 10% mid|"; cout << "rv sorted + 10% mid|";
Generator_reverse_sorted_middle(NMAXSTRING / 10); Generator_reverse_sorted_middle (NMAXSTRING / 10);
cout<<"--------------------+------+------+------+------+------+------+\n"; cout << "--------------------+------+------+------+------+------+------+\n";
cout<<endl<<endl ; cout << endl<<endl ;
return 0; return 0;
} }
void Generator_random(void) void Generator_random(void)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
Test<std::string, std::less<std::string>>(A); Test (A);
}; };
void Generator_sorted(void) void Generator_sorted (void)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort( A.begin() , A.end() ); std::sort (A.begin (), A.end ());
Test<std::string, std::less<std::string>>(A); Test (A);
}; };
void Generator_sorted_end(size_t n_last) void Generator_sorted_end (size_t n_last)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING+ n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin() , A.begin() + NMAXSTRING ); std::sort (A.begin (), A.begin () + NMAXSTRING );
Test<std::string, std::less<std::string>>(A); Test (A);
}; };
void Generator_sorted_middle(size_t n_last) void Generator_sorted_middle (size_t n_middle)
{ {
std::vector<std::string> A,B,C; assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
A.reserve(NMAXSTRING); vector <std::string> A, aux;
A.clear(); A.reserve (NMAXSTRING + n_middle);
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) aux.reserve (n_middle);
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [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) std::sort (A.begin () + n_middle, A.end ());
{ C.push_back ( B[i]); //------------------------------------------------------------------------
for ( size_t k = 0 ; k < step ; ++k ) // To insert n_middle elements, must have (n_middle - 1) intervals between
C.push_back ( A[pos + k] ); // them. The size of the interval is step
}; // The elements after the last element of aux don't need to be moved
while ( pos < A.size() ) C.push_back ( A[pos++]); //-------------------------------------------------------------------------
A = C ; size_t step = NMAXSTRING / (n_middle - 1);
A [0] = std::move (aux [0]);
size_t pos_read = n_middle, pos_write = 1;
Test<std::string, std::less<std::string>>(A); for (size_t i = 1; i < n_middle; ++i)
};
void Generator_reverse_sorted(void)
{
std::vector<std::string> A;
A.reserve(NMAXSTRING);
{ {
std::vector<std::string> B; for (size_t k = 0 ; k < step; ++k)
B.reserve(NMAXSTRING); A [pos_write ++] = std::move (A [pos_read ++]);
if (bsc::fill_vector_string("input.bin", B, NMAXSTRING) != 0) A [pos_write ++] = std::move (aux [i]);
};
aux.clear ();
aux.reserve (0);
Test (A);
};
void Generator_reverse_sorted (void)
{
std::vector <std::string> A;
A.reserve (NMAXSTRING);
{
std::vector <std::string> B;
B.reserve (NMAXSTRING);
if (bsc::fill_vector_string ("input.bin", B, NMAXSTRING) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort(B.begin(), B.end()); std::sort (B.begin(), B.end());
A.clear(); A.clear ();
for (size_t i = 0; i < NMAXSTRING; ++i) for (size_t i = 0; i < NMAXSTRING; ++i)
A.push_back(B[NMAXSTRING - 1 - i]); A.push_back (B [NMAXSTRING - 1 - i]);
}; };
Test<std::string, std::less<std::string>>(A); Test (A);
/*
std::vector<std::string> 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::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<std::string, std::less<std::string>>(A);
*/
}; };
void Generator_reverse_sorted_end(size_t n_last) void Generator_reverse_sorted_end (size_t n_last)
{ {
std::vector<std::string> A; std::vector <std::string> A;
A.reserve(NMAXSTRING); A.reserve (NMAXSTRING);
A.clear(); A.clear ();
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING+ n_last) != 0) if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_last) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
std::sort (A.begin() , A.begin() + NMAXSTRING ); std::sort (A.begin (), A.begin () + NMAXSTRING);
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i) for (size_t i = 0; i < (NMAXSTRING >> 1); ++i)
std::swap ( A[i], A[NMAXSTRING - 1 - i]); std::swap (A [i], A [NMAXSTRING - 1 - i]);
Test<std::string, std::less<std::string>>(A);
Test (A);
}; };
void Generator_reverse_sorted_middle(size_t n_last) void Generator_reverse_sorted_middle (size_t n_middle)
{ {
std::vector<std::string> A,B,C; assert (n_middle > 1 && NMAXSTRING >= (n_middle -1));
A.reserve(NMAXSTRING); vector <std::string> A, aux;
A.clear(); A.reserve (NMAXSTRING + n_middle);
if (bsc::fill_vector_string("input.bin", A, NMAXSTRING + n_last) != 0) aux.reserve (n_middle);
if (bsc::fill_vector_string ("input.bin", A, NMAXSTRING + n_middle) != 0)
{ {
std::cout << "Error in the input file\n"; std::cout << "Error in the input file\n";
return; std::exit (EXIT_FAILURE);
}; };
for ( size_t i = NMAXSTRING ; i < A.size() ; ++i) for (size_t i = 0; i < n_middle; ++i) aux.push_back (std::move (A [i]));
B.push_back ( std::move ( A[i]));
A.resize ( NMAXSTRING);
std::sort (A.begin() , A.end() ); std::sort (A.begin () + n_middle, A.end ());
for ( size_t i =0 ; i< (NMAXSTRING >>1); ++i)
std::swap ( A[i], A[NMAXSTRING - 1 - i]); 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;
size_t step = NMAXSTRING /n_last +1 ; for (size_t i = 1; i < n_middle; ++i)
size_t pos = 0 ; {
for (size_t k = 0 ; k < step; ++k)
for ( size_t i =0 ; i < B.size() ; ++i, pos += step) A [pos_write ++] = std::move (A [pos_read ++]);
{ C.push_back ( B[i]); A [pos_write ++] = std::move (aux [i]);
for ( size_t k = 0 ; k < step ; ++k )
C.push_back ( A[pos + k] );
}; };
while ( pos < A.size() ) aux.clear ();
C.push_back ( A[pos++]); aux.reserve (0);
A = C ; Test (A);
Test<std::string, std::less<std::string>>(A);
}; };
int Test (std::vector <std::string> &B)
template<class IA, class compare> {
int Test (std::vector<IA> &B, compare comp) //---------------------------- begin -----------------------------
{ //---------------------------- begin ----------------------------- std::less <std::string> comp;
double duration; double duration;
time_point start, finish; time_point start, finish;
std::vector<IA> A (B); std::vector <std::string> A (B);
std::vector<double> V; std::vector <double> V;
A = B; A = B;
start = now (); start = now ();
@@ -344,11 +335,12 @@ int Test (std::vector<IA> &B, compare comp)
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// printing the vector // printing the vector
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
std::cout<<std::setprecision(2)<<std::fixed; std::cout << std::setprecision (2) << std::fixed;
for ( uint32_t i =0 ; i < V.size() ; ++i) for (uint32_t i = 0; i < V.size () ; ++i)
{ std::cout<<std::right<<std::setw(5)<<V[i]<<" |"; {
std::cout << std::right << std::setw (5) << V [i] << " |";
}; };
std::cout<<std::endl; std::cout <<std::endl;
return 0; return 0;
}; };

View File

@@ -25,7 +25,7 @@ namespace bsc = boost::sort::common;
void print_banner(); void print_banner();
int main(int argc, char *argv[]) int main(int argc, char *argv [])
{ //---------------------------- begin-------------------------------------- { //---------------------------- begin--------------------------------------
std::string name; std::string name;
size_t number; size_t number;
@@ -37,8 +37,8 @@ int main(int argc, char *argv[])
cout << " file_generator file_name number_elements\n\n"; cout << " file_generator file_name number_elements\n\n";
return 0; return 0;
}; };
name = argv[1]; name = argv [1];
number = atoi(argv[2]); number = atoi (argv [2]);
if (number == 0) { if (number == 0) {
cout << "error, the number can't be zero\n"; cout << "error, the number can't be zero\n";
return 0; return 0;

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_numbers clang++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_numbers
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_objects clang++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_objects
echo "." echo "."
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 45 minutes depending of your machine )" echo "( The time needed is around 45 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
clang++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator clang++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
clang++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_strings clang++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_strings
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_numbers g++ ./benchmark_numbers.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_numbers
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_objects g++ ./benchmark_objects.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_objects
echo "." echo "."
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 45 minutes depending of your machine )" echo "( The time needed is around 45 minutes depending of your machine )"

View File

@@ -7,9 +7,9 @@ echo "=================================================================="
echo "." echo "."
echo "C O M P I L I N G . . . . . . . . . . ." echo "C O M P I L I N G . . . . . . . . . . ."
echo "." echo "."
g++ ./file_generator.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o file_generator g++ ./file_generator.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o file_generator
g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fexceptions -O3 -I../../include -s -o benchmark_strings g++ ./benchmark_strings.cpp -std=c++11 -march=native -w -fno-exceptions -fno-operator-names -O3 -I../../include -s -o benchmark_strings
echo "R U N N I N G . . . . . . . . . . ." echo "R U N N I N G . . . . . . . . . . ."
echo "( The time needed is around 10 minutes depending of your machine )" echo "( The time needed is around 10 minutes depending of your machine )"

View File

@@ -102,7 +102,7 @@ void sort_index(Iter_t global_first, std::vector<Iter_t> &index)
while (pos_in_vector < nelem) 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) (size_t(index[pos_in_vector] - global_first)) == pos_in_vector)
{ {
++pos_in_vector; ++pos_in_vector;

View File

@@ -14,7 +14,6 @@
#ifndef __BOOST_SORT_COMMON_MERGE_BLOCK_HPP #ifndef __BOOST_SORT_COMMON_MERGE_BLOCK_HPP
#define __BOOST_SORT_COMMON_MERGE_BLOCK_HPP #define __BOOST_SORT_COMMON_MERGE_BLOCK_HPP
#include <ciso646>
#include <boost/sort/common/range.hpp> #include <boost/sort/common/range.hpp>
#include <boost/sort/common/rearrange.hpp> #include <boost/sort/common/rearrange.hpp>
#include <boost/sort/common/util/merge.hpp> #include <boost/sort/common/util/merge.hpp>
@@ -126,7 +125,7 @@ struct merge_block
~ merge_block() ~ merge_block()
{ {
if (ptr_circ != nullptr and owned) if (ptr_circ != nullptr && owned)
{ {
delete ptr_circ; delete ptr_circ;
ptr_circ = nullptr; ptr_circ = nullptr;
@@ -171,7 +170,7 @@ struct merge_block
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
bool is_tail(size_t pos) const bool is_tail(size_t pos) const
{ {
return (pos == (nblock - 1) and ntail != 0); return (pos == (nblock - 1) && ntail != 0);
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// function : // function :
@@ -223,10 +222,10 @@ template<class Iter_t, class Compare, uint32_t Power2>
void merge_block<Iter_t, Compare, Power2> void merge_block<Iter_t, Compare, Power2>
::merge_range_pos(it_index itx_first, it_index itx_mid,it_index itx_last) ::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); 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 // Create two index with the position of the blocks to merge
@@ -244,17 +243,17 @@ void merge_block<Iter_t, Compare, Power2>
Iter_t itA = global_range.first, itB = global_range.first; Iter_t itA = global_range.first, itB = global_range.first;
bool validA = false, validB = false; 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 // Load valid ranges from the itxA and ItxB positions
//---------------------------------------------------------------- //----------------------------------------------------------------
if (not validA) if (! validA)
{ {
rngA = get_range(*itxA); rngA = get_range(*itxA);
itA = rngA.first; itA = rngA.first;
validA = true; validA = true;
}; };
if (not validB) if (! validB)
{ {
rngB = get_range(*itxB); rngB = get_range(*itxB);
itB = rngB.first; itB = rngB.first;
@@ -266,7 +265,7 @@ void merge_block<Iter_t, Compare, Power2>
//---------------------------------------------------------------- //----------------------------------------------------------------
if (ptr_circ->size() == 0) if (ptr_circ->size() == 0)
{ {
if (not cmp(*rngB.front(), *rngA.back())) if (! cmp(*rngB.front(), *rngA.back()))
{ {
*(itx_out++) = *(itxA++); *(itx_out++) = *(itxA++);
validA = false; validA = false;
@@ -274,7 +273,7 @@ void merge_block<Iter_t, Compare, Power2>
}; };
if (cmp(*rngB.back(), *rngA.front())) if (cmp(*rngB.back(), *rngA.front()))
{ {
if (not is_tail(*itxB)) if (! is_tail(*itxB))
*(itx_out++) = *itxB; *(itx_out++) = *itxB;
else ptr_circ->push_move_back(rngB.first, rngB.size()); else ptr_circ->push_move_back(rngB.first, rngB.size());
++itxB; ++itxB;
@@ -295,7 +294,7 @@ void merge_block<Iter_t, Compare, Power2>
} }
else else
{ // rngB is finished { // rngB is finished
if (not is_tail(*itxB)) if (! is_tail(*itxB))
{ {
ptr_circ->pop_move_front(rngB.first, rngB.size()); ptr_circ->pop_move_front(rngB.first, rngB.size());
*(itx_out++) = *itxB; *(itx_out++) = *itxB;
@@ -315,7 +314,7 @@ void merge_block<Iter_t, Compare, Power2>
else else
{ // The list B is finished { // The list B is finished
rngA = get_range(*itxA); 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 { // add the tail block to indexA, and shift the element
indexA.push_back(indexB.back()); indexA.push_back(indexB.back());
size_t numA = size_t(itA - rngA.first); size_t numA = size_t(itA - rngA.first);
@@ -341,7 +340,7 @@ template<class Iter_t, class Compare, uint32_t Power2>
void merge_block<Iter_t, Compare, Power2> void merge_block<Iter_t, Compare, Power2>
::move_range_pos_backward(it_index itx_first, it_index itx_last, size_t npos) ::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 // Processing the last block. Must be ready fore to accept npos
@@ -391,7 +390,7 @@ void merge_block<Iter_t, Compare, Power2>
pos_ini = 0; pos_ini = 0;
while (pos_ini < nelem) 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; ++pos_ini;
if (pos_ini == nelem) return; if (pos_ini == nelem) return;
pos_dest = pos_src = pos_ini; pos_dest = pos_src = pos_ini;

View File

@@ -13,7 +13,6 @@
#ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP #ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP
#define __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP #define __BOOST_SORT_PARALLEL_DETAIL_UTIL_RANGE_HPP
#include <ciso646>
#include <cassert> #include <cassert>
#include <functional> #include <functional>
#include <memory> #include <memory>
@@ -235,7 +234,7 @@ inline bool is_mergeable_stable(const range<Iter1_t> &src1,
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Code // Code
//------------------------------------------------------------------------ //------------------------------------------------------------------------
return not comp(*(src1.back()), *(src2.front())); return ! comp(*(src1.back()), *(src2.front()));
}; };
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -380,7 +379,7 @@ static void merge_flow(range<Iter1_t> rng1, range<Iter2_t> rbuf,
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
range<Iter2_t> rbx(rbuf); range<Iter2_t> rbx(rbuf);
range<Iter1_t> rx1(rng1), rx2(rng2); range<Iter1_t> 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) while (rx1.first != rx1.last)
{ {
*(rx1.first++) = (cmp(*rbx.first, *rx2.first)) ? *(rx1.first++) = (cmp(*rbx.first, *rx2.first)) ?

View File

@@ -13,7 +13,6 @@
#ifndef __BOOST_SORT_COMMON_REARRANGE_HPP #ifndef __BOOST_SORT_COMMON_REARRANGE_HPP
#define __BOOST_SORT_COMMON_REARRANGE_HPP #define __BOOST_SORT_COMMON_REARRANGE_HPP
#include <ciso646>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
#include <type_traits> #include <type_traits>
@@ -83,7 +82,7 @@ void rearrange(Iter_data global_first, Iter_index itx_first,
pos_ini = 0; pos_ini = 0;
while (pos_ini < nelem) 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; ++pos_ini;
if (pos_ini == nelem) return; if (pos_ini == nelem) return;
pos_dest = pos_src = pos_ini; pos_dest = pos_src = pos_ini;

View File

@@ -13,7 +13,6 @@
#ifndef __BOOST_SORT_COMMON_SORT_BASIC_HPP #ifndef __BOOST_SORT_COMMON_SORT_BASIC_HPP
#define __BOOST_SORT_COMMON_SORT_BASIC_HPP #define __BOOST_SORT_COMMON_SORT_BASIC_HPP
#include <ciso646>
#include <cstdlib> #include <cstdlib>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
@@ -56,7 +55,7 @@ inline Iter_t is_stable_sorted_forward (Iter_t first, Iter_t last,
#endif #endif
if ((last - first) < 2) return first; if ((last - first) < 2) return first;
Iter_t it2 = first + 1; 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; return it2;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -79,7 +78,7 @@ inline Iter_t is_reverse_stable_sorted_forward(Iter_t first, Iter_t last,
#endif #endif
if ((last - first) < 2) return first; if ((last - first) < 2) return first;
Iter_t it2 = first + 1; 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; return it2;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -105,14 +104,14 @@ size_t number_stable_sorted_forward (Iter_t first, Iter_t last,
// sorted elements // sorted elements
Iter_t it2 = first + 1; 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); size_t nsorted = size_t ( it2 - first);
if ( nsorted != 1) if ( nsorted != 1)
return (nsorted >= min_process) ? nsorted: 0; return (nsorted >= min_process) ? nsorted: 0;
// reverse sorted elements // reverse sorted elements
it2 = first + 1; 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); nsorted = size_t ( it2 - first);
if ( nsorted < min_process) return 0 ; if ( nsorted < min_process) return 0 ;
@@ -140,7 +139,7 @@ inline Iter_t is_stable_sorted_backward(Iter_t first, Iter_t last,
#endif #endif
if ((last - first) < 2) return first; if ((last - first) < 2) return first;
Iter_t itaux = last - 1; 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; return itaux;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -163,7 +162,7 @@ inline Iter_t is_reverse_stable_sorted_backward (Iter_t first, Iter_t last,
#endif #endif
if ((last - first) < 2) return first; if ((last - first) < 2) return first;
Iter_t itaux = last - 1; Iter_t itaux = last - 1;
for (; itaux != first and comp(*itaux, *(itaux - 1)); --itaux); for (; itaux != first && comp(*itaux, *(itaux - 1)); --itaux);
return itaux; return itaux;
} }
@@ -188,13 +187,13 @@ size_t number_stable_sorted_backward (Iter_t first, Iter_t last,
#endif #endif
if ((last - first) < 2) return 0; if ((last - first) < 2) return 0;
Iter_t itaux = last - 1; 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); size_t nsorted = size_t ( last - itaux);
if ( nsorted != 1) if ( nsorted != 1)
return ( nsorted >= min_process)?nsorted: 0 ; return ( nsorted >= min_process)?nsorted: 0 ;
itaux = last - 1; 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); nsorted = size_t ( last - itaux);
if ( nsorted < min_process) return 0 ; if ( nsorted < min_process) return 0 ;
util::reverse ( itaux, last ); util::reverse ( itaux, last );
@@ -238,7 +237,7 @@ inline void internal_sort (const range<Iter1_t> &rng1,
range<Iter2_t> rng2_left(rng2.first, rng2.first + nelem), range<Iter2_t> rng2_left(rng2.first, rng2.first + nelem),
rng2_right(rng2.first + nelem, rng2.last); 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_left.first, rng1_left.last, comp);
insert_sort(rng1_right.first, rng1_right.last, comp); insert_sort(rng1_right.first, rng1_right.last, comp);

View File

@@ -13,7 +13,6 @@
#ifndef __BOOST_SORT_COMMON_UTIL_MERGE_HPP #ifndef __BOOST_SORT_COMMON_UTIL_MERGE_HPP
#define __BOOST_SORT_COMMON_UTIL_MERGE_HPP #define __BOOST_SORT_COMMON_UTIL_MERGE_HPP
#include <ciso646>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
@@ -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 (buf1 == end_buf1) return move_forward(buf_out, buf2, end_buf2);
if (buf2 == end_buf2) return move_forward(buf_out, buf1, end_buf1); 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); Iter3_t mid = move_forward(buf_out, buf1, end_buf1);
return move_forward(mid, buf2, end_buf2); 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); 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++)); 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 (first1 == last1) return move_construct(it_out, first2, last2);
if (first2 == last2) return move_construct(it_out, first1, last1); 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); Value_t* mid = move_construct(it_out, first1, last1);
return move_construct(mid, first2, last2); 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); return move_construct(mid, first1, last1);
}; };
}; };
while (first1 != last1 and first2 != last2) while (first1 != last1 && first2 != last2)
{ {
construct_object((it_out++), construct_object((it_out++),
(not comp(*first2, *first1)) ? (! comp(*first2, *first1)) ?
std::move(*(first1++)) : std::move(*(first1++)) :
std::move(*(first2++))); 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 (buf1 == end_buf1) return end_buf2;
if (buf2 == end_buf2) return move_forward(buf_out, buf1, end_buf1); 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); move_forward(buf_out, buf1, end_buf1);
return end_buf2; 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); 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++)); std::move(*(buf1++)) : std::move(*(buf2++));
}; };
return (buf2 == end_buf2)? move_forward(buf_out, buf1, end_buf1) : end_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) if (buf1 == end_buf1)
return here::move_backward(end_buf_out, buf2, end_buf2); 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); here::move_backward(end_buf_out, buf2, end_buf2);
return buf1; 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); 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) = *(--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_buf2)):
std::move(*(--end_buf1)); std::move(*(--end_buf1));
}; };
@@ -352,19 +351,19 @@ static bool merge_uncontiguous(Iter1_t src1, const Iter1_t end_src1,
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Code // Code
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (src1 == end_src1 or src2 == end_src2 if (src1 == end_src1 || src2 == end_src2
or not comp(*src2, *(end_src1 - 1))) return true; || ! comp(*src2, *(end_src1 - 1))) return true;
while (src1 != end_src1 and not comp(*src2, *src1)) while (src1 != end_src1 && ! comp(*src2, *src1))
++src1; ++src1;
Iter3_t const end_aux = aux + (end_src1 - src1); Iter3_t const end_aux = aux + (end_src1 - src1);
Iter2_t src2_first = src2; Iter2_t src2_first = src2;
move_forward(aux, src1, end_src1); 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) if (src2 == end_src2)
@@ -409,11 +408,11 @@ static bool merge_contiguous(Iter1_t src1, Iter1_t src2, Iter1_t end_src2,
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Code // 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; return true;
Iter1_t end_src1 = src2; Iter1_t end_src1 = src2;
while (src1 != end_src1 and not comp(*src2, *src1)) while (src1 != end_src1 && ! comp(*src2, *src1))
++src1; ++src1;
if (src1 == end_src1) return false; 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))); assert ( circ.free_size() >= size_t ((end_buf1-buf1) + (end_buf2-buf2)));
#endif #endif
if (not comp(*buf2, *(end_buf1 - 1))) if (! comp(*buf2, *(end_buf1 - 1)))
{ {
circ.push_move_back(buf1, (end_buf1 - buf1)); circ.push_move_back(buf1, (end_buf1 - buf1));
it1_out = end_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; it2_out = end_buf2;
return false; 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++)) circ.push_back(comp(*buf2, *buf1) ? std::move(*(buf2++))
: std::move(*(buf1++))); : std::move(*(buf1++)));

View File

@@ -13,7 +13,6 @@
#ifndef __BOOST_SORT_FLAT_STABLE_SORT_HPP #ifndef __BOOST_SORT_FLAT_STABLE_SORT_HPP
#define __BOOST_SORT_FLAT_STABLE_SORT_HPP #define __BOOST_SORT_FLAT_STABLE_SORT_HPP
#include <ciso646>
#include <cstdlib> #include <cstdlib>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
@@ -110,9 +109,10 @@ public:
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// //
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// function : // @fn divide
/// @brief : /// @brief Divide a big list of blocks in two parts to be sorted and merged
/// @param Pos : /// @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 /// @return
//------------------------------------------------------------------------ //------------------------------------------------------------------------
template <class Iter_t, typename Compare, uint32_t Power2> template <class Iter_t, typename Compare, uint32_t Power2>
@@ -135,18 +135,17 @@ void flat_stable_sort <Iter_t, Compare, Power2>
}; };
// //
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// function : sort_small // @fn sort_small
/// @brief : /// @brief sort an small number of blocks
/// @param /// @param itx_first iterator to the first element in the index
/// @param /// @param itx_last itarator to to the after the last element in the index
/// @param
//------------------------------------------------------------------------ //------------------------------------------------------------------------
template <class Iter_t, typename Compare, uint32_t Power2> template <class Iter_t, typename Compare, uint32_t Power2>
void flat_stable_sort <Iter_t, Compare, Power2> void flat_stable_sort <Iter_t, Compare, Power2>
::sort_small(it_index itx_first, it_index itx_last) ::sort_small(it_index itx_first, it_index itx_last)
{ {
size_t nblock = size_t(itx_last - itx_first); 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(); value_t *paux = ptr_circ->get_buffer();
range_it rng_data = get_group_range(*itx_first, nblock); range_it rng_data = get_group_range(*itx_first, nblock);
@@ -172,7 +171,7 @@ void flat_stable_sort <Iter_t, Compare, Power2>
}; };
// //
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// function : is_sorted_forward // @fn is_sorted_forward
/// @brief : return if the data are ordered, /// @brief : return if the data are ordered,
/// @param itx_first : iterator to the first block in the index /// @param itx_first : iterator to the first block in the index
/// @param itx_last : iterator to the last block in the index /// @param itx_last : iterator to the last block in the index
@@ -213,7 +212,7 @@ bool flat_stable_sort <Iter_t, Compare, Power2>
}; };
// //
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// function : is_sorted_backward // @fn is_sorted_backward
/// @brief : return if the data are ordered, /// @brief : return if the data are ordered,
/// @param itx_first : iterator to the first block in the index /// @param itx_first : iterator to the first block in the index
/// @param itx_last : iterator to the last 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; 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 /// @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 /// 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 /// @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 /// algorithm depending of the type and size of the data to sort
/// ///

View File

@@ -13,7 +13,6 @@
#ifndef __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP #ifndef __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP
#define __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP #define __BOOST_SORT_INTROSORT_DETAIL_INSERT_SORT_HPP
#include <ciso646>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
#include <algorithm> #include <algorithm>
@@ -51,7 +50,7 @@ static void insert_sort (Iter_t first, Iter_t last,
value_t Aux = std::move (*it_examine); value_t Aux = std::move (*it_examine);
Iter_t it_insertion = 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 = std::move (*(it_insertion - 1));
--it_insertion; --it_insertion;