// Algorithm implementation -*- C++ -*-
// Copyright (C) 2001-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file bits/stl_algo.h
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{algorithm}
*/
#ifndef _STL_ALGO_H
#define _STL_ALGO_H 1
#include <cstdlib> // for rand
#include <bits/algorithmfwd.h>
#include <bits/stl_heap.h>
#include <bits/stl_tempbuf.h> // for _Temporary_buffer
#if __cplusplus >= 201103L
#include <random> // for std::uniform_int_distribution
#include <functional> // for std::bind
#endif
// See concept_check.h for the __glibcxx_*_requires macros.
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Swaps the median value of *__a, *__b and *__c to *__result
template<typename _Iterator>
void
__move_median_to_first(_Iterator __result, _Iterator __a,
_Iterator __b, _Iterator __c)
{
// concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_Iterator>::value_type>)
if (*__a < *__b)
{
if (*__b < *__c)
std::iter_swap(__result, __b);
else if (*__a < *__c)
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __a);
}
else if (*__a < *__c)
std::iter_swap(__result, __a);
else if (*__b < *__c)
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __b);
}
/// Swaps the median value of *__a, *__b and *__c under __comp to *__result
template<typename _Iterator, typename _Compare>
void
__move_median_to_first(_Iterator __result, _Iterator __a,
_Iterator __b, _Iterator __c,
_Compare __comp)
{
// concept requirements
__glibcxx_function_requires(_BinaryFunctionConcept<_Compare, bool,
typename iterator_traits<_Iterator>::value_type,
typename iterator_traits<_Iterator>::value_type>)
if (__comp(*__a, *__b))
{
if (__comp(*__b, *__c))
std::iter_swap(__result, __b);
else if (__comp(*__a, *__c))
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __a);
}
else if (__comp(*__a, *__c))
std::iter_swap(__result, __a);
else if (__comp(*__b, *__c))
std::iter_swap(__result, __c);
else
std::iter_swap(__result, __b);
}
// for_each
/// This is an overload used by find() for the Input Iterator case.
template<typename _InputIterator, typename _Tp>
inline _InputIterator
__find(_InputIterator __first, _InputIterator __last,
const _Tp& __val, input_iterator_tag)
{
while (__first != __last && !(*__first == __val))
++__first;
return __first;
}
/// This is an overload used by find_if() for the Input Iterator case.
template<typename _InputIterator, typename _Predicate>
inline _InputIterator
__find_if(_InputIterator __first, _InputIterator __last,
_Predicate __pred, input_iterator_tag)
{
while (__first != __last && !bool(__pred(*__first)))
++__first;
return __first;
}
/// This is an overload used by find() for the RAI case.
template<typename _RandomAccessIterator, typename _Tp>
_RandomAccessIterator
__find(_RandomAccessIterator __first, _RandomAccessIterator __last,
const _Tp& __val, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::difference_type
__trip_count = (__last - __first) >> 2;
for (; __trip_count > 0; --__trip_count)
{
if (*__first == __val)
return __first;
++__first;
if (*__first == __val)
return __first;
++__first;
if (*__first == __val)
return __first;
++__first;
if (*__first == __val)
return __first;
++__first;
}
switch (__last - __first)
{
case 3:
if (*__first == __val)
return __first;
++__first;
case 2:
if (*__first == __val)
return __first;
++__first;
case 1:
if (*__first == __val)
return __first;
++__first;
case 0:
default:
return __last;
}
}
/// This is an overload used by find_if() for the RAI case.
template<typename _RandomAccessIterator, typename _Predicate>
_RandomAccessIterator
__find_if(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Predicate __pred, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::difference_type
__trip_count = (__last - __first) >> 2;
for (; __trip_count > 0; --__trip_count)
{
if (__pred(*__first))
return __first;
++__first;
if (__pred(*__first))
return __first;
++__first;
if (__pred(*__first))
return __first;
++__first;
if (__pred(*__first))
return __first;
++__first;
}
switch (__last - __first)
{
case 3:
if (__pred(*__first))
return __first;
++__first;
case 2:
if (__pred(*__first))
return __first;
++__first;
case 1:
if (__pred(*__first))
return __first;
++__first;
case 0:
default:
return __last;
}
}
/// This is an overload used by find_if_not() for the Input Iterator case.
template<typename _InputIterator, typename _Predicate>
inline _InputIterator
__find_if_not(_InputIterator __first, _InputIterator __last,
_Predicate __pred, input_iterator_tag)
{
while (__first != __last && bool(__pred(*__first)))
++__first;
return __first;
}
/// This is an overload used by find_if_not() for the RAI case.
template<typename _RandomAccessIterator, typename _Predicate>
_RandomAccessIterator
__find_if_not(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Predicate __pred, random_access_iterator_tag)
{
typename iterator_traits<_RandomAccessIterator>::difference_type
__trip_count = (__last - __first) >> 2;
for (; __trip_count > 0; --__trip_count)
{
if (!bool(__pred(*__first)))
return __first;
++__fir
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ESP8266编译工具(用于cygwin) (980个子文件)
libstdc++.a 9.49MB
libc.a 2.63MB
libc.a 1.48MB
libg.a 1.48MB
libm.a 1MB
libiberty.a 961KB
libsupc++.a 788KB
libgcc.a 710KB
libhal.a 339KB
liblto_plugin.dll.a 54KB
libgcov.a 43KB
algorithm 19KB
algorithm 2KB
algorithm 1KB
array 9KB
array 9KB
array 8KB
array 7KB
atomic 33KB
bitset 45KB
bitset 12KB
bitset 10KB
bool_set 7KB
build.log.bz2 232KB
cassert 2KB
ccomplex 1KB
ccomplex 1KB
cctype 2KB
cctype 1KB
cerrno 2KB
cfenv 2KB
cfenv 2KB
cfloat 2KB
cfloat 1KB
chrono 23KB
cinttypes 2KB
cinttypes 2KB
ciso646 1KB
climits 2KB
climits 1KB
clocale 2KB
cmath 41KB
cmath 37KB
cmath 6KB
complex 51KB
complex 12KB
condition_variable 8KB
mkheaders.conf 187B
xtensa-lx106-elf-ct-ng.config 3KB
xt-ct-ng.config 72B
csetjmp 2KB
csignal 2KB
cstdalign 1KB
cstdarg 2KB
cstdarg 1KB
cstdbool 1KB
cstdbool 1KB
cstddef 2KB
cstdint 3KB
cstdint 2KB
cstdio 4KB
cstdio 1KB
cstdlib 6KB
cstdlib 2KB
cstring 3KB
ctgmath 1KB
ctgmath 1KB
ctime 2KB
ctime 1KB
cwchar 6KB
cwchar 2KB
cwctype 3KB
cwctype 1KB
decimal 17KB
deque 14KB
deque 11KB
deque 3KB
cyglto_plugin-0.dll 64KB
gdb-syscalls.dtd 461B
dynamic_bitset 41KB
exception 5KB
cc1plus.exe 10.61MB
cc1.exe 9.69MB
lto1.exe 9.14MB
xtensa-lx106-elf-gdb.exe 3.53MB
ld.bfd.exe 984KB
xtensa-lx106-elf-ld.exe 984KB
xtensa-lx106-elf-ld.bfd.exe 984KB
ld.exe 984KB
xtensa-lx106-elf-as.exe 978KB
as.exe 978KB
objdump.exe 947KB
xtensa-lx106-elf-objdump.exe 947KB
xtensa-lx106-elf-objcopy.exe 837KB
xtensa-lx106-elf-strip.exe 837KB
objcopy.exe 837KB
strip.exe 837KB
xtensa-lx106-elf-gprof.exe 735KB
xtensa-lx106-elf-ranlib.exe 695KB
ranlib.exe 695KB
共 980 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
徐松亮
- 粉丝: 172
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功