EMAN2
Public Member Functions | Public Attributes | List of all members
EMAN::PriorityQueue< ValueT, KeyT > Class Template Reference

Template class for a priority queue. More...

#include <priority_queue.h>

Public Member Functions

 PriorityQueue (int max)
 Constructor. More...
 
 ~PriorityQueue ()
 Destructor. More...
 
int getLength ()
 Get current length. More...
 
bool isEmpty ()
 Test whether empty. More...
 
bool isFull ()
 Test whether full. More...
 
void add (ValueT *v, KeyT k)
 Add an element. More...
 
void remove (ValueT *&v, KeyT &k)
 Remove an element. More...
 

Public Attributes

int queueLength
 Number of elements in queue. More...
 
int maxLength
 Maximum number of elements int he queue. More...
 
ValueT ** valueQueue
 Queue of elements. More...
 
KeyT * keyQueue
 Queue of keys. More...
 

Detailed Description

template<class ValueT, class KeyT>
class EMAN::PriorityQueue< ValueT, KeyT >

Template class for a priority queue.

The smallest element is at the front

Definition at line 17 of file priority_queue.h.

Constructor & Destructor Documentation

◆ PriorityQueue()

template<class ValueT , class KeyT >
EMAN::PriorityQueue< ValueT, KeyT >::PriorityQueue ( int  max)
inline

Constructor.

Definition at line 37 of file priority_queue.h.

38 {
39 this->maxLength = max ;
40 this->queueLength = 0 ;
41 this->valueQueue = new ValueT* [ max ] ;
42 this->keyQueue = new KeyT [ max ] ;
43
44 };
int queueLength
Number of elements in queue.
ValueT ** valueQueue
Queue of elements.
KeyT * keyQueue
Queue of keys.
int maxLength
Maximum number of elements int he queue.

◆ ~PriorityQueue()

template<class ValueT , class KeyT >
EMAN::PriorityQueue< ValueT, KeyT >::~PriorityQueue ( )
inline

Destructor.

Definition at line 49 of file priority_queue.h.

50 {
51 delete [] keyQueue ;
52 for ( int i = 0 ; i < queueLength ; i ++ )
53 {
54 delete valueQueue [ i ] ;
55 }
56 delete [] valueQueue ;
57 };

References EMAN::PriorityQueue< ValueT, KeyT >::keyQueue, EMAN::PriorityQueue< ValueT, KeyT >::queueLength, and EMAN::PriorityQueue< ValueT, KeyT >::valueQueue.

Member Function Documentation

◆ add()

template<class ValueT , class KeyT >
void EMAN::PriorityQueue< ValueT, KeyT >::add ( ValueT *  v,
KeyT  k 
)
inline

Add an element.

Definition at line 86 of file priority_queue.h.

87 {
88 if ( this->isFull() )
89 {
90 printf("PRIORITY QUEUE FILLED UP !!! \n");
91 return ;
92 }
93
94 int ind = queueLength ;
95 int tind ;
96 queueLength ++ ;
97
98 while ( ind > 0 )
99 {
100 tind = ( ind + 1 ) / 2 - 1 ;
101 if ( k < keyQueue[tind] )
102 {
103 keyQueue[ ind ] = keyQueue [ tind ] ;
104 valueQueue [ ind ] = valueQueue [ tind ] ;
105 ind = tind ;
106 }
107 else
108 {
109 break;
110 }
111 }
112
113 valueQueue[ ind ] = v ;
114 keyQueue [ ind ] = k ;
115 };
bool isFull()
Test whether full.

References EMAN::PriorityQueue< ValueT, KeyT >::isFull(), EMAN::PriorityQueue< ValueT, KeyT >::keyQueue, EMAN::PriorityQueue< ValueT, KeyT >::queueLength, and EMAN::PriorityQueue< ValueT, KeyT >::valueQueue.

Referenced by wustl_mm::SkeletonMaker::Volume::curveSkeleton(), wustl_mm::SkeletonMaker::Volume::curveSkeleton2D(), wustl_mm::SkeletonMaker::Volume::skeleton(), and wustl_mm::SkeletonMaker::Volume::surfaceSkeletonPres().

◆ getLength()

template<class ValueT , class KeyT >
int EMAN::PriorityQueue< ValueT, KeyT >::getLength ( )
inline

Get current length.

Definition at line 62 of file priority_queue.h.

63 {
64 return this->queueLength ;
65 };

References EMAN::PriorityQueue< ValueT, KeyT >::queueLength.

◆ isEmpty()

template<class ValueT , class KeyT >
bool EMAN::PriorityQueue< ValueT, KeyT >::isEmpty ( )
inline

◆ isFull()

template<class ValueT , class KeyT >
bool EMAN::PriorityQueue< ValueT, KeyT >::isFull ( )
inline

Test whether full.

Definition at line 78 of file priority_queue.h.

79 {
80 return ( this->queueLength == this->maxLength ) ;
81 };

Referenced by EMAN::PriorityQueue< ValueT, KeyT >::add().

◆ remove()

template<class ValueT , class KeyT >
void EMAN::PriorityQueue< ValueT, KeyT >::remove ( ValueT *&  v,
KeyT &  k 
)
inline

Remove an element.

Definition at line 120 of file priority_queue.h.

121 {
122 if ( this->isEmpty() )
123 {
124 v = NULL ;
125 k = 0 ;
126 return ;
127 }
128
129 v = valueQueue[0] ;
130 k = keyQueue[0] ;
131 queueLength -- ;
132
133 if ( queueLength == 0 )
134 {
135 valueQueue[0] = NULL ;
136 return ;
137 }
138
139 ValueT * vv = valueQueue [ queueLength ] ;
140 KeyT kk = keyQueue [ queueLength ], lowk ;
141 int ind = 0, tind, ind2, ind3 ;
142 while ( 1 )
143 {
144 ind2 = 2 * ( ind + 1 ) - 1 ;
145 ind3 = ind2 + 1 ;
146 tind = ind ;
147 lowk = kk ;
148
149 if ( ind2 >= queueLength )
150 {
151 break ;
152 }
153 else
154 {
155 if ( keyQueue [ ind2 ] < lowk )
156 {
157 tind = ind2 ;
158 lowk = keyQueue [ ind2 ] ;
159 }
160
161 if ( ind3 < queueLength )
162 {
163 if ( keyQueue [ ind3 ] < lowk )
164 {
165 tind = ind3 ;
166 }
167 }
168
169 if ( ind != tind )
170 {
171 valueQueue [ ind ] = valueQueue [ tind ] ;
172 keyQueue [ ind ] = keyQueue [ tind ] ;
173 ind = tind ;
174 }
175 else
176 {
177 break ;
178 }
179 }
180 }
181
182 valueQueue [ ind ] = vv ;
183 keyQueue [ ind ] = kk ;
184 valueQueue [ queueLength ] = NULL ;
185 keyQueue [ queueLength ] = NULL ;
186 };
bool isEmpty()
Test whether empty.

References EMAN::PriorityQueue< ValueT, KeyT >::isEmpty(), EMAN::PriorityQueue< ValueT, KeyT >::keyQueue, EMAN::PriorityQueue< ValueT, KeyT >::queueLength, and EMAN::PriorityQueue< ValueT, KeyT >::valueQueue.

Referenced by wustl_mm::SkeletonMaker::Volume::curveSkeleton(), wustl_mm::SkeletonMaker::Volume::curveSkeleton2D(), wustl_mm::SkeletonMaker::Volume::skeleton(), and wustl_mm::SkeletonMaker::Volume::surfaceSkeletonPres().

Member Data Documentation

◆ keyQueue

template<class ValueT , class KeyT >
KeyT* EMAN::PriorityQueue< ValueT, KeyT >::keyQueue

◆ maxLength

template<class ValueT , class KeyT >
int EMAN::PriorityQueue< ValueT, KeyT >::maxLength

Maximum number of elements int he queue.

Definition at line 24 of file priority_queue.h.

◆ queueLength

template<class ValueT , class KeyT >
int EMAN::PriorityQueue< ValueT, KeyT >::queueLength

◆ valueQueue

template<class ValueT , class KeyT >
ValueT** EMAN::PriorityQueue< ValueT, KeyT >::valueQueue

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