[DUG]Sorting Stringlist
Paul Heinz
paul at accredo.co.nz
Thu Aug 18 17:58:18 NZST 2005
John asked:
> As I understand it, loadfromfile method uses add, which takes note of
> whether list is to be sorted or not...
> Hence case 1 just adds each new line to the end of the stringlist, case 2
> adds each record to the correct sorted order place. My guess is 1 is
> faster, but I am guessing.
>
> Number of records in file may be anywhere from 10 to 100,000
With most datastructures, it's generally faster to bulk load unsorted and
then sort once. This applies to DB engines and I would imagine StringLists.
It's because updating a sorted structure is O(n log n) for each addition,
whereas sort is O(n log n) once.
Regards,
Paul.
More information about the Delphi
mailing list