Bill Allombert on Wed, 21 Feb 2018 11:51:28 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: vecsort() and sign()


On Tue, Feb 20, 2018 at 10:18:41PM +0100, Karim Belabas wrote:
> Nice idea. But the documentation gives an example which explains
> why a naive implementation of this is a bad idea (n log(n) calls to cmpf
> instead of n).
> 
> In this case, it is better to do something like
> 
>   T = [cmpf(x) | x<-v];
>   perm = vecsort(T,,1); \\ indirect sort
>   vecextract(v, perm)
> 
> We can do that internally, of course !

internally, vecsort actually always use an indirect sort anyway.

> I have a quick & dirty
> implementation for this.
> 
> Unfortunately, the idea breaks down with vecsearch(), which is a most
> important application of vecsort() [ for repeated searches in a sorted vector ]:

Well, nowadays we should recommends using Map in most case.

Cheers,
Bill.