[fpc-pascal] TSortedCollection dupes ordering

Frederic Da Vitoria davitofrg at gmail.com
Wed Feb 5 09:57:04 CET 2014


2014-02-05 waldo kitty <wkitty42 at windstream.net>:

> On 2/4/2014 5:16 PM, Frederic Da Vitoria wrote:
>
>> 2014-02-04 waldo kitty <wkitty42 at windstream.net <mailto:
>> wkitty42 at windstream.net>>:
>>
> [...]
>
>      i kinda thought about that earlier when i was digging thru the
>> code... IIRC,
>>     insert was overridden because there are cases where the existing
>> record
>>     needs to be replaced (because the new record is newer) using AtPut
>> and the
>>     non-added records must be logged and their reason for not being added
>> (older
>>     or same)...
>>
>>
>> Just a quick idea which could be completely wrong, but wouldn't it solve
>> your
>> issue if Compare always returned -1 instead of 0?
>>
>
> no, because i lose (at least) the logging of why the record was tossed
> out... see below...


Hm, yes, you don't always want to keep duplicates.


> it wouldn't help with the duplicate keys being inserted in reverse order...
>

Once again I did not test this, but it seems to me that if Compare returned
-1 instead of 0, any duplicate would be inserted after because it would
never be considered as equal to any other. But since you still want your
collection to be able to choose between skipping duplicates or keeping
them, the Compare modification would have to be slightly more subtle,
something like:

if result = 0 and Duplicates
    then result := -1

at the end of the Compare function.

-- 
Frederic Da Vitoria
(davitof)

Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140205/05178e6c/attachment.html>


More information about the fpc-pascal mailing list