/*
*
* 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.
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef __SGI_STL_INTERNAL_ALGO_H
#define __SGI_STL_INTERNAL_ALGO_H
#include <stl_heap.h>
__STL_BEGIN_NAMESPACE
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma set woff 1209
#endif
template <class T>
inline const T& __median(const T& a, const T& b, const T& c) {
if (a < b)
if (b < c)
return b;
else if (a < c)
return c;
else
return a;
else if (a < c)
return a;
else if (b < c)
return c;
else
return b;
}
template <class T, class Compare>
inline const T& __median(const T& a, const T& b, const T& c, Compare comp) {
if (comp(a, b))
if (comp(b, c))
return b;
else if (comp(a, c))
return c;
else
return a;
else if (comp(a, c))
return a;
else if (comp(b, c))
return c;
else
return b;
}
template <class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f) {
for ( ; first != last; ++first)
f(*first);
return f;
}
template <class InputIterator, class T>
InputIterator find(InputIterator first, InputIterator last, const T& value) {
while (first != last && *first != value) ++first;
return first;
}
template <class InputIterator, class Predicate>
InputIterator find_if(InputIterator first, InputIterator last,
Predicate pred) {
while (first != last && !pred(*first)) ++first;
return first;
}
template <class ForwardIterator>
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last) {
if (first == last) return last;
ForwardIterator next = first;
while(++next != last) {
if (*first == *next) return first;
first = next;
}
return last;
}
template <class ForwardIterator, class BinaryPredicate>
ForwardIterator adjacent_find(ForwardIterator first, ForwardIterator last,
BinaryPredicate binary_pred) {
if (first == last) return last;
ForwardIterator next = first;
while(++next != last) {
if (binary_pred(*first, *next)) return first;
first = next;
}
return last;
}
template <class InputIterator, class T, class Size>
void count(InputIterator first, InputIterator last, const T& value,
Size& n) {
for ( ; first != last; ++first)
if (*first == value)
++n;
}
template <class InputIterator, class Predicate, class Size>
void count_if(InputIterator first, InputIterator last, Predicate pred,
Size& n) {
for ( ; first != last; ++first)
if (pred(*first))
++n;
}
#ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
template <class InputIterator, class T>
typename iterator_traits<InputIterator>::difference_type
count(InputIterator first, InputIterator last, const T& value) {
typename iterator_traits<InputIterator>::difference_type n = 0;
for ( ; first != last; ++first)
if (*first == value)
++n;
return n;
}
template <class InputIterator, class Predicate>
typename iterator_traits<InputIterator>::difference_type
count_if(InputIterator first, InputIterator last, Predicate pred) {
typename iterator_traits<InputIterator>::difference_type n = 0;
for ( ; first != last; ++first)
if (pred(*first))
++n;
return n;
}
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
template <class ForwardIterator1, class ForwardIterator2, class Distance1,
class Distance2>
ForwardIterator1 __search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
Distance1*, Distance2*) {
Distance1 d1 = 0;
distance(first1, last1, d1);
Distance2 d2 = 0;
distance(first2, last2, d2);
if (d1 < d2) return last1;
ForwardIterator1 current1 = first1;
ForwardIterator2 current2 = first2;
while (current2 != last2)
if (*current1 == *current2) {
++current1;
++current2;
}
else {
if (d1 == d2)
return last1;
else {
current1 = ++first1;
current2 = first2;
--d1;
}
}
return first1;
}
template <class ForwardIterator1, class ForwardIterator2>
inline ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2)
{
return __search(first1, last1, first2, last2, distance_type(first1),
distance_type(first2));
}
template <class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate, class Distance1, class Distance2>
ForwardIterator1 __search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate binary_pred, Distance1*, Distance2*) {
Distance1 d1 = 0;
distance(first1, last1, d1);
Distance2 d2 = 0;
distance(first2, last2, d2);
if (d1 < d2) return last1;
ForwardIterator1 current1 = first1;
ForwardIterator2 current2 = first2;
while (current2 != last2)
if (binary_pred(*current1, *current2)) {
++current1;
++current2;
}
else {
if (d1 == d2)
return last1;
else {
current1 = ++first1;
current2 = first2;
--d1;
}
}
return first1;
}
template <class ForwardIterator1, class ForwardIterator2,
class BinaryPredicate>
inline ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate binary_pred) {
return __search(first1, last1, first2, last2, binary_pred,
distance_type(first1), distance_type(first2));
}
template <class ForwardIterator, class Integer, class T>
ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
Integer count, const T& value) {
if (count <= 0)
return first;
else {
first = find(first, last, value);
while (first != last) {
Integer n = count - 1;
ForwardIterator i = first;
++i;
while (i != last && n != 0 && *i == value) {
++i;
--n;
}
if (n == 0)
return first;
else
first = find(i, last, value);
}
return last;
}
}
template <class ForwardIterator, class Integer, class T, class BinaryPredicate>
ForwardIterator search_n(ForwardIterator first, ForwardIterator last,
Integer count, const T& value,
BinaryPredicate binary_pred) {
if (count <= 0)
return first;
else {
while (first != last) {
if (binary_pred(*first, value)) break;
++first;
}
while (first != last) {
Integer n = count - 1;
ForwardIterator i = first;
++i;
while (i != last && n != 0 && binary
没有合适的资源?快使用搜索试试~ 我知道了~
stl-SGI-30.zip
共77个文件
h:58个
vector:1个
stack:1个
需积分: 0 3 下载量 120 浏览量
2023-02-04
22:35:20
上传
评论
收藏 144KB ZIP 举报
温馨提示
C++/STL 的 SGI3.0 版本,源代码
资源推荐
资源详情
资源评论
收起资源包目录
stl_SGI_30.zip (77个子文件)
stl_construct.h 2KB
stl_stack.h 2KB
slist.h 830B
stl_vector.h 17KB
stl_iterator.h 26KB
algobase.h 2KB
stl_map.h 7KB
list.h 1KB
multimap.h 1KB
stack.h 1KB
set.h 1KB
type_traits.h 9KB
stl_algobase.h 14KB
stl_multimap.h 7KB
ropeimpl.h 42KB
stl_function.h 18KB
iterator.h 3KB
utility 1KB
stl_heap.h 8KB
defalloc.h 2KB
stl_numeric.h 6KB
stl_relops.h 2KB
alloc.h 1KB
stl_set.h 7KB
stl_tempbuf.h 3KB
map 1KB
hash_map 1KB
function.h 3KB
stl_list.h 17KB
stl_hash_set.h 13KB
stl_deque.h 41KB
deque.h 1KB
list 1KB
tempbuf.h 2KB
stl_pair.h 2KB
vector 1KB
map.h 1KB
stack 1KB
stl_rope.h 61KB
functional 762B
limits 14KB
heap.h 1KB
stl_slist.h 20KB
queue 1KB
multiset.h 1KB
deque 1KB
tree.h 1KB
iterator 1KB
stl_config.h 8KB
stl_queue.h 4KB
stl_alloc.h 21KB
rope 920B
algorithm 1KB
stl_hash_map.h 13KB
pthread_alloc 10KB
hash_set.h 1KB
hash_map.h 1KB
memory 2KB
vector.h 1KB
algo.h 3KB
slist 807B
pair.h 1KB
numeric 1KB
stl_uninitialized.h 8KB
stl_tree.h 35KB
stl_multiset.h 7KB
pthread_alloc.h 867B
stl_algo.h 84KB
stl_raw_storage_iter.h 3KB
stl_hash_fun.h 3KB
stl_hashtable.h 26KB
bvector.h 1KB
set 1KB
rope.h 909B
hash_set 1KB
hashtable.h 2KB
stl_bvector.h 18KB
共 77 条
- 1
资源评论
枫叶先生
- 粉丝: 3859
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功