00001 #ifndef CACHED_EST_INFO_HELPER_H 00002 #define CACHED_EST_INFO_HELPER_H 00003 00004 //-------------------------------------------------------------------- 00005 // 00006 // This file is part of PEACE. 00007 // 00008 // PEACE is free software: you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation, either version 3 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // PEACE is distributed in the hope that it will be useful, but 00014 // WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with PEACE. If not, see <http://www.gnu.org/licenses/>. 00020 // 00021 // Miami University makes no representations or warranties about the 00022 // suitability of the software, either express or implied, including 00023 // but not limited to the implied warranties of merchantability, 00024 // fitness for a particular purpose, or non-infringement. Miami 00025 // University shall not be liable for any damages suffered by licensee 00026 // as a result of using, result of using, modifying or distributing 00027 // this software or its derivatives. 00028 // 00029 // By using or copying this Software, Licensee agrees to abide by the 00030 // intellectual property laws, and all other applicable laws of the 00031 // U.S., and the terms of GNU General Public License (version 3). 00032 // 00033 // Authors: Dhananjai M. Rao raodm@muohio.edu 00034 // 00035 //--------------------------------------------------------------------- 00036 00037 #include "CachedESTInfo.h" 00038 00039 /** \file CachedESTInfoHelper.h 00040 00041 \brief A collection of functors and static utility methods for 00042 varions operations on CachedESTInfo objects. 00043 00044 This file was primarily introduced to try and centralized some of 00045 the utility methods and definitions associated with manaing 00046 CachedESTInfo objects. These classes and methods were moved here 00047 as they technicaly don't belong to any specific class and they 00048 were unnecessarily cluttering other files. 00049 */ 00050 00051 /** Functor for CachedESTInfo sorting. 00052 00053 This Functor is used when sorting ESTs based on 00054 similarity/distance metric by the sort method defined in this 00055 class. This functor sorts methods in ascending order with the 00056 smallest values at top. 00057 */ 00058 class LessCachedESTInfo : 00059 public std::binary_function<CachedESTInfo, CachedESTInfo, bool> { 00060 public: 00061 /** Constructor. 00062 00063 The constructor requires a pointer to the ESTAnalyzer that 00064 is being used for analysis. The analyzer is used to 00065 compare the metrics for sorting CachedESTInfo objects. 00066 This constructor is called in the MSTCache class for 00067 sorting cache entries. 00068 00069 \param[in] analyzer The analyzer to be used for comparing 00070 the metric values associated with two CachedESTInfo 00071 objects. 00072 */ 00073 LessCachedESTInfo(const ESTAnalyzer *analyzer) : 00074 comparator(analyzer) {} 00075 00076 /** \fn operator()(const CachedESTInfo& estInfo1, const CachedESTInfo& estInfo2) 00077 00078 \brief operator() for CachedESTInfo. 00079 00080 The following operator provides a convenient mechanism for 00081 comparing CachedESTInfo objects for sorting. This 00082 operator overrides the default STL operator() by comparing 00083 only the metrics of two CachedESTInfo objects (ignoring 00084 the EST indexes and any other information). This method 00085 uses the metric comparison functionality provided by all 00086 EST analyzers. 00087 00088 \param[in] estInfo1 The first CachedESTInfo object to be 00089 used for comparison. 00090 00091 \param[in] estInfo2 The second CachedESTInfo object to be 00092 used for comparison. 00093 00094 \return This method returns \c true if \c estInfo1.metric 00095 is better than \c estInfo2.metric. Otherwise it returns 00096 \c false. 00097 */ 00098 inline bool operator()(const CachedESTInfo& estInfo1, 00099 const CachedESTInfo& estInfo2) 00100 { return comparator->compareMetrics(estInfo1.metric, estInfo2.metric); } 00101 00102 private: 00103 /** The functor for comparing. 00104 00105 This comparator is set based on the template parameter 00106 associated with the enclosing class. 00107 */ 00108 const ESTAnalyzer *const comparator; 00109 00110 /** A dummy operator= 00111 00112 The operator=() is supressed for this class as it has constant 00113 members whose value is set when the object is created. These 00114 values cannot be changed during the lifetime of this object. 00115 00116 \param[in] src The source object from where data is to be 00117 copied. Currently this value is ignored. 00118 00119 \return Reference to this. 00120 */ 00121 LessCachedESTInfo& operator=(const LessCachedESTInfo& src); 00122 }; 00123 00124 /** Functor for CachedESTInfo sorting. 00125 00126 This Functor is used when sorting ESTs based on 00127 similarity/distance metric by the sort method defined in this 00128 class. This functor sorts methods in \b descending order with the 00129 smallest values at the bottom. This functor is useful for 00130 maintaing heaps with the best metric at the top. 00131 */ 00132 class GreaterCachedESTInfo : 00133 public std::binary_function<CachedESTInfo, CachedESTInfo, bool> { 00134 public: 00135 /** Constructor. 00136 00137 The constructor requires a pointer to the ESTAnalyzer that is 00138 being used for analysis. The analyzer is used to compare the 00139 metrics for sorting CachedESTInfo objects. This constructor 00140 is called in the MSTCache derived classes for sorting cache 00141 entries. 00142 00143 \param[in] analyzer The analyzer to be used for comparing 00144 the metric values associated with two CachedESTInfo 00145 objects. 00146 */ 00147 GreaterCachedESTInfo(const ESTAnalyzer *analyzer) : 00148 comparator(analyzer) {} 00149 00150 /** \fn operator()(const CachedESTInfo& estInfo1, const CachedESTInfo& estInfo2) 00151 00152 \brief operator() for CachedESTInfo to compare two CachedESTInfo 00153 objects. 00154 00155 The following operator provides a convenient mechanism for 00156 comparing CachedESTInfo objects for sorting. This 00157 operator overrides the default STL operator() by comparing 00158 only the metrics of two CachedESTInfo objects (ignoring 00159 the EST indexes and any other information). This method 00160 uses the metric comparison functionality provided by all 00161 EST analyzers. 00162 00163 \param[in] estInfo1 The first CachedESTInfo object to be 00164 used for comparison. 00165 00166 \param[in] estInfo2 The second CachedESTInfo object to be 00167 used for comparison. 00168 00169 \return This method returns \c true if \c estInfo2.metric is 00170 better than \c estInfo1.metric. Otherwise it returns \c 00171 false. 00172 */ 00173 inline bool operator()(const CachedESTInfo& estInfo1, 00174 const CachedESTInfo& estInfo2) 00175 { return comparator->compareMetrics(estInfo2.metric, estInfo1.metric); } 00176 00177 private: 00178 /** The functor for comparing. 00179 00180 This comparator is set based on the template parameter 00181 associated with the enclosing class. 00182 */ 00183 const ESTAnalyzer *const comparator; 00184 00185 /** A dummy operator= 00186 00187 The operator=() is supressed for this class as it has constant 00188 members whose value is set when the object is created. These 00189 values cannot be changed during the lifetime of this object. 00190 00191 \param[in] src The source object from where data is to be 00192 copied. Currently this value is ignored. 00193 00194 \return Reference to this. 00195 */ 00196 GreaterCachedESTInfo& operator=(const GreaterCachedESTInfo& src); 00197 }; 00198 00199 #endif