www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - topNIndex

reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
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?

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?

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)

4) Should we keep it, or should we chuck it?


T

-- 
This is not a sentence.
Jan 22 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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. Andrei
Jan 22 2015
parent reply "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
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
Jan 22 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 1/22/15 1:09 PM, H. S. Teoh via Digitalmars-d wrote:
 Do we really want to publicly document this function before we clean it
 up?
Most likely not. If you have the time, please take it to completion; otherwise leave it deleted. -- Andrei
Jan 22 2015
parent "H. S. Teoh via Digitalmars-d" <digitalmars-d puremagic.com> writes:
On Thu, Jan 22, 2015 at 01:24:55PM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
 On 1/22/15 1:09 PM, H. S. Teoh via Digitalmars-d wrote:
Do we really want to publicly document this function before we clean
it up?
Most likely not. If you have the time, please take it to completion; otherwise leave it deleted. -- Andrei
https://github.com/D-Programming-Language/phobos/pull/2898 I decided not to attempt implementing SwapStrategy, but at least document the current limitations. I think in spite of its limitations topNIndex is probably still useful in its present form. T -- The early bird gets the worm. Moral: ewww...
Jan 22 2015