00001 /***************************************************************************** 00002 * $Source: /cvsroot/charm/src/ck-ldb/heap.h,v $ 00003 * $Author: gzheng $ 00004 * $Date: 2005-04-30 22:34:45 $ 00005 * $Revision: 1.8 $ 00006 *****************************************************************************/ 00007 00018 00019 #ifndef _HEAP_H_ 00020 #define _HEAP_H_ 00021 00022 #include "elements.h" 00023 00024 class heapRecord 00025 { public: 00026 short deleted; // boolean 00027 InfoRecord *info; 00028 }; 00029 00030 class heapIterator{ 00031 public: 00032 int next; 00033 }; 00034 00035 class minHeap 00036 { 00037 private: 00038 heapRecord *h; 00039 int count; 00040 int size; 00041 void swap(int i, int j) { 00042 heapRecord temp = h[i]; 00043 h[i] = h[j]; 00044 h[j] = temp; 00045 } 00046 00047 public: 00048 minHeap(int size); 00049 ~minHeap(); 00050 int numElements() { return count; } 00051 int insert(InfoRecord *); 00052 InfoRecord *deleteMin(); 00053 InfoRecord *iterator(heapIterator *); 00054 InfoRecord *next(heapIterator *); 00055 void update(InfoRecord *); 00056 private: 00057 int least(int a, int b, int c); 00058 void update(int index); 00059 }; 00060 00061 class maxHeap 00062 { 00063 private: 00064 heapRecord *h; 00065 int count; 00066 int size; 00067 00068 void swap(int i, int j) { 00069 heapRecord temp = h[i]; 00070 h[i] = h[j]; 00071 h[j] = temp; 00072 } 00073 00074 public: 00075 maxHeap(int size); 00076 ~maxHeap(); 00077 int numElements(); 00078 int insert(InfoRecord *); 00079 InfoRecord *deleteMax(); 00080 InfoRecord *iterator(heapIterator *); 00081 InfoRecord *next(heapIterator *); 00082 }; 00083 00084 00085 #endif /* _HEAP_H_ */ 00086
1.5.1