Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Micha Nelissen
Bart van den Broek wrote: Why not add an overloaded CustomSort method that accepts the compare function that you like. Has the code duplication, maintenance, bloat, etc. problem. Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Michael Van Canneyt
On Mon, 6 Nov 2006, Micha Nelissen wrote: Hi, Does anyone use the CustomSort facility of TStringList ? I am a bit troubled because it's broken by design it seems. You can sort the list with it, but searching/adding will not work properly (or be linear). I want to have a callback that

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Micha Nelissen
Michael Van Canneyt wrote: Ehm. What has adding/searching to do with sorting ? Adding: keep the list sorted. Searching: ability to use binary search instead of linear. Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Michael Van Canneyt
On Tue, 7 Nov 2006, Micha Nelissen wrote: Michael Van Canneyt wrote: Ehm. What has adding/searching to do with sorting ? Adding: keep the list sorted. Use Sorted:=True. Searching: ability to use binary search instead of linear. It is used if Sorted=True. But not with customsearch.

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Chris Cheney
Does anyone use the CustomSort facility of TStringList ? I am a bit troubled because it's broken by design it seems. You can sort the list with it, but searching/adding will not work properly (or be linear). I want to have a callback that gives you two strings to compare, instead of two

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Micha Nelissen
Michael Van Canneyt wrote: The purpose of Customsearch is to sort the list once using a custom sorting algorithm. That reduces its usefulness, and why I said it's a broken design :). Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Michael Van Canneyt
On Tue, 7 Nov 2006, Micha Nelissen wrote: Michael Van Canneyt wrote: The purpose of Customsearch is to sort the list once using a custom sorting algorithm. That reduces its usefulness, and why I said it's a broken design :). Maybe, but it's implemented to be delphi compatible. What

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Micha Nelissen
Chris Cheney wrote: Stating the obvious: but the programmer might wish to sort by the objects or by some combination of the strings and the objects (or even by entries in an external array, unrelated to the StringList) - the indexes are therefore needed in the general case. Oh right, sorting

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Vinzent Hoefler
On Tuesday 07 November 2006 09:17, Micha Nelissen wrote: Chris Cheney wrote: Of course, the efficient way to build a sorted list is to set Sorted to False and to sort the list after all the items have been added. It doesn't matter in O-time: both are O(n log n). Nevertheless, you

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Mattias Gaertner
On Tue, 07 Nov 2006 10:17:24 +0100 Micha Nelissen [EMAIL PROTECTED] wrote: Chris Cheney wrote: Stating the obvious: but the programmer might wish to sort by the objects or by some combination of the strings and the objects (or even by entries in an external array, unrelated to the

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Micha Nelissen
Vinzent Hoefler wrote: It doesn't matter in O-time: both are O(n log n). Nevertheless, you probably will save some function call overhead. That highly depends on the sorting algorithm used. A plain Quicksort has a very bad worst case of O(n**2) that develops especially when the list to be

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Marco van de Voort
Does anyone use the CustomSort facility of TStringList ? It's delphi compat. I am a bit troubled because it's broken by design it seems. You can sort the list with it, but searching/adding will not work properly (or be linear). Why would you want to add/search while sorting?

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Micha Nelissen
Marco van de Voort wrote: I am a bit troubled because it's broken by design it seems. You can sort the list with it, but searching/adding will not work properly (or be linear). Why would you want to add/search while sorting? After sorting, to search efficiently, why else ? Micha

Re: [fpc-devel] TStringList.CustomSort

2006-11-07 Thread Marco van de Voort
Michael Van Canneyt wrote: The purpose of Customsearch is to sort the list once using a custom sorting algorithm. That reduces its usefulness, and why I said it's a broken design :). Well, it fits with the rest of TStringList then :-) Seriously, I wouldn't bother using TStringList. It's

[fpc-devel] TStringList.CustomSort

2006-11-06 Thread Micha Nelissen
Hi, Does anyone use the CustomSort facility of TStringList ? I am a bit troubled because it's broken by design it seems. You can sort the list with it, but searching/adding will not work properly (or be linear). I want to have a callback that gives you two strings to compare, instead of two