# OpenGraph DrawingFramework

v. 2022.02 (Dogwood)

ogdf::Top10Heap< X, INDEX > Class Template Reference

A variant of BinaryHeapSimple which always holds only the 10 elements with the highest keys. More...

#include <ogdf/basic/MinHeap.h>

Inheritance diagram for ogdf::Top10Heap< X, INDEX >:

## Public Types

enum  PushResult { PushResult::Accepted, PushResult::Rejected, PushResult::Swapped }
The type for results of a Top10Heap::push operation. More...

## Public Member Functions

Top10Heap ()
Constructor generating a heap which holds the 10 elements with highest value ever added to the heap. More...

bool full () const
Returns true if the heap is completely filled (i.e. the next push operation will return something) More...

PushResult insert (X &x, X &out)
Alternative name for push(). More...

void insertBlind (X &x)
Alternative name for pushBlind(). More...

const X & operator[] (INDEX idx) const
obtain const references to the element at index idx More...

PushResult push (X &x, X &out)
Tries to push the element x onto the heap (and may return a removed element as out). More...

void pushBlind (X &x)
Simple (and slightly faster) variant of Top10Heap::push. More...

## Static Public Member Functions

static bool returnedSomething (PushResult r)
Convenience function: Returns true if the PushResults states that push caused an element to be not/no-longer in the heap. More...

static bool successful (PushResult r)
Convenience function: Returns true if the PushResults states that the newly pushed element is new in the heap. More...

Protected Member Functions inherited from ogdf::BinaryHeapSimple< X, int >
int capacity () const
Returns the current array-size of the heap, i.e., the number of elements which can be added before the next resize occurs. More...

void heapdown ()

void heapup (int idx)

BinaryHeapSimple (int size)
Construtor, giving initial array size. More...

void clear ()
empties the heap [O(1)] More...

bool empty () const
Returns true if the heap is empty. More...

extractMin ()
Returns the top (i.e., smallest) element and removed it from the heap [Same as pop(), O(log n)]. More...

const X & getMin () const
Returns a reference to the top (i.e., smallest) element of the heap. It does not remove it. [Same as top(), O(1)]. More...

void insert (X &x)
Adds an element to the heap [Same as push(), O(log n)]. More...

const X & operator[] (int idx) const
obtain const references to the element at index idx (the smallest array index is 0, as for traditional C-arrays) More...

pop ()
Returns the top (i.e., smallest) element and removed it from the heap [Same as extractMin(), O(log n)]. More...

void push (X &x)
Adds an element to the heap [Same as insert(), O(log n)]. More...

int size () const
Returns the number of elements in the heap. More...

const X & top () const
Returns a reference to the top (i.e., smallest) element of the heap. It does not remove it. [Same as getMin(), O(1)]. More...

## Detailed Description

### template<class X, class INDEX = int> class ogdf::Top10Heap< X, INDEX >

A variant of BinaryHeapSimple which always holds only the 10 elements with the highest keys.

It assumes that the data-elements are themselves comparable, i.e., the compare-function of the items implicitly defines the keys.

If your intended datastructure do not directly offer a compare function, but you have certain key-values (scores, etc.), you may want to use the convenience-class Prioritized < Priority,X > to bind both together and use within BinaryHeapSimple.

Definition at line 148 of file MinHeap.h.

## ◆ PushResult

template<class X , class INDEX = int>
 strong

The type for results of a Top10Heap::push operation.

Enumerator
Accepted
Rejected
Swapped

Definition at line 151 of file MinHeap.h.

## ◆ Top10Heap()

template<class X , class INDEX = int>
 ogdf::Top10Heap< X, INDEX >::Top10Heap ( )
inline

Constructor generating a heap which holds the 10 elements with highest value ever added to the heap.

Definition at line 159 of file MinHeap.h.

## ◆ full()

template<class X , class INDEX = int>
 bool ogdf::Top10Heap< X, INDEX >::full ( ) const
inline

Returns true if the heap is completely filled (i.e. the next push operation will return something)

Definition at line 163 of file MinHeap.h.

## ◆ insert()

template<class X , class INDEX = int>
 PushResult ogdf::Top10Heap< X, INDEX >::insert ( X & x, X & out )
inline

Alternative name for push().

Definition at line 202 of file MinHeap.h.

## ◆ insertBlind()

template<class X , class INDEX = int>
 void ogdf::Top10Heap< X, INDEX >::insertBlind ( X & x )
inline

Alternative name for pushBlind().

Definition at line 219 of file MinHeap.h.

## ◆ operator[]()

template<class X , class INDEX = int>
 const X& ogdf::Top10Heap< X, INDEX >::operator[] ( INDEX idx ) const
inline

obtain const references to the element at index idx

The smallest array index is 0, as for traditional C-arrays. Useful, e.g., when iterating through the final heap elements.

Definition at line 228 of file MinHeap.h.

## ◆ push()

template<class X , class INDEX = int>
 PushResult ogdf::Top10Heap< X, INDEX >::push ( X & x, X & out )
inline

Tries to push the element x onto the heap (and may return a removed element as out).

If the heap is not yet completely filled, the pushed element is accepted and added to the heap. The function returns PushResult::Accepted, and the out parameter is not touched.

If the heap is filled and the key of the pushed element is too small to be accepted (i.e. the heap is filled with all larger elements), then the element if rejected: The funtion returns PushResult::Rejected, and the out parameter is set to x.

If the heap is filled and the key of the pushed element is large enough to belong to the top elements, the element is accepted and the currently smallest element in the heap is removed from the heap. The function returns PushResult::Swapped and sets the out parameter to the element removed from the heap.

You may want to use the convenience funtions successful and returnedSomething on the return-value if you are only interested certain aspects of the push.

Definition at line 188 of file MinHeap.h.

## ◆ pushBlind()

template<class X , class INDEX = int>
 void ogdf::Top10Heap< X, INDEX >::pushBlind ( X & x )
inline

Simple (and slightly faster) variant of Top10Heap::push.

The behavior is the identical to Top10Heap::push, but there is nothing reported to the outside

Definition at line 210 of file MinHeap.h.

## ◆ returnedSomething()

template<class X , class INDEX = int>
 static bool ogdf::Top10Heap< X, INDEX >::returnedSomething ( PushResult r )
inlinestatic

Convenience function: Returns true if the PushResults states that push caused an element to be not/no-longer in the heap.

Definition at line 156 of file MinHeap.h.

## ◆ successful()

template<class X , class INDEX = int>
 static bool ogdf::Top10Heap< X, INDEX >::successful ( PushResult r )
inlinestatic

Convenience function: Returns true if the PushResults states that the newly pushed element is new in the heap.

Definition at line 154 of file MinHeap.h.

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