MeVisLab Toolbox Reference
ml::WEMHeap< T > Class Template Reference

Min-Heap structure with property v[i]<v[2*i+1] and v[i]<v[2*i+2] Parent at index i has children at indices 2*i+1 and 2*i+2 Smallest values are stored closer to root of tree. More...

#include <WEMHeap.h>

Inheritance diagram for ml::WEMHeap< T >:
ml::WEMVector< WEMPrimitive >

Public Member Functions

 WEMHeap ()
 Standard constructor.
 
 WEMHeap (WEMHeap &&) noexcept=default
 
WEMHeapoperator= (WEMHeap &&) noexcept=default
 
 ~WEMHeap () override
 Standard destructor.
 
Troot ()
 Returns the root (first) element of this heap, typecast from WEMPrimitive to T.
 
const Troot () const
 Returns the root (first) element of this heap, typecast from WEMPrimitive to T.
 
void swap (unsigned int i, unsigned int j) override
 Swaps two heap elements given by their indices and resorts this heap.
 
void insert (WEMPrimitive *wp)
 Inserts the given heap element and resorts this heap.
 
void insert (WEMPrimitive *wp, double v)
 Inserts the given heap element and sets its value, and resorts this heap.
 
void update (WEMPrimitive *wp, double nv)
 Updates given heap element with the given value and resorts this heap.
 
int remove (WEMPrimitive *wp) override
 Removes the given heap element and resorts this heap.
 
void sort ()
 Sorts this heap.
 
void clear () override
 Remove all elements from heap.
 
- Public Member Functions inherited from ml::WEMVector< WEMPrimitive >
 WEMVector (unsigned int init=0)
 Standard constructor.
 
 WEMVector (WEMVector &&other) noexcept
 
WEMVectoroperator= (WEMVector &&other) noexcept
 
virtual ~WEMVector ()
 Standard destructor.
 
unsigned int num () const
 Returns the number of elements in this vector.
 
WEMPrimitiveat (unsigned int pos) const
 Returns the element at the given position or returns NULL if out of range.
 
WEMPrimitivefirst ()
 Returns the first element.
 
const WEMPrimitivefirst () const
 Returns the first element.
 
WEMPrimitivelast ()
 Returns the last element.
 
const WEMPrimitivelast () const
 Returns the last element.
 
virtual unsigned int append (WEMPrimitive *elem)
 Appends the given element to back of this vector.
 
virtual void deleteAt (unsigned int pos)
 Deletes the element at the given position.
 
virtual void deleteLast ()
 Deletes the last element of this vector.
 
virtual int remove (WEMPrimitive *elem)
 Deletes the element given by its pointer.
 
virtual int lookup (WEMPrimitive *elem) const
 Searches for the given element in this vector and returns its position.
 
virtual int removeUnSwapped (WEMPrimitive *elem)
 Deletes the element given by its pointer. Keeps the order of the elements!
 
virtual void destroy ()
 Deletes all elements in this vector.
 
virtual void replace (WEMPrimitive *elem, unsigned int pos)
 Replaces the given position with the given element.
 
void reserve (unsigned int init)
 Reserves init elements, copies old ones if existing.
 

Additional Inherited Members

- Protected Member Functions inherited from ml::WEMVector< WEMPrimitive >
virtual void expand ()
 Grow vector, add extra block of size BLOCKSIZE.
 
virtual unsigned int appendUnsafe (WEMPrimitive *elem)
 Append element to back of vector, don't check on element being non-NULL.
 

Detailed Description

template<class T>
class ml::WEMHeap< T >

Min-Heap structure with property v[i]<v[2*i+1] and v[i]<v[2*i+2] Parent at index i has children at indices 2*i+1 and 2*i+2 Smallest values are stored closer to root of tree.

Elements are sorted while inserting them in the heap.

Definition at line 28 of file WEMHeap.h.

Constructor & Destructor Documentation

◆ WEMHeap() [1/2]

template<class T >
ml::WEMHeap< T >::WEMHeap ( )

Standard constructor.

Definition at line 75 of file WEMHeap.h.

◆ WEMHeap() [2/2]

template<class T >
ml::WEMHeap< T >::WEMHeap ( WEMHeap< T > && )
defaultnoexcept

◆ ~WEMHeap()

template<class T >
ml::WEMHeap< T >::~WEMHeap ( )
override

Standard destructor.

Definition at line 82 of file WEMHeap.h.

Member Function Documentation

◆ clear()

template<class T >
void ml::WEMHeap< T >::clear ( )
overridevirtual

Remove all elements from heap.

Reimplemented from ml::WEMVector< WEMPrimitive >.

Definition at line 278 of file WEMHeap.h.

References ml::WEMVector< T, fixedBufferSize >::clear(), and mlrange_cast().

◆ insert() [1/2]

template<class T >
void ml::WEMHeap< T >::insert ( WEMPrimitive * wp)

Inserts the given heap element and resorts this heap.

Definition at line 124 of file WEMHeap.h.

References ml::WEMVector< T, fixedBufferSize >::appendUnsafe(), and mlrange_cast().

◆ insert() [2/2]

template<class T >
void ml::WEMHeap< T >::insert ( WEMPrimitive * wp,
double v )

Inserts the given heap element and sets its value, and resorts this heap.

Definition at line 138 of file WEMHeap.h.

References ml::WEMVector< T, fixedBufferSize >::appendUnsafe(), and mlrange_cast().

◆ operator=()

template<class T >
WEMHeap & ml::WEMHeap< T >::operator= ( WEMHeap< T > && )
defaultnoexcept

References mlrange_cast().

◆ remove()

template<class T >
int ml::WEMHeap< T >::remove ( WEMPrimitive * wp)
override

Removes the given heap element and resorts this heap.

Definition at line 159 of file WEMHeap.h.

References ml::WEMMinHeapCompare::less(), and mlrange_cast().

◆ root() [1/2]

template<class T >
T * ml::WEMHeap< T >::root ( )

Returns the root (first) element of this heap, typecast from WEMPrimitive to T.

Definition at line 90 of file WEMHeap.h.

References ml::WEMVector< T, fixedBufferSize >::first(), mlrange_cast(), and T.

◆ root() [2/2]

template<class T >
const T * ml::WEMHeap< T >::root ( ) const

Returns the root (first) element of this heap, typecast from WEMPrimitive to T.

Definition at line 106 of file WEMHeap.h.

◆ sort()

template<class T >
void ml::WEMHeap< T >::sort ( )

Sorts this heap.

Definition at line 260 of file WEMHeap.h.

References mlrange_cast().

◆ swap()

template<class T >
void ml::WEMHeap< T >::swap ( unsigned int i,
unsigned int j )
overridevirtual

Swaps two heap elements given by their indices and resorts this heap.

Reimplemented from ml::WEMVector< WEMPrimitive >.

Definition at line 114 of file WEMHeap.h.

References mlrange_cast(), and ml::WEMVector< T, fixedBufferSize >::swap().

◆ update()

template<class T >
void ml::WEMHeap< T >::update ( WEMPrimitive * wp,
double nv )

Updates given heap element with the given value and resorts this heap.

Definition at line 194 of file WEMHeap.h.

References mlrange_cast().


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