topNIndex

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Thu Jan 22 13:09:00 PST 2015


On Thu, Jan 22, 2015 at 12:42:09PM -0800, Andrei Alexandrescu via Digitalmars-d wrote:
> On 1/22/15 11:50 AM, H. S. Teoh via Digitalmars-d wrote:
> >There's an undocumented function (2 overloads) called topNIndex
> >that's still sitting in std.algorithm.package, 'cos I have no idea
> >what it does and where it belongs.
> >
> >1) Do we still want this function?
> 
> Yes.
> 
> >2) There's a bunch of dead code that has been commented out since
> >2009, including a function named topNIndexImpl. Does that mean that
> >topNIndex is also dead code?
> 
> topNIndex is supposed to be public.
> 
> >3) What is this function supposed to do? (OK OK, I can just read the
> >code, but I figured it's faster to ask here. :-P)
> 
> void topNIndex(
>     alias less = "a < b",
>     SwapStrategy ss = SwapStrategy.unstable,
>     Range, RangeIndex)(Range r, RangeIndex index, SortOutput sorted =
> SortOutput.no)
> if (isIntegral!(ElementType!(RangeIndex)));
> 
> It stores the indices of the top `index.length` elements of `r` in `index`,
> without modifying `r`.
> 
> >4) Should we keep it, or should we chuck it?
> 
> Keep.
[...]

Hmm. I'm looking over the code, and it appears that the implementation
is incomplete. The compile-time parameter SwapStrategy is never used in
the function bodies, for example, and the signature constraints fail to
verify range operations freely employed (like opIndex, etc).

Do we really want to publicly document this function before we clean it
up?


T

-- 
Claiming that your operating system is the best in the world because more people use it is like saying McDonalds makes the best food in the world. -- Carl B. Constantine


More information about the Digitalmars-d mailing list