Recent

Author Topic: TStrings.IndexOfName / TStringList  (Read 14833 times)

marcodor

  • New Member
  • *
  • Posts: 17
Re: TStrings.IndexOfName / TStringList
« Reply #15 on: July 05, 2015, 09:17:11 pm »
JuhaManninen, thanks for THashedStringList  hint, just checked implementation, will go with this class.

Marcov, it should not break any Delphi compatibility, if function runs faster it's about optimization, not compatibility. So less arrogance please.

Jc99, thanks for code. Anyway, instead having this already in THashedStringList it can also be improved in TStringList.

If items are sorted, why not use it? Just 5 lines of code optimizations.

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: TStrings.IndexOfName / TStringList
« Reply #16 on: July 05, 2015, 10:36:05 pm »
[...]
Jc99, thanks for code. Anyway, instead having this already in THashedStringList it can also be improved in TStringList.

If items are sorted, why not use it? Just 5 lines of code optimizations.
+1
and hey You did it in 5 lines ? Cool, please share.

BTW, TStringList.find always does a binary search even in an unsorted list. Is this really supposed to be that way ?
[Edit]
Could someone verify this ?
--> [...] <---
Plz have a look at this.
you put three strings in a stringlist and find does not find the last one (somtimes, when unsorted)
« Last Edit: July 06, 2015, 01:26:48 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStrings.IndexOfName / TStringList
« Reply #17 on: July 05, 2015, 11:40:54 pm »
I admit the class name is misleading. I realized it only afterwards. If somebody comes up with a better name, we can still change it.

TMappedStringList.

howardpc

  • Hero Member
  • *****
  • Posts: 3646
Re: TStrings.IndexOfName / TStringList
« Reply #18 on: July 05, 2015, 11:48:30 pm »
TUnsortedLookupStringList

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: TStrings.IndexOfName / TStringList
« Reply #19 on: July 06, 2015, 12:13:40 am »
@JuhaManninen:
Since you say in the wiki:
It's a
Quote
[...] TStringList with a fast lookup feature.
TFastLookupStringList


OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStrings.IndexOfName / TStringList
« Reply #20 on: July 06, 2015, 12:25:59 am »
jc99, you could take a look at TStringToStringTree.

TDictionaryStringList is the best solution possible to deduplicate an unsorted list of strings. But I think you could use TStringToStringTree directly instead of using a TStringList for IndexOfName.

If you want to know the index in order to get the value, with a map you get the value directly and the index does not matter.
« Last Edit: July 06, 2015, 01:09:11 am by typo »

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: TStrings.IndexOfName / TStringList
« Reply #21 on: July 06, 2015, 01:09:35 am »
jc99, you could take a look at TStringToStringTree.
Yes:
http://wiki.lazarus.freepascal.org/AVL_Tree
But what's your point ?

An AVL-Tree is an automatic balanced binary tree. I learned about/implemented these in the early 90's.   
« Last Edit: July 06, 2015, 01:21:35 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: TStrings.IndexOfName / TStringList
« Reply #22 on: July 06, 2015, 01:52:20 am »
TDictionaryStringList is the best solution possible to deduplicate an unsorted list of strings. But I think you could use TStringToStringTree directly instead of using a TStringList for IndexOfName.

If you want to know the index in order to get the value, with a map you get the value directly and the index does not matter.
That depends how the map(ping) is implemented. If it is an AVL-Tree, than you get to the Data-node in O(log(n)) that's exactly the same as a binary search through a sorted list.
The sorting of the list is normaly done in O(n log (n)). But building the Tree also takes O(n log(n)).

Much worse is that Valuelist-editor uses TStringlist -> TStrings linear search to get to the value. That's quite a showstopper, if you use larger lists.
With the new code you only have to sort the list, and then you can access the values nearly optimal. Without changing the code of the VLE-component.
   
And the thing with the Index is only because TStrings is implemented that way.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3977
  • I like bugs.
Re: TStrings.IndexOfName / TStringList
« Reply #23 on: July 07, 2015, 02:22:59 pm »
I finally renamed TDictionaryStringList  -> TLookupStringList.
Thanks for the suggestions. Typo's TMappedStringList was good except that it raised a question "mapped to what?" at least in my head. The others were too long IMO.
Typo, if you know people who use the class, you can advertise the name change.

Patches for ValueListEditor are welcome. It belongs to a different project than TStringList, Bart or myself can commit changes for it.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStrings.IndexOfName / TStringList
« Reply #24 on: July 07, 2015, 04:54:04 pm »
Thanks.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStrings.IndexOfName / TStringList
« Reply #25 on: July 07, 2015, 09:13:59 pm »
Patches for ValueListEditor are welcome. It belongs to a different project than TStringList, Bart or myself can commit changes for it.

Where is the source?

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: TStrings.IndexOfName / TStringList
« Reply #26 on: July 07, 2015, 10:17:37 pm »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStrings.IndexOfName / TStringList
« Reply #27 on: July 07, 2015, 10:44:29 pm »
What is the problem?

jc99

  • Hero Member
  • *****
  • Posts: 544
    • My private Site
Re: TStrings.IndexOfName / TStringList
« Reply #28 on: July 07, 2015, 11:08:03 pm »
What is the problem?
Exactly !?
What do you mean by where is the source ?
In the trunk ?! In the repository ?! ???
So I was a little bit puzzled.

--------
Dude, what's on my back ? - Sweet, what's on my back ? - DUDE, what's on my back ? - SWEET ......
 
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: TStrings.IndexOfName / TStringList
« Reply #29 on: July 07, 2015, 11:09:06 pm »
The question was not addressed to you. Take care of your life.

 

TinyPortal © 2005-2018