STXXL
1.4-dev
|
Loser tree from Knuth, "Sorting and Searching", Section 5.4.1.
MaxArity | maximum arity of loser tree, has to be a power of two |
Arity | maximum arity of merger, does not need to be a power of 2 |
Definition at line 38 of file pq_losertree.h.
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_type & | arrays |
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 |
Element * | current [MaxArity] |
Element * | current_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_ |
Element * | segment [MaxArity] |
unsigned_type | segment_size [MaxArity] |
Element | sentinel |
unsigned_type | size_ |
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.
typedef CompareType stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::comparator_type |
Definition at line 42 of file pq_losertree.h.
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.
typedef value_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::Element |
Definition at line 43 of file pq_losertree.h.
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.
typedef ValueType stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::value_type |
Definition at line 41 of file pq_losertree.h.
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.
anonymous enum |
Enumerator | |
---|---|
max_arity |
Definition at line 44 of file pq_losertree.h.
anonymous enum |
Enumerator | |
---|---|
arity | |
max_arity |
Definition at line 260 of file pq_mergers.h.
stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree | ( | ) |
Definition at line 211 of file pq_losertree.h.
References stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::current, stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::current_end, stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::free_slots, stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::init(), stxxl::priority_queue_local::internal_bounded_stack< ValueType, MaxSize >::push(), stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::segment, and stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::sentinel.
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.
|
inline |
Definition at line 298 of file pq_mergers.h.
|
inline |
compact nonempty segments in the left half of the tree
Definition at line 489 of file pq_mergers.h.
|
private |
Definition at line 363 of file pq_losertree.h.
References sentinel, and STXXL_VERBOSE3.
|
private |
Definition at line 485 of file pq_losertree.h.
References sentinel, and STXXL_VERBOSE2.
|
inline |
make the tree twice as wide
Definition at line 461 of file pq_mergers.h.
|
private |
Definition at line 333 of file pq_losertree.h.
References sentinel, and STXXL_VERBOSE3.
|
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().
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::init | ( | ) |
Definition at line 224 of file pq_losertree.h.
References sentinel.
Referenced by stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree().
|
inline |
Definition at line 363 of file pq_mergers.h.
|
inline |
Definition at line 305 of file pq_mergers.h.
Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::ext_merger().
|
private |
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.
|
inlineprivate |
Definition at line 689 of file pq_losertree.h.
References sentinel.
|
inline |
Definition at line 158 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::is_sentinel().
|
inline |
True if a is the sentinel value.
Definition at line 316 of file pq_mergers.h.
|
inline |
Definition at line 198 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::is_space_available().
|
inline |
Whether there is still space for new array.
Definition at line 345 of file pq_mergers.h.
|
inline |
compact tree if it got considerably smaller
Definition at line 546 of file pq_mergers.h.
|
inline |
Definition at line 196 of file pq_losertree.h.
|
inline |
Definition at line 190 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::multi_merge().
void stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::multi_merge | ( | Element * | target, |
unsigned_type | length | ||
) |
Definition at line 510 of file pq_losertree.h.
References stxxl::priority_queue_local::merge3_iterator(), stxxl::priority_queue_local::merge4_iterator(), stxxl::potentially_parallel::multiway_merge_sentinels(), and STXXL_VERBOSE3.
|
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.
|
inline |
Definition at line 613 of file pq_mergers.h.
|
private |
|
inline |
multi-merge for arbitrary K
Definition at line 571 of file pq_mergers.h.
|
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().
|
inline |
Definition at line 162 of file pq_losertree.h.
|
inline |
rebuild loser tree information from the values in current
Definition at line 351 of file pq_mergers.h.
|
private |
Definition at line 236 of file pq_losertree.h.
|
inline |
Definition at line 206 of file pq_losertree.h.
|
inline |
Definition at line 172 of file pq_losertree.h.
|
inline |
Definition at line 765 of file pq_mergers.h.
|
private |
|
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.
|
inline |
Initial call to recursive update_on_insert.
Definition at line 451 of file pq_mergers.h.
|
protected |
reference to the linked arrays
Definition at line 282 of file pq_mergers.h.
|
private |
Definition at line 55 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::append_merger(), stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::init(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
compare_type stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::cmp |
the comparator object
Definition at line 269 of file pq_mergers.h.
|
private |
Definition at line 74 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
private |
Definition at line 75 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
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().
|
private |
Definition at line 57 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
protected |
stack of free player indices
Definition at line 295 of file pq_mergers.h.
|
private |
current tree size, invariant (k == 1 << logK), always a power of two
Definition at line 61 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::append_merger(), stxxl::priority_queue_local::ext_merger< BlockType, CompareType, Arity, AllocStr >::prefetch_arrays(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
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().
|
private |
Definition at line 79 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
private |
Definition at line 76 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
private |
Definition at line 77 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
private |
Definition at line 63 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< ValueType, CompareType, MaxArity >::loser_tree(), and stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().
|
private |
Definition at line 59 of file pq_losertree.h.
Referenced by stxxl::priority_queue_local::loser_tree< self_type, CompareType, MaxArity >::swap().