tpl_dynBinHeap.H

00001 
00002 /*
00003   This file is part of Aleph system
00004 
00005   Copyright (c) 2002, 2003, 2004, 2005, 2006
00006   UNIVERSITY LOS ANDES (ULA) Merida - REPÚBLICA BOLIVARIANA DE VENEZUELA  
00007 
00008   - Center of Studies in Microelectronics & Distributed Systems (CEMISID) 
00009   - ULA Computer Science Department
00010   - FUNDACITE Mérida - Ministerio de Ciencia y Tecnología
00011 
00012   PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE AND ITS
00013   DOCUMENTATION IS HEREBY GRANTED, PROVIDED THAT BOTH THE COPYRIGHT
00014   NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES OF THE
00015   SOFTWARE, DERIVATIVE WORKS OR MODIFIED VERSIONS, AND ANY PORTIONS
00016   THEREOF, AND THAT BOTH NOTICES APPEAR IN SUPPORTING DOCUMENTATION.
00017 
00018   Aleph is distributed in the hope that it will be useful, but WITHOUT
00019   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020   or FITNESS FOR A PARTICULAR PURPOSE.
00021 
00022   UNIVERSIDAD DE LOS ANDES requests users of this software to return to 
00023 
00024   Leandro Leon
00025   CEMISID 
00026   Ed La Hechicera 
00027   3er piso, ala sur
00028   Facultad de Ingenieria 
00029   Universidad de Los Andes 
00030   Merida - REPÚBLICA BOLIVARIANA DE VENEZUELA    or
00031 
00032   lrleon@ula.ve
00033 
00034   any improvements or extensions that they make and grant Universidad 
00035   de Los Andes (ULA) the rights to redistribute these changes. 
00036 
00037   Aleph is (or was) granted by: 
00038   - Consejo de Desarrollo Cientifico, Humanistico, Tecnico de la ULA 
00039     (CDCHT)
00040   - Fundacite Mérida
00041 */
00042 
00043 # ifndef TPL_DYNBINHEAP_H
00044 # define TPL_DYNBINHEAP_H
00045 
00046 # include <tpl_binHeap.H>
00047 
00048 using namespace Aleph;
00049 
00050 namespace Aleph {
00051 
00065     template <class T, class Compare = Aleph::less<T> >
00066 class DynBinHeap : public BinHeap<T, Compare>
00067 {
00068 public:
00069 
00079   T & insert(const T & item) throw(std::exception, std::bad_alloc)
00080   {
00081     typename BinHeap<T, Compare>::Node * node = 
00082       new typename BinHeap<T, Compare>::Node (item);
00083 
00084     BinHeap<T, Compare>::insert(node);
00085 
00086     return node->get_key();
00087   }
00088 
00095   T getMin() throw(std::exception, std::underflow_error)
00096   {
00097     typename BinHeap<T, Compare>::Node * node = BinHeap<T, Compare>::getMin();
00098 
00099     T return_value = node->get_key(); 
00100 
00101     delete node;
00102 
00103     return return_value;
00104   }
00105 
00119   void update(T & data)
00120   {
00121     typename BinHeap<T, Compare>::Node * node = 
00122       BinHeap<T, Compare>::Node::key_to_node(data);
00123 
00124     BinHeap<T, Compare>::update(node);
00125   }
00126 
00130   T & top() const throw(std::exception, std::underflow_error)
00131   {
00132     typename BinHeap<T, Compare>::Node * node = BinHeap<T, Compare>::top();
00133 
00134     return node->get_key();
00135   }
00136 
00138   void empty()
00139   {
00140     this->remove_all_and_delete();
00141   }
00142 
00144   ~DynBinHeap()
00145   {
00146     empty();
00147   }
00148 };
00149 
00150 } // end namespace Aleph
00151 
00152 # endif // TPL_DYNBINHEAP_H
00153 
00154 
00155 

Leandro R. León