[R-pkg-devel] R_orderVector1 - algo: radix, shell, or another?

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Mon Sep 25 09:26:16 CEST 2023


В Sun, 24 Sep 2023 10:38:41 +0200
Jan Gorecki <j.gorecki using wit.edu.pl> пишет:

> https://github.com/wch/r-source/blob/ed51d34ec195b89462a8531b9ef30b7b72e47204/src/main/sort.c#L1133

> could anyone describe which one R_orderVector1 uses,

The body of the sorting algorithm is defined in the sort2_with_index
macro. This is shell sort. (I don't actually recognise sorting
algorithms on sight, but the "sincs" array gave it away:
<https://discourse.julialang.org/t/ironic-observation-about-sort-and-sortperm-speed-for-small-integers-vs-r/8715/3>.)

> and if there is easy API to use different ones from C?

No easy ones, I think. You could construct a call to order(..., method
= 'radix') from R or bundle a sort implementation of your own.

These are all undocumented implementation details. They could change in
a new version of R (although quite a lot of it hasn't changed in 11-22
years). Why are you looking for specific sorting algorithms? Could
there be a better way to solve your problem?

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list