我使用boost / range / algorithm.hpp中的boost :: sort(),但实际上......很慢,我只是使用无符号整数类型,所以我想"也许使用integer_sort( )来自boost / sort / spreadort / integer_sort.hpp我可以提高速度" 问题是std :: sort(v.begin(),v.end())在~54秒内运行并且提升:sort(v)在~54秒内(同一时间)
但我写了类似基数排序的东西,需要大约28秒,但我认为integer_sort可以比我的代码更优化,但我不知道如何使用integer_sort。
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,
^~~~~~~~~~~~
如果我尝试使用integer_sort(v.begin(),v.end());我得到了
RandomAccessIter first
我知道这与(v.begin(),v.end())std::sort(v)
<有关 - 当我尝试candidate expects 3 arguments, 1 provided
< - 这时我会得到类似的东西是不正确的。但我不理解错误信息。
不要在std :: sort中说integer_sort(array.begin(), array.end());
float_sort(array.begin(), array.end());
string_sort(array.begin(), array.end());
。
那么如何使用integer_sort()?
integer_sort,float_sort和string_sort中的每一个都有3个主要版本:基本版本,它采用第一个迭代器和最后一个迭代器,就像std :: sort:
fun()
答案 0 :(得分:1)
您在调用integer_sort
时缺少名称空间资格。
integer_sort
位于boost::sort::spreadsort
命名空间中(请参阅the documentation)。所以你的电话应该是这样的:
boost::sort::spreadsort::integer_sort(v.begin(), v.end());
另请注意,如果您尝试在同一程序中使用boost::sort
和Boost.Sort
库,则会遇到问题,因为boost::sort
功能模板与Boost.Sort
冲突命名空间(见the bug report)。
boost::sort
只是std::sort
的包装器,所以预计两者的性能会相同。
boost::sort::spreadsort::integer_sort
以下), std::sort
将使用boost::sort::spreadsort::detail::min_sort_size
,因此对于较小的数据大小,预计它们的性能几乎相同(最高为integer_sort
检查是否使用std::sort
的额外费用。