Does C++ Algorithm/Boost Lib have Radix Sort?

旧时模样 提交于 2019-12-22 06:31:25

问题


I want to sort integers and I know radix sort is supposed to be awesome for it. Any library implementation for this sort?


回答1:


Depends on how strictly you define radix sort, since Boost 1.58.0 includes Spreadsort, which is a hybrid sorting algorithm that heuristically mixes bucket and comparison sorting.

For sorting integers and with no requirement for worst-case Θ(n) efficiency, Spreadsort should satisfy you.

For argument's sake, you can also take a look at my implementation of LSD radix sort, which is fairly inefficient with memory but occasionally faster than Spreadsort. You only require the radix_sort branch but I've linked to the speed_test branch because it has the readme.




回答2:


The more actual answer is Yes since 1.58 it does:

  • http://www.boost.org/doc/libs/1_58_0/libs/sort/doc/html/index.html

It has something known as SpreadSort and will "magically" detect optimized paths for types like std::string, or floating point numbers that can be treated as byte arrays.



来源:https://stackoverflow.com/questions/21251061/does-c-algorithm-boost-lib-have-radix-sort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!