Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2018-12

Fwd: Re: fpc-devel Digest, Vol 175, Issue 29

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Franz Müller

Hi,

I have finished work on the improved stringlist. There are few changes in the public section:  A new public property OnCompareItems: TStringListSortCompare allows to define the compare function, while keeping sslAuto as sortstyle. If OnCompareItems uses data from the object instead of or in addition to the string itself for sorting, the new public boolean property ObjectSort must be set to true; in that case, the function Indexof will work like for unsorted strings. Finally, the find method can be called with an additional object as parameter, to allow finding of string-object combinations through binary search. I made a few minor improvements, too, so there is no speed penalty for the increased flexibiity.

But before finalizing the patch and submitting it to the bugtracker, I have some questions.

1. It is not allowed to change an element of a sorted stringlist or insert a new string at some specific index. If that happens, SSortedListError is signaled. Shouldn't that also be the case when ExchangeItems is called on a sorted stringlist? I suggest adding the error message there too.

2. Eventually, I can also address the randomization problem by making a non-random choice of the Pivot Element according to

/On Fri, Nov 30, 2018 at 2:29 PM Andrea Mauri ////wrote: /

/if TStringList sort will be changed, please take into account the issue related to randomised pivot initialisation in TStringList sort and the consequences to Random sequence (//http://forum.lazarus-ide.org/index.php?topic=43257.0//). /

/On Fri, Nov 30, 2018 at 2:29 PM Andrea Mauri ////wrote: /

/if TStringList sort will be changed, please take into account the issue related to randomised pivot initialisation in TStringList sort and the consequences to Random sequence (//http://forum.lazarus-ide.org/index.php?topic=43257.0//). /

/https://en.wikipedia.org/wiki/Quicksort#Choice_of_pivot//suggest to either use a random value as pivot or the mean of the first, middle and last element. Bart /

However, I am sceptical whether that would be worth the overhead - whatever the overhead is, because it is absolutely unclear to me what is meant with "the mean of the first, middle and last element". You can caculate the mean for numbers, but not for strings. So I would rather leave these things as they are now.

But maybe there is an easy way to save the state of the random number generator routine before sorting and to restore it when the sort is done?

3. The documentation should be updated. Is there a documentation about how to proceed to update the documentation for a class? There are a lot of different places with descriptions and explanations, I have no idea what to update and how to do that.

4. Are there test cases to validate the new stringlist, to make sure no existing code is broken? I have tested everything I could think of, but there may be constellations that I don't imagine. As stringlists have certainly been thoroughly tested when they were first written, there may already exist some "test suite" to test the behaviour. That would be very helpful and I would be glad to run additional tests before submitting the patch.

Franz

Reply by email

Bart
to Franz Müller
PM Franz Müller wrote
But maybe there is an easy way to save the state of the random number generator routine before sorting and to restore it when the sort is done?

Save RandSeed and restore it after you're done with your calls to Random.

Bart

Reply by email

Ozz Nixon
to Bart

I would assume Mean of First,Middle,Last relative to how Binary Searches Work, Test zero, Test end, Start Middle - some Binary Search Strictly Start Middle and Work to Start or End. So maybe the wording MEAN is wrong - but, I am sure they are pointing how to high speed of Binary Searches. I used them extensively for performance in many of my data oriented objects, TDXStringList for one... before adapting generics, keeping my code more generic in design for other compilers on other platforms - I built my own TDXIntegerList, TDXObjectList, TDXStringList, TDXHashList. Has allowed me to develop extremely fast socket server solutions, pascal interpreters, SQL Server, and soon to be released my first Virtual Bot Wars tournament environment - designed for tens of thousands of concurrent players - writing their own pascal-like attack algorithms to run against other players, in real-time. Part of an AI initiative I have started using binary search abstract tree structure interpreters to run as fast as Google's V8 engine. (sorry for over share - excited about the game project coming to life next year!).

Ozz

AM Bart wrote 12 lines
On Sat, Dec 22, 2018 at 1:03 PM Franz Müller wrote: > But maybe there is an easy way to save the state of the random number generator routine before sorting and to restore it when the sort is done? Save RandSeed and restore it after you're done with your calls to Random. -- Bart _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to Bart: Save RandSeed and restore it after you're done with your calls to Random. Bart

Am Sa., 22. Dez. 2018, 17:38 hat Bart geschrieben:

Show quoted text 7 lines
On Sat, Dec 22, 2018 at 1:03 PM Franz Müller wrote: > But maybe there is an easy way to save the state of the random number generator routine before sorting and to restore it when the sort is done? Save RandSeed and restore it after you're done with your calls to Random

Please note that this is not threadsafe as another thread running the same or even different code could poke around in the RNG's state as well.

Regards,
Sven

Reply by email