00001
00061 #ifndef ABA_BHEAP_H
00062 #define ABA_BHEAP_H
00063
00064 #include "abacus/array.h"
00065
00066 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX
00067 template<class Type, class Key>
00068 class ABA_BHEAP;
00069
00070 template<class Type,class Key>
00071 ostream&operator<< (ostream& out, const ABA_BHEAP<Type, Key>& rhs);
00072 #endif
00073
00074 template<class Type, class Key> class ABA_BHEAP : public ABA_ABACUSROOT {
00075 public:
00076
00082 ABA_BHEAP(ABA_GLOBAL *glob, int size);
00083
00094 ABA_BHEAP(ABA_GLOBAL *glob,
00095 const ABA_BUFFER<Type> &elems,
00096 const ABA_BUFFER<Key> &keys);
00097 #ifdef ABACUS_NEW_TEMPLATE_SYNTAX
00098
00107 friend ostream& operator<< <> (ostream&, const ABA_BHEAP<Type, Key>&);
00108 #else
00109
00118 friend ostream& operator<< (ostream& out, const ABA_BHEAP<Type, Key>& rhs);
00119 #endif
00120
00132 void insert(Type elem, Key key);
00133
00139 Type getMin() const;
00140
00147 Key getMinKey() const;
00148
00161 Type extractMin();
00162
00163
00166 void clear();
00167
00170 int size() const;
00171
00174 int number() const;
00175
00179 bool empty() const;
00180
00185 void realloc(int newSize);
00186
00192 void check() const;
00193
00194 private:
00195
00198 int leftSon(int i) const;
00199
00202 int rightSon(int i) const;
00203
00206 int father(int i) const;
00207
00214 void heapify(int i);
00215
00216 ABA_GLOBAL *glob_;
00217 ABA_ARRAY<Type> heap_;
00218 ABA_ARRAY<Key> keys_;
00219 int n_;
00220 };
00221
00222 #include "abacus/bheap.inc"
00223
00224 #endif // !ABA_BHEAP_H
00225
00226