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>
* 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: Fix two comments.
......
// 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
// software; you can redistribute it and/or modify it under the
......@@ -72,7 +72,8 @@ namespace std
__is_heap(_RandomAccessIterator __first, _Distance __n)
{
_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 ((__child & 1) == 0)
......@@ -88,7 +89,8 @@ namespace std
_Distance __n)
{
_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 ((__child & 1) == 0)
......@@ -116,7 +118,8 @@ namespace std
_Distance __holeIndex, _Distance __topIndex, _Tp __value)
{
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && *(__first + __parent) < __value) {
while (__holeIndex > __topIndex && *(__first + __parent) < __value)
{
*(__first + __holeIndex) = *(__first + __parent);
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
......@@ -149,8 +152,8 @@ namespace std
__glibcxx_requires_valid_range(__first, __last);
// __glibcxx_requires_heap(__first, __last - 1);
std::__push_heap(__first, _DistanceType((__last - __first) - 1), _DistanceType(0),
_ValueType(*(__last - 1)));
std::__push_heap(__first, _DistanceType((__last - __first) - 1),
_DistanceType(0), _ValueType(*(__last - 1)));
}
template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
......@@ -160,7 +163,9 @@ namespace std
_Distance __topIndex, _Tp __value, _Compare __comp)
{
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && __comp(*(__first + __parent), __value)) {
while (__holeIndex > __topIndex
&& __comp(*(__first + __parent), __value))
{
*(__first + __holeIndex) = *(__first + __parent);
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
......@@ -195,8 +200,8 @@ namespace std
__glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last - 1, __comp);
std::__push_heap(__first, _DistanceType((__last - __first) - 1), _DistanceType(0),
_ValueType(*(__last - 1)), __comp);
std::__push_heap(__first, _DistanceType((__last - __first) - 1),
_DistanceType(0), _ValueType(*(__last - 1)), __comp);
}
template<typename _RandomAccessIterator, typename _Distance, typename _Tp>
......@@ -204,16 +209,18 @@ namespace std
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __value)
{
_Distance __topIndex = __holeIndex;
const _Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) {
while (__secondChild < __len)
{
if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
__holeIndex = __secondChild;
__secondChild = 2 * (__secondChild + 1);
}
if (__secondChild == __len) {
if (__secondChild == __len)
{
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
......@@ -225,9 +232,11 @@ namespace std
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type _Distance;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
*__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
inline void
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType;
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
// concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
......@@ -252,7 +262,8 @@ namespace std
__glibcxx_requires_valid_range(__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,
......@@ -261,16 +272,19 @@ namespace std
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __value, _Compare __comp)
{
_Distance __topIndex = __holeIndex;
const _Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) {
if (__comp(*(__first + __secondChild), *(__first + (__secondChild - 1))))
while (__secondChild < __len)
{
if (__comp(*(__first + __secondChild),
*(__first + (__secondChild - 1))))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
__holeIndex = __secondChild;
__secondChild = 2 * (__secondChild + 1);
}
if (__secondChild == __len) {
if (__secondChild == __len)
{
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
......@@ -282,7 +296,8 @@ namespace std
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __value, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type _Distance;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type
_Distance;
*__result = *__first;
std::__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__value, __comp);
......@@ -310,8 +325,10 @@ namespace std
__glibcxx_requires_valid_range(__first, __last);
__glibcxx_requires_heap_pred(__first, __last, __comp);
typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType;
std::__pop_heap(__first, __last - 1, __last - 1, _ValueType(*(__last - 1)), __comp);
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
std::__pop_heap(__first, __last - 1, __last - 1,
_ValueType(*(__last - 1)), __comp);
}
/**
......@@ -337,13 +354,17 @@ namespace std
__glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
__glibcxx_requires_valid_range(__first, __last);
if (__last - __first < 2) return;
_DistanceType __len = __last - __first;
_DistanceType __parent = (__len - 2)/2;
if (__last - __first < 2)
return;
while (true) {
std::__adjust_heap(__first, __parent, __len, _ValueType(*(__first + __parent)));
if (__parent == 0) return;
const _DistanceType __len = __last - __first;
_DistanceType __parent = (__len - 2) / 2;
while (true)
{
std::__adjust_heap(__first, __parent, __len,
_ValueType(*(__first + __parent)));
if (__parent == 0)
return;
__parent--;
}
}
......@@ -373,14 +394,17 @@ namespace std
_RandomAccessIterator>)
__glibcxx_requires_valid_range(__first, __last);
if (__last - __first < 2) return;
_DistanceType __len = __last - __first;
_DistanceType __parent = (__len - 2)/2;
if (__last - __first < 2)
return;
while (true) {
const _DistanceType __len = __last - __first;
_DistanceType __parent = (__len - 2) / 2;
while (true)
{
std::__adjust_heap(__first, __parent, __len,
_ValueType(*(__first + __parent)), __comp);
if (__parent == 0) return;
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