The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,091 other followers

Archive for December 26th, 2019

Delphi: Why is there no class procedure TArray.Sort(Keys: array of T; var Values: array of T; const Comparer: IComparer);

Posted by jpluimers on 2019/12/26

The underlying question at [WayBack] … Does anyone know of any array sort method similar to this for Delphi (with the two array parameters, key and value with a comparer method) … – Ugochukwu Mmaduekwe – Google+ was basically this:

Why is there no
class procedure TArray<T>.Sort(Keys: array of T; var Values: array of T; const Comparer: IComparer<T>); overload;

From my answer:

No it is not there as the method that does the actual sort does not accommodate for it:

class procedure TArray.QuickSort<T>(var Values: array of T; const Comparer: IComparer<T>; L, R: Integer);

You could write a helper for it so that similarly to C#, they all end in public static void Sort(Array keys, Array items, int index, int length, IComparer comparer)

In case you need to look at the external TrySZSort: https://github.com/dotnet/coreclr/blob/master/src/classlibnative/bcltype/arrayhelpers.cpp#L268

In other cases, C# uses an IntrospectionSort implemented at

Or you could try to use this overload of TArray.Sort Method (array of T):

class procedure Sort<T>(var Values: array of T; const Comparer: IComparer<T>); overload;

It was introduced in Delphi 2009.

Your Comparer then needs to extract the key of each element and implement IComparer<T>.

However, this will never sort the Keys array.

–jeroen

Posted in Delphi, Development, Software Development | Leave a Comment »

Sasha Laundy on Twitter: “The best debugger ever made is a good night’s sleep.”

Posted by jpluimers on 2019/12/26

Very similar to “you get the best ideas while sleeping“:

[WayBack/Archive.isSasha Laundy on Twitter: “The best debugger ever made is a good night’s sleep.”

Via: [WayBack] So true it hurts – CodeProject – Google+

For me, taking a shower and contemplating during a commute are good debuggers too. But sleeping is still the best.

Hope you enjoyed Christmas, good luck on your debugging ventures!

–jeroen

Posted in Debugging, Development, Fun, Quotes, Software Development | Leave a Comment »

 
%d bloggers like this: