Uwe Raabe 2057 Posted December 9, 2022 15 minutes ago, Vandrovnik said: Has someone created it on QP, so that we can vote? Currently I cannot find one. Seems like @dummzeuch is the right person. If he refuses I will be happy to step in. The reference to the TStringList.Find implementation should definitely be mentioned. I also suggest a separate QP entry for updating the documentation. Share this post Link to post
Stefan Glienke 2002 Posted December 9, 2022 (edited) 13 hours ago, Anders Melander said: It's fine that there are corner cases that performs worse than optimal, like with quick sort Which has been a solved problem for quite some - it's called IntroSort - no language I know uses plain QuickSort as their default standard library sort these days. If not IntroSort they might use TimSort. Edited December 9, 2022 by Stefan Glienke 1 Share this post Link to post
David Heffernan 2345 Posted December 9, 2022 37 minutes ago, Uwe Raabe said: It is just my personal opinion that if everybody is going to avoid the standard routines in favor of writing its own, we may never see any improvement in that area. I don't think that's right. You suggest we should just use broken code because that's likely to persuade Emba to change it? I want the program that I ship to be good. Share this post Link to post
Uwe Raabe 2057 Posted December 9, 2022 57 minutes ago, David Heffernan said: You suggest we should just use broken code Neither did I say so, nor is the code broken. It may have a bad performance in some cases, but if I can rule out these cases, why should I dismiss that code? Share this post Link to post
David Heffernan 2345 Posted December 9, 2022 44 minutes ago, Uwe Raabe said: Neither did I say so, nor is the code broken. It may have a bad performance in some cases, but if I can rule out these cases, why should I dismiss that code? It's broken in my view because binary search should be O(log n). And this code isn't. It isn't binary search. It's a hybrid binary and linear search. Obviously people can do what they want. I won't be using this code though. Share this post Link to post
Uwe Raabe 2057 Posted December 9, 2022 Here is the QP entry: https://quality.embarcadero.com/browse/RSP-40174 3 2 Share this post Link to post
Attila Kovacs 629 Posted December 9, 2022 Why did they change it in the first place? Share this post Link to post
Uwe Raabe 2057 Posted December 9, 2022 Because it didn't return the first matching element but an arbitrary one. I was pretty sure someone requested it, but I cannot find any QP entry for that. It is also possible that it was initiated internally. Share this post Link to post
Attila Kovacs 629 Posted December 9, 2022 (edited) 20 minutes ago, Uwe Raabe said: Because it didn't return the first matching element but an arbitrary one. I'm not sure on that. Look the code in Berlin, it's searching from the left and returning the first matching element. Edit: oh no, I see. Edit edit, well, no-oh no, can't see again. 😄 If the list is sorted I can't create a list where binsearch would not return the first element in the list. Berlin U2. Edited December 9, 2022 by Attila Kovacs Share this post Link to post
Uwe Raabe 2057 Posted December 9, 2022 Seems you are right. The implementation up to 10.4 looks like it is already satisfying the requirement. In that case the change made in 11 may as well be reverted. I will ask for the reason of that change. Share this post Link to post
Uwe Raabe 2057 Posted December 10, 2022 On 12/8/2022 at 11:08 AM, dummzeuch said: OK, so it depends on the Delphi version. As we now found out: it doesn't. While the implementation changed in Delphi 11 it always made a lower bound binary search even in Delphi versions below 11. Share this post Link to post
dummzeuch 1505 Posted December 10, 2022 (edited) 1 hour ago, Uwe Raabe said: As we now found out: it doesn't. While the implementation changed in Delphi 11 it always made a lower bound binary search even in Delphi versions below 11. OK, so there are two bugs: the documentation is (and has always been) wrong. the implementation in Delphi 11 was "verschlimmbessert" (made worse by trying to improve it). The function BinarySearch should have been called differently (yes, off by one) Goes to show that I should simply have done what I did while the quality of the docs was even worse than it is today: Look at the sources. Edited December 10, 2022 by dummzeuch 2 Share this post Link to post
Tommi Prami 130 Posted December 12, 2022 On 12/9/2022 at 4:42 PM, Uwe Raabe said: Here is the QP entry: https://quality.embarcadero.com/browse/RSP-40174 Voted... Share this post Link to post