[libcxx-commits] [PATCH] D141205: [libcxx] nth_element use introselect to avoid quadratic behavior

Danila Kutenin via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jan 8 09:04:04 PST 2023


danlark added inline comments.


================
Comment at: libcxx/include/__algorithm/nth_element.h:104
+        {
+            // fall back to heap select.
+            std::__heap_select<_AlgPolicy, _Compare>(__first, __nth, __last, __comp);
----------------
Mordante wrote:
> Can you add comment why this is done? Currently the comment and the code tell the same thing.
> For maintainability it would be very good to know why we switch the algorithm.
Even though I am in favor of this patch, this does not fully fix the issue. With the comparator that changes the inputs on the fly, it's possible to get into a O(n log n) average case.

Otherwise LGTM, thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141205/new/

https://reviews.llvm.org/D141205



More information about the libcxx-commits mailing list