FGL.TFPSList Find method needed (binary search)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

FGL.TFPSList Find method needed (binary search)

AlexeyT
Hello. Can you pls, add Sorted property to TFPSList / TFPGList (Add()
method must sort newly added item), and also Find method (which must use
binary search in Sorted case, and use plain loop if not sorted)?

--
Regards,
Alexey

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FGL.TFPSList Find method needed (binary search)

Free Pascal - General mailing list
Am Sa., 16. Feb. 2019, 21:30 hat AlexeyT <[hidden email]> geschrieben:
Hello. Can you pls, add Sorted property to TFPSList / TFPGList (Add()
method must sort newly added item), and also Find method (which must use
binary search in Sorted case, and use plain loop if not sorted)

You could also check whether rtl-generics already provides what you need. 

Just in case anyone wants to add this (I won't): this also requires properties for a comparer and a compare algorithm (essentially the arguments to Sort) as TFPGList<> should not require the presence of a comparison operator in the generic parameter type. 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: FGL.TFPSList Find method needed (binary search)

Michael Van Canneyt
In reply to this post by AlexeyT


On Sat, 16 Feb 2019, AlexeyT wrote:

> Hello. Can you pls, add Sorted property to TFPSList / TFPGList (Add()
> method must sort newly added item), and also Find method (which must use
> binary search in Sorted case, and use plain loop if not sorted)?

You can use the rtl-generics generics.collections.pas if you want sorting
and binary search.

It makes no sense to re-implement all what is there in fgl.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal