Commit ffa67767 by Paolo Carlini Committed by Paolo Carlini

stl_algo.h: Wrap overlong lines...

2004-01-31  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_algo.h: Wrap overlong lines, constify
	a few variables, reformat according to the coding standards.
	* include/bits/stl_algobase.h: Likewise.
	* include/bits/stl_heap.h: Likewise.

From-SVN: r77050
parent fdf064f2
2004-01-31 Paolo Carlini <pcarlini@suse.de> 2004-01-31 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_algo.h: Wrap overlong lines, constify
a few variables, reformat according to the coding standards.
* include/bits/stl_algobase.h: Likewise.
* include/bits/stl_heap.h: Likewise.
2004-01-31 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.h (_Rep::operator[]): Remove, unused. * include/bits/basic_string.h (_Rep::operator[]): Remove, unused.
* include/bits/basic_string.h: Fix two comments. * include/bits/basic_string.h: Fix two comments.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -91,16 +91,22 @@ namespace std ...@@ -91,16 +91,22 @@ namespace std
inline void inline void
iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
{ {
typedef typename iterator_traits<_ForwardIterator1>::value_type _ValueType1; typedef typename iterator_traits<_ForwardIterator1>::value_type
typedef typename iterator_traits<_ForwardIterator2>::value_type _ValueType2; _ValueType1;
typedef typename iterator_traits<_ForwardIterator2>::value_type
_ValueType2;
// concept requirements // concept requirements
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIterator1>) __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIterator2>) _ForwardIterator1>)
__glibcxx_function_requires(_ConvertibleConcept<_ValueType1, _ValueType2>) __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
__glibcxx_function_requires(_ConvertibleConcept<_ValueType2, _ValueType1>) _ForwardIterator2>)
__glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
_ValueType1 __tmp = *__a; _ValueType2>)
__glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
_ValueType1>)
const _ValueType1 __tmp = *__a;
*__a = *__b; *__a = *__b;
*__b = __tmp; *__b = __tmp;
} }
...@@ -121,7 +127,7 @@ namespace std ...@@ -121,7 +127,7 @@ namespace std
// concept requirements // concept requirements
__glibcxx_function_requires(_SGIAssignableConcept<_Tp>) __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
_Tp __tmp = __a; const _Tp __tmp = __a;
__a = __b; __a = __b;
__b = __tmp; __b = __tmp;
} }
...@@ -146,7 +152,9 @@ namespace std ...@@ -146,7 +152,9 @@ namespace std
// concept requirements // concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>) __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
//return __b < __a ? __b : __a; //return __b < __a ? __b : __a;
if (__b < __a) return __b; return __a; if (__b < __a)
return __b;
return __a;
} }
/** /**
...@@ -166,7 +174,9 @@ namespace std ...@@ -166,7 +174,9 @@ namespace std
// concept requirements // concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>) __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
//return __a < __b ? __b : __a; //return __a < __b ? __b : __a;
if (__a < __b) return __b; return __a; if (__a < __b)
return __b;
return __a;
} }
/** /**
...@@ -184,7 +194,9 @@ namespace std ...@@ -184,7 +194,9 @@ namespace std
min(const _Tp& __a, const _Tp& __b, _Compare __comp) min(const _Tp& __a, const _Tp& __b, _Compare __comp)
{ {
//return __comp(__b, __a) ? __b : __a; //return __comp(__b, __a) ? __b : __a;
if (__comp(__b, __a)) return __b; return __a; if (__comp(__b, __a))
return __b;
return __a;
} }
/** /**
...@@ -202,7 +214,9 @@ namespace std ...@@ -202,7 +214,9 @@ namespace std
max(const _Tp& __a, const _Tp& __b, _Compare __comp) max(const _Tp& __a, const _Tp& __b, _Compare __comp)
{ {
//return __comp(__a, __b) ? __b : __a; //return __comp(__a, __b) ? __b : __a;
if (__comp(__a, __b)) return __b; return __a; if (__comp(__a, __b))
return __b;
return __a;
} }
// All of these auxiliary functions serve two purposes. (1) Replace // All of these auxiliary functions serve two purposes. (1) Replace
...@@ -249,13 +263,15 @@ namespace std ...@@ -249,13 +263,15 @@ namespace std
inline _OutputIterator inline _OutputIterator
__copy_aux2(_InputIterator __first, _InputIterator __last, __copy_aux2(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, __false_type) _OutputIterator __result, __false_type)
{ return std::__copy(__first, __last, __result, std::__iterator_category(__first)); } { return std::__copy(__first, __last, __result,
std::__iterator_category(__first)); }
template<typename _InputIterator, typename _OutputIterator> template<typename _InputIterator, typename _OutputIterator>
inline _OutputIterator inline _OutputIterator
__copy_aux2(_InputIterator __first, _InputIterator __last, __copy_aux2(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, __true_type) _OutputIterator __result, __true_type)
{ return std::__copy(__first, __last, __result, std::__iterator_category(__first)); } { return std::__copy(__first, __last, __result,
std::__iterator_category(__first)); }
template<typename _Tp> template<typename _Tp>
inline _Tp* inline _Tp*
...@@ -274,9 +290,9 @@ namespace std ...@@ -274,9 +290,9 @@ namespace std
_OutputIterator __result, __true_type) _OutputIterator __result, __true_type)
{ {
typedef typename iterator_traits<_InputIterator>::value_type typedef typename iterator_traits<_InputIterator>::value_type
_ValueType; _ValueType;
typedef typename __type_traits<_ValueType>::has_trivial_assignment_operator typedef typename __type_traits<
_Trivial; _ValueType>::has_trivial_assignment_operator _Trivial;
return _OutputIterator(std::__copy_aux2(__first, __last, __result.base(), return _OutputIterator(std::__copy_aux2(__first, __last, __result.base(),
_Trivial())); _Trivial()));
} }
...@@ -287,8 +303,8 @@ namespace std ...@@ -287,8 +303,8 @@ namespace std
_OutputIterator __result, __false_type) _OutputIterator __result, __false_type)
{ {
typedef typename iterator_traits<_InputIterator>::value_type _ValueType; typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
typedef typename __type_traits<_ValueType>::has_trivial_assignment_operator typedef typename __type_traits<
_Trivial; _ValueType>::has_trivial_assignment_operator _Trivial;
return std::__copy_aux2(__first, __last, __result, _Trivial()); return std::__copy_aux2(__first, __last, __result, _Trivial());
} }
...@@ -298,7 +314,8 @@ namespace std ...@@ -298,7 +314,8 @@ namespace std
_OutputIterator __result, __true_type) _OutputIterator __result, __true_type)
{ {
typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal;
return std::__copy_ni2(__first.base(), __last.base(), __result, __Normal()); return std::__copy_ni2(__first.base(), __last.base(),
__result, __Normal());
} }
template<typename _InputIterator, typename _OutputIterator> template<typename _InputIterator, typename _OutputIterator>
...@@ -328,7 +345,8 @@ namespace std ...@@ -328,7 +345,8 @@ namespace std
*/ */
template<typename _InputIterator, typename _OutputIterator> template<typename _InputIterator, typename _OutputIterator>
inline _OutputIterator inline _OutputIterator
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) copy(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
...@@ -342,8 +360,10 @@ namespace std ...@@ -342,8 +360,10 @@ namespace std
template<typename _BidirectionalIterator1, typename _BidirectionalIterator2> template<typename _BidirectionalIterator1, typename _BidirectionalIterator2>
inline _BidirectionalIterator2 inline _BidirectionalIterator2
__copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, __copy_backward(_BidirectionalIterator1 __first,
_BidirectionalIterator2 __result, bidirectional_iterator_tag) _BidirectionalIterator1 __last,
_BidirectionalIterator2 __result,
bidirectional_iterator_tag)
{ {
while (__first != __last) while (__first != __last)
*--__result = *--__last; *--__result = *--__last;
...@@ -373,10 +393,8 @@ namespace std ...@@ -373,10 +393,8 @@ namespace std
static _BidirectionalIterator2 static _BidirectionalIterator2
copy(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, copy(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
_BidirectionalIterator2 __result) _BidirectionalIterator2 __result)
{ { return std::__copy_backward(__first, __last, __result,
return std::__copy_backward(__first, __last, __result, std::__iterator_category(__first)); }
std::__iterator_category(__first));
}
}; };
template<typename _Tp> template<typename _Tp>
...@@ -408,9 +426,10 @@ namespace std ...@@ -408,9 +426,10 @@ namespace std
{ {
typedef typename __type_traits<typename iterator_traits<_BI2>::value_type> typedef typename __type_traits<typename iterator_traits<_BI2>::value_type>
::has_trivial_assignment_operator _Trivial; ::has_trivial_assignment_operator _Trivial;
return std::__copy_backward_dispatch<_BI1, _BI2, _Trivial>::copy(__first, return
__last, std::__copy_backward_dispatch<_BI1, _BI2, _Trivial>::copy(__first,
__result); __last,
__result);
} }
template <typename _BI1, typename _BI2> template <typename _BI1, typename _BI2>
...@@ -432,8 +451,8 @@ namespace std ...@@ -432,8 +451,8 @@ namespace std
{ {
typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal;
return std::__copy_backward_output_normal_iterator(__first.base(), return std::__copy_backward_output_normal_iterator(__first.base(),
__last.base(), __result, __last.base(),
__Normal()); __result, __Normal());
} }
template <typename _BI1, typename _BI2> template <typename _BI1, typename _BI2>
...@@ -442,8 +461,8 @@ namespace std ...@@ -442,8 +461,8 @@ namespace std
_BI2 __result, __false_type) _BI2 __result, __false_type)
{ {
typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal;
return std::__copy_backward_output_normal_iterator(__first, __last, __result, return std::__copy_backward_output_normal_iterator(__first, __last,
__Normal()); __result, __Normal());
} }
/** /**
...@@ -476,8 +495,8 @@ namespace std ...@@ -476,8 +495,8 @@ namespace std
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal; typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal;
return std::__copy_backward_input_normal_iterator(__first, __last, __result, return std::__copy_backward_input_normal_iterator(__first, __last,
__Normal()); __result, __Normal());
} }
...@@ -497,7 +516,8 @@ namespace std ...@@ -497,7 +516,8 @@ namespace std
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<_ForwardIterator>) __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
for ( ; __first != __last; ++__first) for ( ; __first != __last; ++__first)
...@@ -532,7 +552,7 @@ namespace std ...@@ -532,7 +552,7 @@ namespace std
fill(unsigned char* __first, unsigned char* __last, const unsigned char& __c) fill(unsigned char* __first, unsigned char* __last, const unsigned char& __c)
{ {
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
unsigned char __tmp = __c; const unsigned char __tmp = __c;
std::memset(__first, __tmp, __last - __first); std::memset(__first, __tmp, __last - __first);
} }
...@@ -540,7 +560,7 @@ namespace std ...@@ -540,7 +560,7 @@ namespace std
fill(signed char* __first, signed char* __last, const signed char& __c) fill(signed char* __first, signed char* __last, const signed char& __c)
{ {
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
signed char __tmp = __c; const signed char __tmp = __c;
std::memset(__first, static_cast<unsigned char>(__tmp), __last - __first); std::memset(__first, static_cast<unsigned char>(__tmp), __last - __first);
} }
...@@ -548,7 +568,7 @@ namespace std ...@@ -548,7 +568,7 @@ namespace std
fill(char* __first, char* __last, const char& __c) fill(char* __first, char* __last, const char& __c)
{ {
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
char __tmp = __c; const char __tmp = __c;
std::memset(__first, static_cast<unsigned char>(__tmp), __last - __first); std::memset(__first, static_cast<unsigned char>(__tmp), __last - __first);
} }
...@@ -625,7 +645,8 @@ namespace std ...@@ -625,7 +645,8 @@ namespace std
* second iterator points into the second range, and the elements pointed * second iterator points into the second range, and the elements pointed
* to by the iterators are not equal. * to by the iterators are not equal.
*/ */
template<typename _InputIterator1, typename _InputIterator2, typename _BinaryPredicate> template<typename _InputIterator1, typename _InputIterator2,
typename _BinaryPredicate>
pair<_InputIterator1, _InputIterator2> pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _BinaryPredicate __binary_pred) _InputIterator2 __first2, _BinaryPredicate __binary_pred)
...@@ -656,7 +677,8 @@ namespace std ...@@ -656,7 +677,8 @@ namespace std
*/ */
template<typename _InputIterator1, typename _InputIterator2> template<typename _InputIterator1, typename _InputIterator2>
inline bool inline bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2)
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
...@@ -685,7 +707,8 @@ namespace std ...@@ -685,7 +707,8 @@ namespace std
* false depending on whether all of the corresponding elements of the * false depending on whether all of the corresponding elements of the
* ranges are equal. * ranges are equal.
*/ */
template<typename _InputIterator1, typename _InputIterator2, typename _BinaryPredicate> template<typename _InputIterator1, typename _InputIterator2,
typename _BinaryPredicate>
inline bool inline bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __first2,
...@@ -753,7 +776,8 @@ namespace std ...@@ -753,7 +776,8 @@ namespace std
* The same as the four-parameter @c lexigraphical_compare, but uses the * The same as the four-parameter @c lexigraphical_compare, but uses the
* comp parameter instead of @c <. * comp parameter instead of @c <.
*/ */
template<typename _InputIterator1, typename _InputIterator2, typename _Compare> template<typename _InputIterator1, typename _InputIterator2,
typename _Compare>
bool bool
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _InputIterator2 __first2, _InputIterator2 __last2,
...@@ -787,7 +811,8 @@ namespace std ...@@ -787,7 +811,8 @@ namespace std
const size_t __len1 = __last1 - __first1; const size_t __len1 = __last1 - __first1;
const size_t __len2 = __last2 - __first2; const size_t __len2 = __last2 - __first2;
const int __result = std::memcmp(__first1, __first2, std::min(__len1, __len2)); const int __result = std::memcmp(__first1, __first2,
std::min(__len1, __len2));
return __result != 0 ? __result < 0 : __len1 < __len2; return __result != 0 ? __result < 0 : __len1 < __len2;
} }
......
// Heap implementation -*- C++ -*- // Heap implementation -*- C++ -*-
// Copyright (C) 2001 Free Software Foundation, Inc. // Copyright (C) 2001, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -72,12 +72,13 @@ namespace std ...@@ -72,12 +72,13 @@ namespace std
__is_heap(_RandomAccessIterator __first, _Distance __n) __is_heap(_RandomAccessIterator __first, _Distance __n)
{ {
_Distance __parent = 0; _Distance __parent = 0;
for (_Distance __child = 1; __child < __n; ++__child) { for (_Distance __child = 1; __child < __n; ++__child)
if (__first[__parent] < __first[__child]) {
return false; if (__first[__parent] < __first[__child])
if ((__child & 1) == 0) return false;
++__parent; if ((__child & 1) == 0)
} ++__parent;
}
return true; return true;
} }
...@@ -88,12 +89,13 @@ namespace std ...@@ -88,12 +89,13 @@ namespace std
_Distance __n) _Distance __n)
{ {
_Distance __parent = 0; _Distance __parent = 0;
for (_Distance __child = 1; __child < __n; ++__child) { for (_Distance __child = 1; __child < __n; ++__child)
if (__comp(__first[__parent], __first[__child])) {
return false; if (__comp(__first[__parent], __first[__child]))
if ((__child & 1) == 0) return false;
++__parent; if ((__child & 1) == 0)
} ++__parent;
}
return true; return true;
} }
...@@ -116,11 +118,12 @@ namespace std ...@@ -116,11 +118,12 @@ namespace std
_Distance __holeIndex, _Distance __topIndex, _Tp __value) _Distance __holeIndex, _Distance __topIndex, _Tp __value)
{ {
_Distance __parent = (__holeIndex - 1) / 2; _Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && *(__first + __parent) < __value) { while (__holeIndex > __topIndex && *(__first + __parent) < __value)
*(__first + __holeIndex) = *(__first + __parent); {
__holeIndex = __parent; *(__first + __holeIndex) = *(__first + __parent);
__parent = (__holeIndex - 1) / 2; __holeIndex = __parent;
} __parent = (__holeIndex - 1) / 2;
}
*(__first + __holeIndex) = __value; *(__first + __holeIndex) = __value;
} }
...@@ -149,8 +152,8 @@ namespace std ...@@ -149,8 +152,8 @@ namespace std
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
// __glibcxx_requires_heap(__first, __last - 1); // __glibcxx_requires_heap(__first, __last - 1);
std::__push_heap(__first, _DistanceType((__last - __first) - 1), _DistanceType(0), std::__push_heap(__first, _DistanceType((__last - __first) - 1),
_ValueType(*(__last - 1))); _DistanceType(0), _ValueType(*(__last - 1)));
} }
template<typename _RandomAccessIterator, typename _Distance, typename _Tp, template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
...@@ -160,11 +163,13 @@ namespace std ...@@ -160,11 +163,13 @@ namespace std
_Distance __topIndex, _Tp __value, _Compare __comp) _Distance __topIndex, _Tp __value, _Compare __comp)
{ {
_Distance __parent = (__holeIndex - 1) / 2; _Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && __comp(*(__first + __parent), __value)) { while (__holeIndex > __topIndex
*(__first + __holeIndex) = *(__first + __parent); && __comp(*(__first + __parent), __value))
__holeIndex = __parent; {
__parent = (__holeIndex - 1) / 2; *(__first + __holeIndex) = *(__first + __parent);
} __holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(__first + __holeIndex) = __value; *(__first + __holeIndex) = __value;
} }
...@@ -195,8 +200,8 @@ namespace std ...@@ -195,8 +200,8 @@ namespace std
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last - 1, __comp); __glibcxx_requires_heap_pred(__first, __last - 1, __comp);
std::__push_heap(__first, _DistanceType((__last - __first) - 1), _DistanceType(0), std::__push_heap(__first, _DistanceType((__last - __first) - 1),
_ValueType(*(__last - 1)), __comp); _DistanceType(0), _ValueType(*(__last - 1)), __comp);
} }
template<typename _RandomAccessIterator, typename _Distance, typename _Tp> template<typename _RandomAccessIterator, typename _Distance, typename _Tp>
...@@ -204,19 +209,21 @@ namespace std ...@@ -204,19 +209,21 @@ namespace std
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex, __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __value) _Distance __len, _Tp __value)
{ {
_Distance __topIndex = __holeIndex; const _Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2; _Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) { while (__secondChild < __len)
if (*(__first + __secondChild) < *(__first + (__secondChild - 1))) {
__secondChild--; if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
*(__first + __holeIndex) = *(__first + __secondChild); __secondChild--;
__holeIndex = __secondChild; *(__first + __holeIndex) = *(__first + __secondChild);
__secondChild = 2 * (__secondChild + 1); __holeIndex = __secondChild;
} __secondChild = 2 * (__secondChild + 1);
if (__secondChild == __len) { }
*(__first + __holeIndex) = *(__first + (__secondChild - 1)); if (__secondChild == __len)
__holeIndex = __secondChild - 1; {
} *(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
std::__push_heap(__first, __holeIndex, __topIndex, __value); std::__push_heap(__first, __holeIndex, __topIndex, __value);
} }
...@@ -225,9 +232,11 @@ namespace std ...@@ -225,9 +232,11 @@ namespace std
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value) _RandomAccessIterator __result, _Tp __value)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::difference_type _Distance; typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
*__result = *__first; *__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first), __value); std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__value);
} }
/** /**
...@@ -243,7 +252,8 @@ namespace std ...@@ -243,7 +252,8 @@ namespace std
inline void inline void
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType; typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
// concept requirements // concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
...@@ -252,7 +262,8 @@ namespace std ...@@ -252,7 +262,8 @@ namespace std
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap(__first, __last); __glibcxx_requires_heap(__first, __last);
std::__pop_heap(__first, __last - 1, __last - 1, _ValueType(*(__last - 1))); std::__pop_heap(__first, __last - 1, __last - 1,
_ValueType(*(__last - 1)));
} }
template<typename _RandomAccessIterator, typename _Distance, template<typename _RandomAccessIterator, typename _Distance,
...@@ -261,19 +272,22 @@ namespace std ...@@ -261,19 +272,22 @@ namespace std
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex, __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __value, _Compare __comp) _Distance __len, _Tp __value, _Compare __comp)
{ {
_Distance __topIndex = __holeIndex; const _Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2; _Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) { while (__secondChild < __len)
if (__comp(*(__first + __secondChild), *(__first + (__secondChild - 1)))) {
__secondChild--; if (__comp(*(__first + __secondChild),
*(__first + __holeIndex) = *(__first + __secondChild); *(__first + (__secondChild - 1))))
__holeIndex = __secondChild; __secondChild--;
__secondChild = 2 * (__secondChild + 1); *(__first + __holeIndex) = *(__first + __secondChild);
} __holeIndex = __secondChild;
if (__secondChild == __len) { __secondChild = 2 * (__secondChild + 1);
*(__first + __holeIndex) = *(__first + (__secondChild - 1)); }
__holeIndex = __secondChild - 1; if (__secondChild == __len)
} {
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
std::__push_heap(__first, __holeIndex, __topIndex, __value, __comp); std::__push_heap(__first, __holeIndex, __topIndex, __value, __comp);
} }
...@@ -282,9 +296,10 @@ namespace std ...@@ -282,9 +296,10 @@ namespace std
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value, _Compare __comp) _RandomAccessIterator __result, _Tp __value, _Compare __comp)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::difference_type _Distance; typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
*__result = *__first; *__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first), std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__value, __comp); __value, __comp);
} }
...@@ -310,8 +325,10 @@ namespace std ...@@ -310,8 +325,10 @@ namespace std
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last, __comp); __glibcxx_requires_heap_pred(__first, __last, __comp);
typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType; typedef typename iterator_traits<_RandomAccessIterator>::value_type
std::__pop_heap(__first, __last - 1, __last - 1, _ValueType(*(__last - 1)), __comp); _ValueType;
std::__pop_heap(__first, __last - 1, __last - 1,
_ValueType(*(__last - 1)), __comp);
} }
/** /**
...@@ -337,15 +354,19 @@ namespace std ...@@ -337,15 +354,19 @@ namespace std
__glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
if (__last - __first < 2) return; if (__last - __first < 2)
_DistanceType __len = __last - __first; return;
_DistanceType __parent = (__len - 2)/2;
const _DistanceType __len = __last - __first;
while (true) { _DistanceType __parent = (__len - 2) / 2;
std::__adjust_heap(__first, __parent, __len, _ValueType(*(__first + __parent))); while (true)
if (__parent == 0) return; {
__parent--; std::__adjust_heap(__first, __parent, __len,
} _ValueType(*(__first + __parent)));
if (__parent == 0)
return;
__parent--;
}
} }
/** /**
...@@ -373,16 +394,19 @@ namespace std ...@@ -373,16 +394,19 @@ namespace std
_RandomAccessIterator>) _RandomAccessIterator>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
if (__last - __first < 2) return; if (__last - __first < 2)
_DistanceType __len = __last - __first; return;
_DistanceType __parent = (__len - 2)/2;
const _DistanceType __len = __last - __first;
while (true) { _DistanceType __parent = (__len - 2) / 2;
std::__adjust_heap(__first, __parent, __len, while (true)
_ValueType(*(__first + __parent)), __comp); {
if (__parent == 0) return; std::__adjust_heap(__first, __parent, __len,
__parent--; _ValueType(*(__first + __parent)), __comp);
} if (__parent == 0)
return;
__parent--;
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment