aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h
diff options
context:
space:
mode:
authormikhnenko <mikhnenko@yandex-team.com>2023-09-27 19:43:57 +0300
committermikhnenko <mikhnenko@yandex-team.com>2023-09-27 20:05:15 +0300
commit48a18a64bb612e73011e1c49aef96b8dad6bffba (patch)
tree88f71d26ed4c98edd9b389e3c5f1f674f34942ac /contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h
parenta78a2d51f5c2eda80188caf7a1045a5c8bdce1b3 (diff)
downloadydb-48a18a64bb612e73011e1c49aef96b8dad6bffba.tar.gz
Upd libc++ to d0af4276d62418ba9e54fec99b293d2fd7c92213 (14 Mar 2022)
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h')
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h b/contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h
index 2a69f6ee47..2932a5e31d 100644
--- a/contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h
+++ b/contrib/libs/cxxsupp/libcxx/include/__algorithm/pop_heap.h
@@ -11,10 +11,11 @@
#include <__algorithm/comp.h>
#include <__algorithm/comp_ref_type.h>
+#include <__algorithm/push_heap.h>
#include <__algorithm/sift_down.h>
#include <__config>
#include <__iterator/iterator_traits.h>
-#include <__utility/swap.h>
+#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -28,10 +29,21 @@ void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
{
+ using value_type = typename iterator_traits<_RandomAccessIterator>::value_type;
+
if (__len > 1)
{
- swap(*__first, *--__last);
- _VSTD::__sift_down<_Compare>(__first, __comp, __len - 1, __first);
+ value_type __top = std::move(*__first); // create a hole at __first
+ _RandomAccessIterator __hole = std::__floyd_sift_down<_Compare>(__first, __comp, __len);
+ --__last;
+ if (__hole == __last) {
+ *__hole = std::move(__top);
+ } else {
+ *__hole = std::move(*__last);
+ ++__hole;
+ *__last = std::move(__top);
+ std::__sift_up<_Compare>(__first, __hole, __comp, __hole - __first);
+ }
}
}