Просмотр исходного кода

Upd libc++ to 18 Jun 2022 ff3989e6ae740a9b3adaad0e2bf7691ffd6dad12

```
[libc++] Add Implemented Papers section
[libc++] Enable -Wweak-vtables
[libc++] Make sure we install libc++abi headers on Apple
[libc++] Don't force -O2 when building the benchmarks
[libc++] Mark standard-mandated includes as such
[libc++] Implement std::boyer_moore{, _horspool}_searcher
[libc++] Unwrap reverse_iterator<reverse_iterator<Iter>> in __unwrap_iter
[libc++] Simplify __config a bit
[libc++][ranges] Implement `ranges::sort`.
[libc++] Remove now-unused experimental/filesystem config file
[libc++] Robust against C++20-hostile iterators
[libc++] Implement ranges::lexicographical_compare
[libc++] Removes unneeded <iterator> includes.
[libcxx] Fix allocator<void>::pointer in C++20 with removed members
[libcxx] Remove extraneous '---' lines in .clang-format files
[libc++][NFCI] span: replace enable_if with concepts
[libc++] Find a clang-format everybody is happy with
[libc++] Use explicit module cache path in tests
[libc++] Remove macros for IBM compiler
```
mikhnenko 1 год назад
Родитель
Сommit
c67f6bf0e3

+ 4 - 0
build/sysincl/stl-to-libcxx.yml

@@ -233,6 +233,7 @@
   - __algorithm/lexicographical_compare.h:                 contrib/libs/cxxsupp/libcxx/include/__algorithm/lexicographical_compare.h
   - __algorithm/lower_bound.h:                             contrib/libs/cxxsupp/libcxx/include/__algorithm/lower_bound.h
   - __algorithm/make_heap.h:                               contrib/libs/cxxsupp/libcxx/include/__algorithm/make_heap.h
+  - __algorithm/make_projected.h:                          contrib/libs/cxxsupp/libcxx/include/__algorithm/make_projected.h
   - __algorithm/max.h:                                     contrib/libs/cxxsupp/libcxx/include/__algorithm/max.h
   - __algorithm/max_element.h:                             contrib/libs/cxxsupp/libcxx/include/__algorithm/max_element.h
   - __algorithm/merge.h:                                   contrib/libs/cxxsupp/libcxx/include/__algorithm/merge.h
@@ -277,6 +278,7 @@
   - __algorithm/ranges_is_partitioned.h:                   contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_is_partitioned.h
   - __algorithm/ranges_is_sorted.h:                        contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_is_sorted.h
   - __algorithm/ranges_is_sorted_until.h:                  contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_is_sorted_until.h
+  - __algorithm/ranges_lexicographical_compare.h:          contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_lexicographical_compare.h
   - __algorithm/ranges_lower_bound.h:                      contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_lower_bound.h
   - __algorithm/ranges_max.h:                              contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_max.h
   - __algorithm/ranges_max_element.h:                      contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_max_element.h
@@ -289,6 +291,7 @@
   - __algorithm/ranges_replace.h:                          contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_replace.h
   - __algorithm/ranges_replace_if.h:                       contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_replace_if.h
   - __algorithm/ranges_reverse.h:                          contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_reverse.h
+  - __algorithm/ranges_sort.h:                             contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_sort.h
   - __algorithm/ranges_swap_ranges.h:                      contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_swap_ranges.h
   - __algorithm/ranges_transform.h:                        contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_transform.h
   - __algorithm/ranges_upper_bound.h:                      contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_upper_bound.h
@@ -434,6 +437,7 @@
   - __functional/bind_front.h:                             contrib/libs/cxxsupp/libcxx/include/__functional/bind_front.h
   - __functional/binder1st.h:                              contrib/libs/cxxsupp/libcxx/include/__functional/binder1st.h
   - __functional/binder2nd.h:                              contrib/libs/cxxsupp/libcxx/include/__functional/binder2nd.h
+  - __functional/boyer_moore_searcher.h:                   contrib/libs/cxxsupp/libcxx/include/__functional/boyer_moore_searcher.h
   - __functional/compose.h:                                contrib/libs/cxxsupp/libcxx/include/__functional/compose.h
   - __functional/default_searcher.h:                       contrib/libs/cxxsupp/libcxx/include/__functional/default_searcher.h
   - __functional/function.h:                               contrib/libs/cxxsupp/libcxx/include/__functional/function.h

+ 1 - 1
build/ymake.core.conf

@@ -9,7 +9,7 @@
 FAKEID=628318530716
 
 SANDBOX_FAKEID=${FAKEID}.7600000
-CPP_FAKEID=2023-10-27
+CPP_FAKEID=2023-11-01
 GO_FAKEID=11100371
 ANDROID_FAKEID=2023-05-17
 CLANG_TIDY_FAKEID=2023-06-06

+ 0 - 19
contrib/libs/cxxsupp/libcxx/include/__algorithm/copy.h

@@ -74,13 +74,6 @@ __copy_impl(reverse_iterator<_InIter> __first,
   return std::make_pair(__last, reverse_iterator<_OutIter>(std::__rewrap_iter(__result.base(), __result_first)));
 }
 
-template <class _InIter, class _Sent, class _OutIter>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
-pair<reverse_iterator<reverse_iterator<_InIter> >, reverse_iterator<reverse_iterator<_OutIter> > >
-__copy_impl(reverse_iterator<reverse_iterator<_InIter> > __first,
-            reverse_iterator<reverse_iterator<_Sent> > __last,
-            reverse_iterator<reverse_iterator<_OutIter> > __result);
-
 template <class _InIter, class _Sent, class _OutIter,
           __enable_if_t<!(is_copy_constructible<_InIter>::value
                        && is_copy_constructible<_Sent>::value
@@ -101,18 +94,6 @@ __copy(_InIter __first, _Sent __last, _OutIter __result) {
   return std::make_pair(std::__rewrap_iter(__first, __ret.first), std::__rewrap_iter(__result, __ret.second));
 }
 
-// __unwrap_iter can't unwrap random_access_iterators, so we need to unwrap two reverse_iterators manually
-template <class _InIter, class _Sent, class _OutIter>
-inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11
-pair<reverse_iterator<reverse_iterator<_InIter> >, reverse_iterator<reverse_iterator<_OutIter> > >
-__copy_impl(reverse_iterator<reverse_iterator<_InIter> > __first,
-            reverse_iterator<reverse_iterator<_Sent> > __last,
-            reverse_iterator<reverse_iterator<_OutIter> > __result) {
-  auto __ret = std::__copy(__first.base().base(), __last.base().base(), __result.base().base());
-  return std::make_pair(reverse_iterator<reverse_iterator<_InIter> >(reverse_iterator<_InIter>(__ret.first)),
-                        reverse_iterator<reverse_iterator<_OutIter> >(reverse_iterator<_OutIter>(__ret.second)));
-}
-
 template <class _InputIterator, class _OutputIterator>
 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
 _OutputIterator

+ 51 - 0
contrib/libs/cxxsupp/libcxx/include/__algorithm/make_projected.h

@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
+#define _LIBCPP___ALGORITHM_MAKE_PROJECTED_H
+
+#include <__concepts/same_as.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/invoke.h>
+#include <__utility/forward.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+
+template <class _Comp, class _Proj>
+_LIBCPP_HIDE_FROM_ABI constexpr static
+decltype(auto) __make_projected_comp(_Comp& __comp, _Proj& __proj) {
+  if constexpr (same_as<_Proj, identity>) {
+    // Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable
+    // optimizations that rely on the type of the comparator.
+    return __comp;
+
+  } else {
+    return [&](auto&& __lhs, auto&& __rhs) {
+      return std::invoke(__comp,
+                        std::invoke(__proj, std::forward<decltype(__lhs)>(__lhs)),
+                        std::invoke(__proj, std::forward<decltype(__rhs)>(__rhs)));
+    };
+  }
+}
+
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+#endif // _LIBCPP___ALGORITHM_MAKE_PROJECTED_H

+ 98 - 0
contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_lexicographical_compare.h

@@ -0,0 +1,98 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
+#define _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H
+
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/invoke.h>
+#include <__functional/ranges_operations.h>
+#include <__iterator/concepts.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __lexicographical_compare {
+struct __fn {
+
+  template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Comp>
+  _LIBCPP_HIDE_FROM_ABI constexpr static
+  bool __lexicographical_compare_impl(_Iter1 __first1, _Sent1 __last1,
+                                      _Iter2 __first2, _Sent2 __last2,
+                                      _Comp& __comp,
+                                      _Proj1& __proj1,
+                                      _Proj2& __proj2) {
+    while (__first2 != __last2) {
+      if (__first1 == __last1
+       || std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
+        return true;
+      if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
+        return false;
+      ++__first1;
+      ++__first2;
+    }
+    return false;
+  }
+
+  template <input_iterator _Iter1, sentinel_for<_Iter1> _Sent1,
+            input_iterator _Iter2, sentinel_for<_Iter2> _Sent2,
+            class _Proj1 = identity,
+            class _Proj2 = identity,
+            indirect_strict_weak_order<projected<_Iter1, _Proj1>, projected<_Iter2, _Proj2>> _Comp = ranges::less>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  bool operator()(_Iter1 __first1, _Sent1 __last1,
+                  _Iter2 __first2, _Sent2 __last2,
+                  _Comp __comp = {},
+                  _Proj1 __proj1 = {},
+                  _Proj2 __proj2 = {}) const {
+    return __lexicographical_compare_impl(std::move(__first1), std::move(__last1),
+                                          std::move(__first2), std::move(__last2),
+                                          __comp,
+                                          __proj1,
+                                          __proj2);
+  }
+
+  template <input_range _Range1,
+            input_range _Range2,
+            class _Proj1 = identity,
+            class _Proj2 = identity,
+            indirect_strict_weak_order<projected<iterator_t<_Range1>, _Proj1>,
+                                       projected<iterator_t<_Range2>, _Proj2>> _Comp = ranges::less>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  bool operator()(_Range1&& __range1, _Range2&& __range2, _Comp __comp = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const {
+    return __lexicographical_compare_impl(ranges::begin(__range1), ranges::end(__range1),
+                                          ranges::begin(__range2), ranges::end(__range2),
+                                          __comp,
+                                          __proj1,
+                                          __proj2);
+  }
+
+};
+} // namespace __lexicographical_compare
+
+inline namespace __cpo {
+  inline constexpr auto lexicographical_compare = __lexicographical_compare::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+#endif // _LIBCPP___ALGORITHM_RANGES_LEXICOGRAPHICAL_COMPARE_H

+ 79 - 0
contrib/libs/cxxsupp/libcxx/include/__algorithm/ranges_sort.h

@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_SORT_H
+#define _LIBCPP___ALGORITHM_RANGES_SORT_H
+
+#include <__algorithm/make_projected.h>
+#include <__algorithm/sort.h>
+#include <__concepts/same_as.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/invoke.h>
+#include <__functional/ranges_operations.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__iterator/projected.h>
+#include <__iterator/sortable.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __sort {
+
+struct __fn {
+  template <class _Iter, class _Sent, class _Comp, class _Proj>
+  _LIBCPP_HIDE_FROM_ABI constexpr static
+  _Iter __sort_fn_impl(_Iter __first, _Sent __last, _Comp& __comp, _Proj& __proj) {
+    auto __last_iter = ranges::next(__first, __last);
+
+    auto&& __projected_comp = __make_projected_comp(__comp, __proj);
+    std::__sort_impl(std::move(__first), __last_iter, __projected_comp);
+
+    return __last_iter;
+  }
+
+  template <random_access_iterator _Iter, sentinel_for<_Iter> _Sent, class _Comp = ranges::less, class _Proj = identity>
+    requires sortable<_Iter, _Comp, _Proj>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  _Iter operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
+    return __sort_fn_impl(std::move(__first), std::move(__last), __comp, __proj);
+  }
+
+  template <random_access_range _Range, class _Comp = ranges::less, class _Proj = identity>
+    requires sortable<iterator_t<_Range>, _Comp, _Proj>
+  _LIBCPP_HIDE_FROM_ABI constexpr
+  borrowed_iterator_t<_Range> operator()(_Range&& __r, _Comp __comp = {}, _Proj __proj = {}) const {
+    return __sort_fn_impl(ranges::begin(__r), ranges::end(__r), __comp, __proj);
+  }
+};
+
+} // namespace __sort
+
+inline namespace __cpo {
+  inline constexpr auto sort = __sort::__fn{};
+} // namespace __cpo
+} // namespace ranges
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
+
+#endif // _LIBCPP___ALGORITHM_RANGES_SORT_H

+ 23 - 9
contrib/libs/cxxsupp/libcxx/include/__algorithm/sort.h

@@ -18,6 +18,7 @@
 #include <__config>
 #include <__debug>
 #include <__functional/operations.h>
+#include <__functional/ranges_operations.h>
 #include <__iterator/iterator_traits.h>
 #include <__utility/swap.h>
 #include <climits>
@@ -115,6 +116,7 @@ _LIBCPP_HIDDEN unsigned __sort5(_ForwardIterator __x1, _ForwardIterator __x2, _F
   return __r;
 }
 
+// The comparator being simple is a prerequisite for using the branchless optimization.
 template <class _Tp>
 struct __is_simple_comparator : false_type {};
 template <class _Tp>
@@ -123,6 +125,12 @@ template <class _Tp>
 struct __is_simple_comparator<less<_Tp>&> : true_type {};
 template <class _Tp>
 struct __is_simple_comparator<greater<_Tp>&> : true_type {};
+#if _LIBCPP_STD_VER > 17
+template <>
+struct __is_simple_comparator<ranges::less&> : true_type {};
+template <>
+struct __is_simple_comparator<ranges::greater&> : true_type {};
+#endif
 
 template <class _Compare, class _Iter, class _Tp = typename iterator_traits<_Iter>::value_type>
 using __use_branchless_sort =
@@ -571,22 +579,28 @@ extern template _LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long do
 
 extern template _LIBCPP_FUNC_VIS unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
 
-template <class _RandomAccessIterator, class _Compare>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void
-sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+template <class _RandomAccessIterator, class _Comp>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void __sort_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp& __comp) {
   _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
-  typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+  using _Comp_ref = typename __comp_ref_type<_Comp>::type;
   if (__libcpp_is_constant_evaluated()) {
-    _VSTD::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
+    std::__partial_sort<_Comp_ref>(__first, __last, __last, _Comp_ref(__comp));
   } else {
-    _VSTD::__sort<_Comp_ref>(_VSTD::__unwrap_iter(__first), _VSTD::__unwrap_iter(__last), _Comp_ref(__comp));
+    std::__sort<_Comp_ref>(std::__unwrap_iter(__first), std::__unwrap_iter(__last), _Comp_ref(__comp));
   }
 }
 
+template <class _RandomAccessIterator, class _Comp>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
+  std::__sort_impl(std::move(__first), std::move(__last), __comp);
+}
+
 template <class _RandomAccessIterator>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void sort(_RandomAccessIterator __first,
-                                                                         _RandomAccessIterator __last) {
-  _VSTD::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17
+void sort(_RandomAccessIterator __first, _RandomAccessIterator __last) {
+  std::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
 }
 
 _LIBCPP_END_NAMESPACE_STD

+ 18 - 4
contrib/libs/cxxsupp/libcxx/include/__algorithm/unwrap_iter.h

@@ -63,6 +63,22 @@ __unwrap_iter(_Iter __i) _NOEXCEPT
     return _Impl::__apply(__i);
 }
 
+template <class _OrigIter, class _UnwrappedIter>
+struct __rewrap_iter_impl {
+  static _LIBCPP_CONSTEXPR _OrigIter __apply(_OrigIter __first, _UnwrappedIter __result) {
+    // Precondition: __result is reachable from __first
+    // Precondition: _OrigIter is a contiguous iterator
+    return __first + (__result - std::__unwrap_iter(__first));
+  }
+};
+
+template <class _OrigIter>
+struct __rewrap_iter_impl<_OrigIter, _OrigIter> {
+  static _LIBCPP_CONSTEXPR _OrigIter __apply(_OrigIter, _OrigIter __result) {
+    return __result;
+  }
+};
+
 template<class _OrigIter>
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 _OrigIter __rewrap_iter(_OrigIter, _OrigIter __result)
@@ -70,13 +86,11 @@ _OrigIter __rewrap_iter(_OrigIter, _OrigIter __result)
     return __result;
 }
 
-template<class _OrigIter, class _UnwrappedIter>
+template<class _OrigIter, class _UnwrappedIter, class _Impl = __rewrap_iter_impl<_OrigIter, _UnwrappedIter> >
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 _OrigIter __rewrap_iter(_OrigIter __first, _UnwrappedIter __result)
 {
-    // Precondition: __result is reachable from __first
-    // Precondition: _OrigIter is a contiguous iterator
-    return __first + (__result - _VSTD::__unwrap_iter(__first));
+  return _Impl::__apply(__first, __result);
 }
 
 _LIBCPP_END_NAMESPACE_STD

Разница между файлами не показана из-за своего большого размера
+ 670 - 762
contrib/libs/cxxsupp/libcxx/include/__config


+ 313 - 0
contrib/libs/cxxsupp/libcxx/include/__functional/boyer_moore_searcher.h

@@ -0,0 +1,313 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___FUNCTIONAL_BOYER_MOORE_SEARCHER_H
+#define _LIBCPP___FUNCTIONAL_BOYER_MOORE_SEARCHER_H
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#include <__algorithm/fill_n.h>
+#include <__config>
+#include <__functional/hash.h>
+#include <__functional/operations.h>
+#include <__iterator/distance.h>
+#include <__iterator/iterator_traits.h>
+#include <__memory/shared_ptr.h>
+#include <__utility/pair.h>
+#include <array>
+#include <unordered_map>
+#include <vector>
+
+#if _LIBCPP_STD_VER > 14
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Key,
+          class _Value,
+          class _Hash,
+          class _BinaryPredicate,
+          bool /*useArray*/>
+class _BMSkipTable;
+
+// General case for BM data searching; use a map
+template <class _Key,
+          class _Value,
+          class _Hash,
+          class _BinaryPredicate>
+class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, false> {
+private:
+  using value_type = _Value;
+  using key_type = _Key;
+
+  const value_type __default_value_;
+  unordered_map<_Key, _Value, _Hash, _BinaryPredicate> __table_;
+
+public:
+  _LIBCPP_HIDE_FROM_ABI
+  explicit _BMSkipTable(size_t __sz, value_type __default_value, _Hash __hash, _BinaryPredicate __pred)
+      : __default_value_(__default_value),
+        __table_(__sz, __hash, __pred) {}
+
+  _LIBCPP_HIDE_FROM_ABI void insert(const key_type& __key, value_type __val) {
+    __table_[__key] = __val;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI value_type operator[](const key_type& __key) const {
+    auto __it = __table_.find(__key);
+    return __it == __table_.end() ? __default_value_ : __it->second;
+  }
+};
+
+// Special case small numeric values; use an array
+template <class _Key,
+          class _Value,
+          class _Hash,
+          class _BinaryPredicate>
+class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, true> {
+private:
+  using value_type = _Value;
+  using key_type = _Key;
+
+  using unsigned_key_type = make_unsigned_t<key_type>;
+  std::array<value_type, 256> __table_;
+  static_assert(numeric_limits<unsigned_key_type>::max() < 256);
+
+public:
+  _LIBCPP_HIDE_FROM_ABI explicit _BMSkipTable(size_t, value_type __default_value, _Hash, _BinaryPredicate) {
+    std::fill_n(__table_.data(), __table_.size(), __default_value);
+  }
+
+  _LIBCPP_HIDE_FROM_ABI void insert(key_type __key, value_type __val) {
+    __table_[static_cast<unsigned_key_type>(__key)] = __val;
+  }
+
+  _LIBCPP_HIDE_FROM_ABI value_type operator[](key_type __key) const {
+    return __table_[static_cast<unsigned_key_type>(__key)];
+  }
+};
+
+template <class _RandomAccessIterator1,
+          class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
+          class _BinaryPredicate = equal_to<>>
+class _LIBCPP_TEMPLATE_VIS boyer_moore_searcher {
+private:
+  using difference_type = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+  using value_type = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
+  using __skip_table_type = _BMSkipTable<value_type,
+                                         difference_type,
+                                         _Hash,
+                                         _BinaryPredicate,
+                                         is_integral_v<value_type>
+                                      && sizeof(value_type) == 1
+                                      && is_same_v<_Hash, hash<value_type>>
+                                      && is_same_v<_BinaryPredicate, equal_to<>>>;
+
+public:
+  boyer_moore_searcher(_RandomAccessIterator1 __first,
+                       _RandomAccessIterator1 __last,
+                       _Hash __hash = _Hash(),
+                       _BinaryPredicate __pred = _BinaryPredicate())
+    : __first_(__first),
+      __last_(__last),
+      __pred_(__pred),
+      __pattern_length_(__last - __first),
+      __skip_table_(std::make_shared<__skip_table_type>(__pattern_length_, -1, __hash, __pred_)),
+      __suffix_(std::__allocate_shared_unbounded_array<difference_type[]>(
+          allocator<difference_type>(), __pattern_length_ + 1)) {
+    difference_type __i = 0;
+    while (__first != __last) {
+      __skip_table_->insert(*__first, __i);
+      ++__first;
+      ++__i;
+    }
+    __build_suffix_table(__first_, __last_, __pred_);
+  }
+
+  template <class _RandomAccessIterator2>
+  pair<_RandomAccessIterator2, _RandomAccessIterator2>
+  operator()(_RandomAccessIterator2 __first, _RandomAccessIterator2 __last) const {
+    static_assert(__is_same_uncvref<typename iterator_traits<_RandomAccessIterator1>::value_type,
+                                    typename iterator_traits<_RandomAccessIterator2>::value_type>::value,
+                  "Corpus and Pattern iterators must point to the same type");
+    if (__first == __last)
+      return std::make_pair(__last, __last);
+    if (__first_ == __last_)
+      return std::make_pair(__first, __first);
+
+    if (__pattern_length_ > (__last - __first))
+      return std::make_pair(__last, __last);
+    return __search(__first, __last);
+  }
+
+private:
+  _RandomAccessIterator1 __first_;
+  _RandomAccessIterator1 __last_;
+  _BinaryPredicate __pred_;
+  difference_type __pattern_length_;
+  shared_ptr<__skip_table_type> __skip_table_;
+  shared_ptr<difference_type[]> __suffix_;
+
+  template <class _RandomAccessIterator2>
+  pair<_RandomAccessIterator2, _RandomAccessIterator2>
+  __search(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const {
+    _RandomAccessIterator2 __current = __f;
+    const _RandomAccessIterator2 __last = __l - __pattern_length_;
+    const __skip_table_type& __skip_table = *__skip_table_;
+
+    while (__current <= __last) {
+      difference_type __j = __pattern_length_;
+      while (__pred_(__first_[__j - 1], __current[__j - 1])) {
+        --__j;
+        if (__j == 0)
+          return std::make_pair(__current, __current + __pattern_length_);
+      }
+
+      difference_type __k = __skip_table[__current[__j - 1]];
+      difference_type __m = __j - __k - 1;
+      if (__k < __j && __m > __suffix_[__j])
+        __current += __m;
+      else
+        __current += __suffix_[__j];
+    }
+    return std::make_pair(__l, __l);
+  }
+
+  template <class _Iterator, class _Container>
+  void __compute_bm_prefix(_Iterator __first, _Iterator __last, _BinaryPredicate __pred, _Container& __prefix) {
+    const size_t __count = __last - __first;
+
+    __prefix[0] = 0;
+    size_t __k = 0;
+
+    for (size_t __i = 1; __i != __count; ++__i) {
+      while (__k > 0 && !__pred(__first[__k], __first[__i]))
+        __k = __prefix[__k - 1];
+
+      if (__pred(__first[__k], __first[__i]))
+        ++__k;
+      __prefix[__i] = __k;
+    }
+  }
+
+  void __build_suffix_table(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _BinaryPredicate __pred) {
+    const size_t __count = __last - __first;
+
+    if (__count == 0)
+      return;
+
+    vector<difference_type> __scratch(__count);
+
+    __compute_bm_prefix(__first, __last, __pred, __scratch);
+    for (size_t __i = 0; __i <= __count; ++__i)
+      __suffix_[__i] = __count - __scratch[__count - 1];
+
+    using _ReverseIter = reverse_iterator<_RandomAccessIterator1>;
+    __compute_bm_prefix(_ReverseIter(__last), _ReverseIter(__first), __pred, __scratch);
+
+    for (size_t __i = 0; __i != __count; ++__i) {
+      const size_t __j = __count - __scratch[__i];
+      const difference_type __k = __i - __scratch[__i] + 1;
+
+      if (__suffix_[__j] > __k)
+        __suffix_[__j] = __k;
+    }
+  }
+};
+
+template <class _RandomAccessIterator1,
+          class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>,
+          class _BinaryPredicate = equal_to<>>
+class _LIBCPP_TEMPLATE_VIS boyer_moore_horspool_searcher {
+private:
+  using difference_type = typename iterator_traits<_RandomAccessIterator1>::difference_type;
+  using value_type = typename iterator_traits<_RandomAccessIterator1>::value_type;
+  using __skip_table_type = _BMSkipTable<value_type,
+                                         difference_type,
+                                         _Hash,
+                                         _BinaryPredicate,
+                                         is_integral_v<value_type>
+                                      && sizeof(value_type) == 1
+                                      && is_same_v<_Hash, hash<value_type>>
+                                      && is_same_v<_BinaryPredicate, equal_to<>>>;
+public:
+  boyer_moore_horspool_searcher(_RandomAccessIterator1 __first,
+                                _RandomAccessIterator1 __last,
+                                _Hash __hash = _Hash(),
+                                _BinaryPredicate __pred = _BinaryPredicate())
+    : __first_(__first),
+      __last_(__last),
+      __pred_(__pred),
+      __pattern_length_(__last - __first),
+      __skip_table_(std::make_shared<__skip_table_type>(__pattern_length_, __pattern_length_, __hash, __pred_)) {
+    if (__first == __last)
+      return;
+    --__last;
+    difference_type __i = 0;
+    while (__first != __last) {
+      __skip_table_->insert(*__first, __pattern_length_ - 1 - __i);
+      ++__first;
+      ++__i;
+    }
+  }
+
+  template <class _RandomAccessIterator2>
+  pair<_RandomAccessIterator2, _RandomAccessIterator2>
+  operator()(_RandomAccessIterator2 __first, _RandomAccessIterator2 __last) const {
+    static_assert(__is_same_uncvref<typename std::iterator_traits<_RandomAccessIterator1>::value_type,
+                                    typename std::iterator_traits<_RandomAccessIterator2>::value_type>::value,
+                  "Corpus and Pattern iterators must point to the same type");
+    if (__first == __last)
+      return std::make_pair(__last, __last);
+    if (__first_ == __last_)
+      return std::make_pair(__first, __first);
+
+    if (__pattern_length_ > __last - __first)
+      return std::make_pair(__last, __last);
+
+    return __search(__first, __last);
+  }
+
+private:
+  _RandomAccessIterator1 __first_;
+  _RandomAccessIterator1 __last_;
+  _BinaryPredicate __pred_;
+  difference_type __pattern_length_;
+  shared_ptr<__skip_table_type> __skip_table_;
+
+  template <class _RandomAccessIterator2>
+  pair<_RandomAccessIterator2, _RandomAccessIterator2>
+  __search(_RandomAccessIterator2 __f, _RandomAccessIterator2 __l) const {
+    _RandomAccessIterator2 __current = __f;
+    const _RandomAccessIterator2 __last = __l - __pattern_length_;
+    const __skip_table_type& __skip_table = *__skip_table_;
+
+    while (__current <= __last) {
+      difference_type __j = __pattern_length_;
+      while (__pred_(__first_[__j - 1], __current[__j - 1])) {
+        --__j;
+        if (__j == 0)
+          return std::make_pair(__current, __current + __pattern_length_);
+      }
+      __current += __skip_table[__current[__pattern_length_ - 1]];
+    }
+    return std::make_pair(__l, __l);
+  }
+};
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP_STD_VER > 14
+
+#endif // _LIBCPP___FUNCTIONAL_BOYER_MOORE_SEARCHER_H

Некоторые файлы не были показаны из-за большого количества измененных файлов