STXXL  1.4-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity > Class Template Reference

Detailed Description

template<class ValueType, class CompareType, unsigned MaxArity>
class stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >

Loser tree from Knuth, "Sorting and Searching", Section 5.4.1.

Parameters
MaxAritymaximum arity of loser tree, has to be a power of two
Template Parameters
Aritymaximum arity of merger, does not need to be a power of 2

Definition at line 38 of file pq_losertree.h.

+ Inheritance diagram for stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >:
+ Collaboration diagram for stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >:

Classes

struct  Entry
 type of nodes in the loser tree More...
 

Public Types

enum  { max_arity = MaxArity }
 
enum  { arity = Arity, max_arity = MaxArity }
 
typedef ArraysType arrays_type
 type of arrays container linked with loser tree More...
 
typedef CompareType comparator_type
 
typedef CompareType compare_type
 comparator object type More...
 
typedef value_type Element
 
typedef arrays_type::sequence_type sequence_type
 type of the ordered sequences in the arrays container More...
 
typedef ValueType value_type
 
typedef arrays_type::value_type value_type
 type of values stored in the arrays container More...
 

Public Member Functions

 loser_tree ()
 
 loser_tree (const compare_type &c, arrays_type &a)
 
 ~loser_tree ()
 
void compact_tree ()
 compact nonempty segments in the left half of the tree More...
 
void double_k ()
 make the tree twice as wide More...
 
void free_player (unsigned_type slot)
 Free a finished player's slot. More...
 
void init ()
 
unsigned_type init_winner (unsigned_type root)
 
void initialize ()
 
void insert_segment (Element *target, unsigned_type length)
 insert segment beginning at target More...
 
bool is_sentinel (const Element &a)
 
bool is_sentinel (const value_type &a) const
 True if a is the sentinel value. More...
 
bool is_space_available () const
 
bool is_space_available () const
 Whether there is still space for new array. More...
 
void maybe_compact ()
 compact tree if it got considerably smaller More...
 
unsigned_type mem_cons () const
 
void multi_merge (Element *begin, Element *end)
 
void multi_merge (Element *, unsigned_type length)
 
template<class OutputIterator >
void multi_merge (OutputIterator begin, OutputIterator end)
 extract the (length = end - begin) smallest elements and write them to [begin..end) empty segments are deallocated. Requires: there are at least length elements and segments are ended by sentinels. More...
 
template<int LogK, typename OutputIterator >
void multi_merge_f (OutputIterator begin, OutputIterator end)
 
template<class OutputIterator >
void multi_merge_k (OutputIterator begin, OutputIterator end)
 multi-merge for arbitrary K More...
 
unsigned_type new_player ()
 Allocate a free slot for a new player. More...
 
bool not_sentinel (const Element &a)
 
void rebuild_loser_tree ()
 rebuild loser tree information from the values in current More...
 
unsigned_type size () const
 
void swap (loser_tree &obj)
 
void swap (loser_tree &obj)
 
void update_on_insert (unsigned_type node, const value_type &newKey, unsigned_type newIndex, value_type *winner_key, unsigned_type *winner_index, unsigned_type *mask)
 Update loser tree on insert or decrement of player index first go up the tree all the way to the root hand down old winner for the respective subtree based on new value, and old winner and loser update each node on the path to the root top down. More...
 
void update_on_insert (unsigned_type node, const value_type &newKey, unsigned_type newIndex)
 Initial call to recursive update_on_insert. More...
 

Public Attributes

compare_type cmp
 the comparator object More...
 

Protected Attributes

arrays_typearrays
 reference to the linked arrays More...
 
struct Entry entry [max_arity]
 levels of loser tree: entry[0] contains the winner info More...
 
internal_bounded_stack
< unsigned_type, arity
free_slots
 stack of free player indices More...
 

Private Member Functions

void compactTree ()
 
void deallocate_segment (unsigned_type slot)
 
void doubleK ()
 
unsigned_type initWinner (unsigned_type root)
 
bool is_segment_empty (unsigned_type slot)
 
void multi_merge_k (Element *target, unsigned_type length)
 
void rebuildLoserTree ()
 
void update_on_insert (unsigned_type node, const Element &newKey, unsigned_type newIndex, Element *winnerKey, unsigned_type *winnerIndex, unsigned_type *mask)
 
- Private Member Functions inherited from stxxl::noncopyable
 noncopyable ()
 

Private Attributes

comparator_type cmp
 
Elementcurrent [MaxArity]
 
Elementcurrent_end [MaxArity]
 
internal_bounded_stack
< unsigned_type, MaxArity > 
free_slots
 
unsigned_type k
 current tree size, invariant (k == 1 << logK), always a power of two More...
 
unsigned_type logK
 log of current tree size More...
 
unsigned_type mem_cons_
 
Elementsegment [MaxArity]
 
unsigned_type segment_size [MaxArity]
 
Element sentinel
 
unsigned_type size_
 

Member Typedef Documentation

template<class ValueType, class CompareType, unsigned MaxArity>
typedef ArraysType stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::arrays_type

type of arrays container linked with loser tree

Definition at line 255 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
typedef CompareType stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::comparator_type

Definition at line 42 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
typedef CompareType stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::compare_type

comparator object type

Definition at line 257 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
typedef value_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::Element

Definition at line 43 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
typedef arrays_type::sequence_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::sequence_type

type of the ordered sequences in the arrays container

Definition at line 265 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
typedef ValueType stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::value_type

Definition at line 41 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
typedef arrays_type::value_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::value_type

type of values stored in the arrays container

Definition at line 263 of file pq_mergers.h.

Member Enumeration Documentation

template<class ValueType, class CompareType, unsigned MaxArity>
anonymous enum
Enumerator
max_arity 

Definition at line 44 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
anonymous enum
Enumerator
arity 
max_arity 

Definition at line 260 of file pq_mergers.h.

Constructor & Destructor Documentation

template<class ValueType , class CompareType , unsigned MaxArity>
stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::~loser_tree ( )

Definition at line 466 of file pq_losertree.h.

References STXXL_VERBOSE1, and STXXL_VERBOSE2.

template<class ValueType, class CompareType, unsigned MaxArity>
stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree ( const compare_type c,
arrays_type a 
)
inline

Definition at line 298 of file pq_mergers.h.

Member Function Documentation

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::compact_tree ( )
inline

compact nonempty segments in the left half of the tree

Definition at line 489 of file pq_mergers.h.

template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::compactTree ( )
private

Definition at line 363 of file pq_losertree.h.

References sentinel, and STXXL_VERBOSE3.

template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::deallocate_segment ( unsigned_type  slot)
private

Definition at line 485 of file pq_losertree.h.

References sentinel, and STXXL_VERBOSE2.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::double_k ( )
inline

make the tree twice as wide

Definition at line 461 of file pq_mergers.h.

template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::doubleK ( )
private

Definition at line 333 of file pq_losertree.h.

References sentinel, and STXXL_VERBOSE3.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::free_player ( unsigned_type  slot)
inline

Free a finished player's slot.

Definition at line 338 of file pq_mergers.h.

Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::free_array().

template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::init ( )
template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::init_winner ( unsigned_type  root)
inline

Definition at line 363 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::initialize ( )
inline
template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::initWinner ( unsigned_type  root)
private
template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::insert_segment ( Element target,
unsigned_type  length 
)

insert segment beginning at target

Definition at line 420 of file pq_losertree.h.

References STXXL_VERBOSE2.

template<class ValueType , class CompareType , unsigned MaxArity>
bool stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::is_segment_empty ( unsigned_type  slot)
inlineprivate

Definition at line 689 of file pq_losertree.h.

References sentinel.

template<class ValueType, class CompareType, unsigned MaxArity>
bool stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::is_sentinel ( const Element a)
inline
template<class ValueType, class CompareType, unsigned MaxArity>
bool stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::is_sentinel ( const value_type a) const
inline

True if a is the sentinel value.

Definition at line 316 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
bool stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::is_space_available ( ) const
inline
template<class ValueType, class CompareType, unsigned MaxArity>
bool stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::is_space_available ( ) const
inline

Whether there is still space for new array.

Definition at line 345 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::maybe_compact ( )
inline

compact tree if it got considerably smaller

Definition at line 546 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::mem_cons ( ) const
inline

Definition at line 196 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge ( Element begin,
Element end 
)
inline
template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge ( Element target,
unsigned_type  length 
)
template<class ValueType, class CompareType, unsigned MaxArity>
template<class OutputIterator >
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge ( OutputIterator  begin,
OutputIterator  end 
)
inline

extract the (length = end - begin) smallest elements and write them to [begin..end) empty segments are deallocated. Requires: there are at least length elements and segments are ended by sentinels.

Definition at line 667 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
template<int LogK, typename OutputIterator >
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge_f ( OutputIterator  begin,
OutputIterator  end 
)
inline

Definition at line 613 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge_k ( Element target,
unsigned_type  length 
)
private
template<class ValueType, class CompareType, unsigned MaxArity>
template<class OutputIterator >
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge_k ( OutputIterator  begin,
OutputIterator  end 
)
inline

multi-merge for arbitrary K

Definition at line 571 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::new_player ( )
inline

Allocate a free slot for a new player.

Definition at line 322 of file pq_mergers.h.

Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::append_merger().

template<class ValueType, class CompareType, unsigned MaxArity>
bool stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::not_sentinel ( const Element a)
inline

Definition at line 162 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::rebuild_loser_tree ( )
inline

rebuild loser tree information from the values in current

Definition at line 351 of file pq_mergers.h.

template<class ValueType , class CompareType , unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::rebuildLoserTree ( )
private

Definition at line 236 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::size ( ) const
inline

Definition at line 206 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::swap ( loser_tree< ValueType, CompareType, MaxArity > &  obj)
inline

Definition at line 172 of file pq_losertree.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::swap ( loser_tree< ValueType, CompareType, MaxArity > &  obj)
inline

Definition at line 765 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::update_on_insert ( unsigned_type  node,
const Element newKey,
unsigned_type  newIndex,
Element winnerKey,
unsigned_type winnerIndex,
unsigned_type mask 
)
private
template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::update_on_insert ( unsigned_type  node,
const value_type newKey,
unsigned_type  newIndex,
value_type winner_key,
unsigned_type winner_index,
unsigned_type mask 
)
inline

Update loser tree on insert or decrement of player index first go up the tree all the way to the root hand down old winner for the respective subtree based on new value, and old winner and loser update each node on the path to the root top down.

This is implemented recursively

Definition at line 399 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::update_on_insert ( unsigned_type  node,
const value_type newKey,
unsigned_type  newIndex 
)
inline

Initial call to recursive update_on_insert.

Definition at line 451 of file pq_mergers.h.

Member Data Documentation

template<class ValueType, class CompareType, unsigned MaxArity>
arrays_type& stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::arrays
protected

reference to the linked arrays

Definition at line 282 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
compare_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::cmp

the comparator object

Definition at line 269 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
Element* stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::current[MaxArity]
private
template<class ValueType, class CompareType, unsigned MaxArity>
Element* stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::current_end[MaxArity]
private
template<class ValueType, class CompareType, unsigned MaxArity>
struct Entry stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::entry[max_arity]
protected

levels of loser tree: entry[0] contains the winner info

Definition at line 292 of file pq_mergers.h.

Referenced by stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().

template<class ValueType, class CompareType, unsigned MaxArity>
internal_bounded_stack<unsigned_type, MaxArity> stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::free_slots
private
template<class ValueType, class CompareType, unsigned MaxArity>
internal_bounded_stack<unsigned_type, arity> stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::free_slots
protected

stack of free player indices

Definition at line 295 of file pq_mergers.h.

template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::k
private
template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::logK
private

log of current tree size

Definition at line 60 of file pq_losertree.h.

Referenced by stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().

template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::mem_cons_
private
template<class ValueType, class CompareType, unsigned MaxArity>
Element* stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::segment[MaxArity]
private
template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::segment_size[MaxArity]
private
template<class ValueType, class CompareType, unsigned MaxArity>
Element stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::sentinel
private
template<class ValueType, class CompareType, unsigned MaxArity>
unsigned_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::size_
private

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