----- Original Message -----
From: Ross Levis <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Sent: Wednesday, August 01, 2001 11:41 PM
Subject: [DUG]: Sets of Strings?
> A beginners Pascal question here:
>
> Is there a better way of doing this?
> If (Extension='.wav' or Extension='.mp3' or Extension='.ogg') then ...
>
> Is there something similar to a Set I can use that would let me write
> something like this?
> If Extension in AudioFiles then ...
>
> I tried Pos(Extension,AudioFiles)>0 but an extension of '.w' would also
> be true.
You can do something like this with a TStringList using the IndexOf method.
> Another question. Is it quicker to add many items to a TStringList
> unsorted and then Sort it; or set Sorted True & sort each item as it is
> added? Or is there no difference?
Sorting after you add is MUCH faster, for a couple of reasons. One is that
when 'Sorted' is true the Add methods of TStringList first check to see if
the string already exists using the Find method, which also returns the
correct position if the string doesn't already exist. The second is that
when you insert a value near the front of the list it has to move all the
others to make room, which is much slower than using Sort once on the list
once you've added everything to it.
I did a quick speed test on it, adding 10000 numeric values (in reverse
order) to sorted and unsorted lists, then sorting the unsorted one.
Results:
Unsorted:
Add 0.382s
Sort 0.970s
Total 1.352s
Sorted:
Total 119.320s
This is a worst-case scenario for the sorted list of course, so I tried it
in ascending order (best case) and got a total time of 2463ms. Much better,
but still way slower than adding to the unsorted list.
--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur."
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/