algorithm.cpp revision 355940
1//===----------------------- algorithm.cpp --------------------------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#include "algorithm" 10#include "random" 11#ifndef _LIBCPP_HAS_NO_THREADS 12#include "mutex" 13#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) 14#pragma comment(lib, "pthread") 15#endif 16#endif 17 18_LIBCPP_BEGIN_NAMESPACE_STD 19 20template void __sort<__less<char>&, char*>(char*, char*, __less<char>&); 21template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&); 22template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&); 23template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&); 24template void __sort<__less<short>&, short*>(short*, short*, __less<short>&); 25template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&); 26template void __sort<__less<int>&, int*>(int*, int*, __less<int>&); 27template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&); 28template void __sort<__less<long>&, long*>(long*, long*, __less<long>&); 29template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&); 30template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&); 31template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&); 32template void __sort<__less<float>&, float*>(float*, float*, __less<float>&); 33template void __sort<__less<double>&, double*>(double*, double*, __less<double>&); 34template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&); 35 36template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&); 37template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&); 38template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&); 39template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&); 40template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&); 41template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&); 42template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&); 43template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&); 44template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&); 45template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&); 46template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&); 47template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&); 48template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&); 49template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&); 50template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&); 51 52template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&); 53 54#ifndef _LIBCPP_HAS_NO_THREADS 55_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER; 56#endif 57unsigned __rs_default::__c_ = 0; 58 59__rs_default::__rs_default() 60{ 61#ifndef _LIBCPP_HAS_NO_THREADS 62 __libcpp_mutex_lock(&__rs_mut); 63#endif 64 __c_ = 1; 65} 66 67__rs_default::__rs_default(const __rs_default&) 68{ 69 ++__c_; 70} 71 72__rs_default::~__rs_default() 73{ 74#ifndef _LIBCPP_HAS_NO_THREADS 75 if (--__c_ == 0) 76 __libcpp_mutex_unlock(&__rs_mut); 77#else 78 --__c_; 79#endif 80} 81 82__rs_default::result_type 83__rs_default::operator()() 84{ 85 static mt19937 __rs_g; 86 return __rs_g(); 87} 88 89__rs_default 90__rs_get() 91{ 92 return __rs_default(); 93} 94 95_LIBCPP_END_NAMESPACE_STD 96