Qt 4.8
Public Functions | Static Private Functions | Properties | List of all members
QMaxHeap< T > Class Template Reference

Public Functions

bool empty () const
 
bool isEmpty () const
 
pop ()
 
void push (const T &x)
 
 QMaxHeap ()
 
int size () const
 
const T & top () const
 

Static Private Functions

static int left (int i)
 
static int parent (int i)
 
static int right (int i)
 

Properties

QDataBuffer< T > m_data
 

Detailed Description

template<class T>
class QMaxHeap< T >

Definition at line 532 of file qtriangulator.cpp.

Constructors and Destructors

◆ QMaxHeap()

template<class T>
QMaxHeap< T >::QMaxHeap ( )
inline

Definition at line 535 of file qtriangulator.cpp.

535 : m_data(0) {}
QDataBuffer< T > m_data

Functions

◆ empty()

template<class T>
bool QMaxHeap< T >::empty ( ) const
inline

Definition at line 537 of file qtriangulator.cpp.

537 {return m_data.isEmpty();}
bool isEmpty() const
Definition: qdatabuffer_p.h:81
QDataBuffer< T > m_data

◆ isEmpty()

template<class T>
bool QMaxHeap< T >::isEmpty ( ) const
inline

Definition at line 538 of file qtriangulator.cpp.

538 {return m_data.isEmpty();}
bool isEmpty() const
Definition: qdatabuffer_p.h:81
QDataBuffer< T > m_data

◆ left()

template<class T>
static int QMaxHeap< T >::left ( int  i)
inlinestaticprivate

Definition at line 544 of file qtriangulator.cpp.

Referenced by QMaxHeap< QTriangulator::ComplexToSimple::Intersection >::pop().

544 {return 2 * i + 1;}

◆ parent()

template<class T>
static int QMaxHeap< T >::parent ( int  i)
inlinestaticprivate

Definition at line 543 of file qtriangulator.cpp.

Referenced by QMaxHeap< QTriangulator::ComplexToSimple::Intersection >::push().

543 {return (i - 1) / 2;}

◆ pop()

template<class T >
T QMaxHeap< T >::pop ( )

Definition at line 565 of file qtriangulator.cpp.

566 {
567  T result = m_data.first();
568  T back = m_data.last();
569  m_data.pop_back();
570  if (!m_data.isEmpty()) {
571  int current = 0;
572  for (;;) {
573  int left = QMaxHeap::left(current);
574  int right = QMaxHeap::right(current);
575  if (left >= m_data.size())
576  break;
577  int greater = left;
578  if (right < m_data.size() && m_data.at(left) < m_data.at(right))
579  greater = right;
580  if (m_data.at(greater) < back)
581  break;
582  m_data.at(current) = m_data.at(greater);
583  current = greater;
584  }
585  m_data.at(current) = back;
586  }
587  return result;
588 }
static int right(int i)
bool isEmpty() const
Definition: qdatabuffer_p.h:81
Type & at(int i)
Definition: qdatabuffer_p.h:86
void pop_back()
Definition: qdatabuffer_p.h:99
Type & last()
Definition: qdatabuffer_p.h:88
QDataBuffer< T > m_data
Type & first()
Definition: qdatabuffer_p.h:90
static int left(int i)
int size() const
Definition: qdatabuffer_p.h:83

◆ push()

template<class T>
void QMaxHeap< T >::push ( const T &  x)

Definition at line 551 of file qtriangulator.cpp.

552 {
553  int current = m_data.size();
554  int parent = QMaxHeap::parent(current);
555  m_data.add(x);
556  while (current != 0 && m_data.at(parent) < x) {
557  m_data.at(current) = m_data.at(parent);
558  current = parent;
559  parent = QMaxHeap::parent(current);
560  }
561  m_data.at(current) = x;
562 }
static int parent(int i)
Type & at(int i)
Definition: qdatabuffer_p.h:86
void add(const Type &t)
Definition: qdatabuffer_p.h:93
QDataBuffer< T > m_data
int size() const
Definition: qdatabuffer_p.h:83

◆ right()

template<class T>
static int QMaxHeap< T >::right ( int  i)
inlinestaticprivate

Definition at line 545 of file qtriangulator.cpp.

Referenced by QMaxHeap< QTriangulator::ComplexToSimple::Intersection >::pop().

545 {return 2 * i + 2;}

◆ size()

template<class T>
int QMaxHeap< T >::size ( ) const
inline

Definition at line 536 of file qtriangulator.cpp.

536 {return m_data.size();}
QDataBuffer< T > m_data
int size() const
Definition: qdatabuffer_p.h:83

◆ top()

template<class T>
const T& QMaxHeap< T >::top ( ) const
inline

Definition at line 541 of file qtriangulator.cpp.

541 {return m_data.first();}
QDataBuffer< T > m_data
Type & first()
Definition: qdatabuffer_p.h:90

Properties

◆ m_data

template<class T>
QDataBuffer<T> QMaxHeap< T >::m_data
private

Definition at line 547 of file qtriangulator.cpp.


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