Forum > General

TStrings.IndexOfName / TStringList

(1/6) > >>

marcodor:
I think speed of IndexOfName function can be greatly improved in TStringList descendant if list is sorted.
Instead doing a natural scan of all items we may go with a quick find in a sorted list.

jc99:

--- Quote from: marcodor on July 04, 2015, 01:37:35 pm ---I think speed of IndexOfName function can be greatly improved in TStringList descendant if list is sorted.
Instead doing a natural scan of all items we may go with a quick find in a sorted list.

--- End quote ---
I think for this you could use other descendents of TStrings.
Like ... ? (I think there was something like TSortedList or TBucketlist but I could'nt find any of these in the Wiki )
But I remember a Demo, comparing these three (Maybe it's something tied to Delphi)
But each of this has it Up's and Down's (mem-usage, speed of specific activity e.G: inserting, rearranging, generating, reading, ...  )

The TStringList itself should be left alone.
e.G: if you want to load some source-code into TStringlist, it's definitly NOT a good Idea to have this sorted.
but using 'IndexOfName' is normaly no good option either on that.

typo:
If you need fast lookup without the need of a sorted list, have a look at TDictionaryStringList and see if it helps.

http://wiki.lazarus.freepascal.org/LazUtils#TDictionaryStringList

marcodor:
JC99, Why TStringList.IndexOf perform a binary search while IndexOfName not?

I asked this, because TStrings.Values[ internally uses IndexOfName.
Reading a large config section with TIniFile.ReadSectionValues( and after that sorting it will speedup later access of Strings.Values['option']

I really see no problems implementing indexed search for IndexOfName in TStringList especially most code is already done for IndexOf.
Also I suppose IndexOfName is used in many parts/projects (maybe Lazarus itself), so it should improve things.

jc99:
Maybe someone could help me out, but if i remember correctly TStringList does NOT do a binary-search what it does, it goes through a hash-list which is nearly as effective (maybe even more) as a binary search. But this can only be done with a full string. So you need to use a class that does (also) a hashing of the KeyNames.
And as typo suggested TDictionaryStringList might help you in this.

Navigation

[0] Message Index

[#] Next page

Go to full version