STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | List of all members
__gnu_parallel::_LoserTree< __stable, _Tp, _Compare > Class Template Reference

Stable _LoserTree variant. More...

#include <parallel/losertree.h>

Inheritance diagram for __gnu_parallel::_LoserTree< __stable, _Tp, _Compare >:
__gnu_parallel::_LoserTreeBase< _Tp, _Compare >

Public Member Functions

 _LoserTree (unsigned int __k, _Compare __comp)
 
unsigned int __init_winner (unsigned int __root)
 
void __init ()
 
void __delete_min_insert (_Tp __key, bool __sup)
 Delete the smallest element and insert a new element from the previously smallest element's sequence. More...
 
- Public Member Functions inherited from __gnu_parallel::_LoserTreeBase< _Tp, _Compare >
 _LoserTreeBase (unsigned int __k, _Compare __comp)
 The constructor. More...
 
 ~_LoserTreeBase ()
 The destructor. More...
 
void __insert_start (const _Tp &__key, int __source, bool __sup)
 Initializes the sequence "_M_source" with the element "__key". More...
 
int __get_min_source ()
 

Private Types

typedef _LoserTreeBase< _Tp,
_Compare > 
_Base
 

Additional Inherited Members

- Protected Attributes inherited from __gnu_parallel::_LoserTreeBase< _Tp, _Compare >
unsigned int _M_ik
 
unsigned int _M_k
 
unsigned int _M_offset
 
unsigned int _M_log_k
 
_Loser_M_losers
 _LoserTree __elements. More...
 
_Compare _M_comp
 _Compare to use. More...
 
bool _M_first_insert
 State flag that determines whether the _LoserTree is empty. More...
 

Detailed Description

template<bool __stable, typename _Tp, typename _Compare>
class __gnu_parallel::_LoserTree< __stable, _Tp, _Compare >

Stable _LoserTree variant.

Provides the stable implementations of insert_start, __init_winner, __init and __delete_min_insert.

Unstable variant is done using partial specialisation below.

Member Typedef Documentation

template<bool __stable, typename _Tp , typename _Compare >
typedef _LoserTreeBase<_Tp, _Compare> __gnu_parallel::_LoserTree< __stable, _Tp, _Compare >::_Base
private

Constructor & Destructor Documentation

template<bool __stable, typename _Tp , typename _Compare >
__gnu_parallel::_LoserTree< __stable, _Tp, _Compare >::_LoserTree ( unsigned int  __k,
_Compare  __comp 
)
inline
180  : _Base::_LoserTreeBase(__k, __comp)
181  { }
_LoserTreeBase(unsigned int __k, _Compare __comp)
The constructor.
Definition: losertree.h:94

Member Function Documentation

template<bool __stable, typename _Tp , typename _Compare >
void __gnu_parallel::_LoserTree< __stable, _Tp, _Compare >::__delete_min_insert ( _Tp  __key,
bool  __sup 
)
inline

Delete the smallest element and insert a new element from the previously smallest element's sequence.

This implementation is stable.

223  {
224  using std::swap;
225 #if _GLIBCXX_ASSERTIONS
226  // no dummy sequence can ever be at the top!
227  _GLIBCXX_PARALLEL_ASSERT(_M_losers[0]._M_source != -1);
228 #endif
229 
230  int __source = _M_losers[0]._M_source;
231  for (unsigned int __pos = (_M_k + __source) / 2; __pos > 0;
232  __pos /= 2)
233  {
234  // The smaller one gets promoted, ties are broken by _M_source.
235  if ((__sup && (!_M_losers[__pos]._M_sup
236  || _M_losers[__pos]._M_source < __source))
237  || (!__sup && !_M_losers[__pos]._M_sup
238  && ((_M_comp(_M_losers[__pos]._M_key, __key))
239  || (!_M_comp(__key, _M_losers[__pos]._M_key)
240  && _M_losers[__pos]._M_source < __source))))
241  {
242  // The other one is smaller.
243  std::swap(_M_losers[__pos]._M_sup, __sup);
244  std::swap(_M_losers[__pos]._M_source, __source);
245  swap(_M_losers[__pos]._M_key, __key);
246  }
247  }
248 
249  _M_losers[0]._M_sup = __sup;
250  _M_losers[0]._M_source = __source;
251  _M_losers[0]._M_key = __key;
252  }
bool _M_sup
flag, true iff this is a "maximum" __sentinel.
Definition: losertree.h:62
_Loser * _M_losers
_LoserTree __elements.
Definition: losertree.h:75
int _M_source
__index of the __source __sequence.
Definition: losertree.h:64
#define _GLIBCXX_PARALLEL_ASSERT(_Condition)
Definition: base.h:422
_Compare _M_comp
_Compare to use.
Definition: losertree.h:78
unsigned int _M_k
Definition: losertree.h:69
void swap(exception_ptr &__lhs, exception_ptr &__rhs)
Definition: exception_ptr.h:160
_Tp _M_key
_M_key of the element in the _LoserTree.
Definition: losertree.h:66
template<bool __stable, typename _Tp , typename _Compare >
void __gnu_parallel::_LoserTree< __stable, _Tp, _Compare >::__init ( )
inline
211  { _M_losers[0] = _M_losers[__init_winner(1)]; }
_Loser * _M_losers
_LoserTree __elements.
Definition: losertree.h:75
unsigned int __init_winner(unsigned int __root)
Definition: losertree.h:184
template<bool __stable, typename _Tp , typename _Compare >
unsigned int __gnu_parallel::_LoserTree< __stable, _Tp, _Compare >::__init_winner ( unsigned int  __root)
inline
185  {
186  if (__root >= _M_k)
187  return __root;
188  else
189  {
190  unsigned int __left = __init_winner(2 * __root);
191  unsigned int __right = __init_winner(2 * __root + 1);
192  if (_M_losers[__right]._M_sup
193  || (!_M_losers[__left]._M_sup
194  && !_M_comp(_M_losers[__right]._M_key,
195  _M_losers[__left]._M_key)))
196  {
197  // Left one is less or equal.
198  _M_losers[__root] = _M_losers[__right];
199  return __left;
200  }
201  else
202  {
203  // Right one is less.
204  _M_losers[__root] = _M_losers[__left];
205  return __right;
206  }
207  }
208  }
_Loser * _M_losers
_LoserTree __elements.
Definition: losertree.h:75
unsigned int __init_winner(unsigned int __root)
Definition: losertree.h:184
_Compare _M_comp
_Compare to use.
Definition: losertree.h:78
unsigned int _M_k
Definition: losertree.h:69

The documentation for this class was generated from the following file: