FastJet 3.0beta1
|
00001 //STARTHEADER 00002 // $Id: MinHeap.hh 1761 2010-09-16 10:43:18Z soyez $ 00003 // 00004 // Copyright (c) 2005-2006, Matteo Cacciari and Gavin Salam 00005 // 00006 //---------------------------------------------------------------------- 00007 // This file is part of FastJet. 00008 // 00009 // FastJet is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // The algorithms that underlie FastJet have required considerable 00015 // development and are described in hep-ph/0512210. If you use 00016 // FastJet as part of work towards a scientific publication, please 00017 // include a citation to the FastJet paper. 00018 // 00019 // FastJet is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with FastJet; if not, write to the Free Software 00026 // Foundation, Inc.: 00027 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 //---------------------------------------------------------------------- 00029 //ENDHEADER 00030 00031 #ifndef __FASTJET_MINHEAP__HH__ 00032 #define __FASTJET_MINHEAP__HH__ 00033 00034 #include<vector> 00035 #include<cassert> 00036 #include<memory> 00037 #include<limits> 00038 #include "fastjet/internal/base.hh" 00039 00040 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 00041 00042 //====================================================================== 00043 /// \if internal_doc 00044 /// @ingroup internal 00045 /// \class MinHeap 00046 /// A class which provides a "heap"-like structure that allows 00047 /// access to a the minimal value of a dynamically changing set of numbers 00048 /// \endif 00049 class MinHeap { 00050 public: 00051 /// construct a MinHeap from the vector of values, allowing future 00052 /// expansion to a maximum size max_size; 00053 MinHeap (const std::vector<double> & values, unsigned int max_size) : 00054 _heap(max_size) {_initialise(values);}; 00055 00056 /// constructor in which the the maximum size is the size of the values array 00057 MinHeap (const std::vector<double> & values) : 00058 _heap(values.size()) {_initialise(values);}; 00059 00060 /// return the location of the minimal value on the heap 00061 inline unsigned int minloc() const { 00062 return (_heap[0].minloc) - &(_heap[0]);}; 00063 00064 /// return the minimal value on the heap 00065 inline double minval() const {return _heap[0].minloc->value;}; 00066 00067 inline double operator[](int i) const {return _heap[i].value;}; 00068 00069 /// remove the value at the specified location (i.e. replace it with 00070 /// the largest possible value). 00071 void remove(unsigned int loc) { 00072 update(loc,std::numeric_limits<double>::max());}; 00073 00074 /// update the value at the specified location 00075 void update(unsigned int, double); 00076 00077 private: 00078 00079 struct ValueLoc{ 00080 double value; 00081 ValueLoc * minloc; 00082 }; 00083 00084 std::vector<ValueLoc> _heap; 00085 00086 void _initialise(const std::vector<double> & values); 00087 00088 00089 }; 00090 00091 00092 FASTJET_END_NAMESPACE 00093 00094 #endif // __FASTJET_MINHEAP__HH__