I use boost::sort() from boost/range/algorithm.hpp but is really... slow and I'm just working with unsigned integer type, so I thought "Maybe using integer_sort() from boost/sort/spreadsort/integer_sort.hpp I can improve the speed" The Question is that std::sort(v.begin(), v.end()) run in ~54 seconds and boost:sort(v) in ~54 seconds (Same time)
But I Write something like radix sort, and takes ~28 seconds, but I think that integer_sort can be more optimized that my code, but I don't know how use integer_sort.
#include <vector>
#include <boost/range/algorithm.hpp>
#include <boost/sort/spreadsort/integer_sort.hpp> // I WANT USE THIS
#include "myLib.hpp"
using namespace std;
int main(void)
{
vector <unsigned> v(20);
for (unsigned i = 0; i < v.size(); i++)
v[i] = rand() % 1000;
imprime(v); // THIS PRINTS THE VECTOR
boost::sort(v); // THIS SORT THE VECTOR
imprime(v);
integer_sort(v.begin(), v.end()); // THIS DOES'T WORK
return 0;
}
If I try with integer_sort(v.begin(), v.end()); I get
sort.cpp: In function ‘int main()’:
sort.cpp:23:34: error: ‘integer_sort’ was not declared in this scope
integer_sort(v.begin(), v.end());
^
sort.cpp:23:34: note: suggested alternatives:
In file included from sort.cpp:5:0:
/usr/include/boost/sort/spreadsort/integer_sort.hpp:173:15: note: ‘boost::sort::spreadsort::integer_sort’
inline void integer_sort(RandomAccessIter first, RandomAccessIter last,
^~~~~~~~~~~~
In file included from /usr/include/boost/sort/spreadsort/integer_sort.hpp:26:0,
from sort.cpp:5:
/usr/include/boost/sort/spreadsort/detail/integer_sort.hpp:482:5: note: ‘boost::sort::spreadsort::detail::integer_sort’
integer_sort(RandomAccessIter first, RandomAccessIter last, Div_type,
^~~~~~~~~~~~
I know that this has something to do with the (v.begin(), v.end()) RandomAccessIter first
<- I get something similar when I try std::sort(v)
<- this is not correct. But I don't understand the error message. Don't say candidate expects 3 arguments, 1 provided
like in std::sort.
So How use integer_sort()?
Boost Doc Says:
Each of integer_sort, float_sort, and string_sort have 3 main versions: The base version, which takes a first iterator and a last iterator, just like std::sort:
integer_sort(array.begin(), array.end());
float_sort(array.begin(), array.end());
string_sort(array.begin(), array.end());
Aucun commentaire:
Enregistrer un commentaire