std.array suggestion
Stewart Gordon
smjg_1998 at yahoo.com
Thu Mar 9 10:30:10 PST 2006
Oskar Linde wrote:
> Stewart Gordon wrote:
>> Oskar Linde wrote:
>> <snip>
>>> T[] doSort(T[], delegate|function wrongOrder(T,T));
>> <snip>
>>
>> You've left off the return type of wrongOrder. Moreover, why the name
>> wrongOrder? To simply return whether or not these two elements are
>> out of order? Why not use what people are used to, i.e. a function
>> that returns -ve, 0 or +ve for <, = or > respectively?
>
> The return value would be anything usable as a condition in a
> conditional function if(wrongOrder(a,b)) {...}
>
> The reason for not having -ve,0,+ve is that you only need a binary
> predicate for sorting.
But depending on the sorting algorithm, I can imagine that either may be
more efficient.
Quite a lot of things at the moment rely on a three-valued ordering.
C: strcmp, memcmp, qsort
Java: compareTo (sic), Comparator
D: opCmp, std.string.cmp
Even if you do have it documented that doSort is unusual, somebody might
either forget this or be already thinking on the three-valued terms when
they see code that uses it.
> It is also in many cases simpler to define a
> ordering predicate than a 3-valued ordering. The name wrongOrder just
> helps as a reminder of what the predicate should return.
<snip>
If that's so, I wonder why so many things have stuck with the
three-valued ordering.
Stewart.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:- C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS-
PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
More information about the Digitalmars-d
mailing list