00001
00002 00004
00005 #if !defined(AFX_HIERARCHICALQUEUE_H__2E7CF594_00AC_4542_A133_E8188A04FBAD__INCLUDED_)
00006 #define AFX_HIERARCHICALQUEUE_H__2E7CF594_00AC_4542_A133_E8188A04FBAD__INCLUDED_
00007
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011
00012 #include "Queue.h"
00013
00031 class CHierarchicalQueue : public CQueue
00032 {
00033 int size;
00034 deque<LPPIXEL> *hQueue;
00035 deque<short> *hQparity;
00036 deque<LPPIXEL> priorityQueue;
00037 deque<short> priorityQueueParity;
00038
00039 PIXEL currentLevel;
00040
00041 public:
00042 CHierarchicalQueue(int sizeQueue=256){
00043 size = sizeQueue;
00044 hQueue = new deque<LPPIXEL>[size];
00045 hQparity = new deque<short>[size];
00046 currentLevel = 0;
00047 };
00048 ~CHierarchicalQueue() {
00049 priorityQueue.clear();
00050 priorityQueueParity.clear();
00051 for (int i=0; i<size; i++) {
00052 hQueue[i].clear();
00053 hQparity[i].clear();
00054 }
00055 delete [] hQueue;
00056 delete [] hQparity;
00057 };
00058
00059 inline bool empty() {
00060 return (priorityQueue.empty() && hQueue[currentLevel].empty());
00061 };
00062
00063 inline void first(LPPIXEL *p) {
00064 if (!priorityQueue.empty()) {
00065 *p = priorityQueue.front();
00066 priorityQueue.pop_front();
00067 return;
00068 }
00069 if (hQueue[currentLevel].empty()) {
00070
00071 do currentLevel++;
00072 while ((currentLevel<size)
00073 && hQueue[currentLevel].empty());
00074 }
00075 *p = hQueue[currentLevel].front();
00076 hQueue[currentLevel].pop_front();
00077 return;
00078 };
00079
00080 inline void first(LPPIXEL *p, short *parity) {
00081 if (!priorityQueue.empty()) {
00082 *p = priorityQueue.front();
00083 priorityQueue.pop_front();
00084 *parity = priorityQueueParity.front();
00085 priorityQueueParity.pop_front();
00086 return;
00087 }
00088 if (hQueue[currentLevel].empty()) {
00089
00090 do currentLevel++;
00091 while ((currentLevel<size)
00092 && hQueue[currentLevel].empty());
00093 }
00094 *p = hQueue[currentLevel].front();
00095 hQueue[currentLevel].pop_front();
00096 *parity = hQparity[currentLevel].front();
00097 hQparity[currentLevel].pop_front();
00098 return;
00099 };
00100
00101 inline void add(LPPIXEL p) {
00102 if (*p<currentLevel) {
00103 priorityQueue.push_front(p);
00104 return;
00105 }
00106 hQueue[*p].push_front(p);
00107 return;
00108 };
00109
00110 inline void add(LPPIXEL p, short parity) {
00111 if (*p<currentLevel) {
00112 priorityQueue.push_front(p);
00113 priorityQueueParity.push_front(parity);
00114 return;
00115 }
00116 hQueue[*p].push_front(p);
00117 hQparity[*p].push_front(parity);
00118 return;
00119 };
00120
00121 inline void invert() {
00122
00123 };
00124 };
00125
00126 #endif // !defined(AFX_HIERARCHICALQUEUE_H__2E7CF594_00AC_4542_A133_E8188A04FBAD__INCLUDED_)