1/* 2================================================================================ 3 PROJECT: 4 5 John Eddy's Genetic Algorithms (JEGA) 6 7 CONTENTS: 8 9 Inline methods of class LRUDesignCache. 10 11 NOTES: 12 13 See notes of LRUDesignCache.hpp. 14 15 PROGRAMMERS: 16 17 John Eddy (jpeddy@sandia.gov) (JE) 18 19 ORGANIZATION: 20 21 Sandia National Laboratories 22 23 COPYRIGHT: 24 25 This library is free software; you can redistribute it and/or 26 modify it under the terms of the GNU Lesser General Public 27 License as published by the Free Software Foundation; either 28 version 2.1 of the License, or (at your option) any later version. 29 30 This library is distributed in the hope that it will be useful, 31 but WITHOUT ANY WARRANTY; without even the implied warranty of 32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 Lesser General Public License for more details. 34 35 You should have received a copy of the GNU Lesser General Public 36 License along with this library; if not, write to the Free Software 37 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 38 USA 39 40 VERSION: 41 42 2.7.0 43 44 CHANGES: 45 46 Mon Apr 20 08:37:40 2015 - Original Version (JE) 47 48================================================================================ 49*/ 50 51 52 53 54/* 55================================================================================ 56Document This File 57================================================================================ 58*/ 59/** \file 60 * \brief Contains the inline methods of the LRUDesignCache class. 61 */ 62 63 64 65 66/* 67================================================================================ 68Includes 69================================================================================ 70*/ 71 72 73 74 75 76 77 78 79/* 80================================================================================ 81Begin Namespace 82================================================================================ 83*/ 84namespace JEGA { 85 namespace Utilities { 86 87 88 89 90 91/* 92================================================================================ 93Inline Mutators 94================================================================================ 95*/ 96 97 98 99 100 101 102 103 104/* 105================================================================================ 106Inline Accessors 107================================================================================ 108*/ 109 110 111 112 113 114 115 116 117/* 118================================================================================ 119Inline Public Methods 120================================================================================ 121*/ 122 123inline 124void 125LRUDesignCache::indexed_list::on_accessed( 126 const key_type& key 127 ) 128{ 129 this->remove(key); 130 this->add(key); 131} 132 133inline 134void 135LRUDesignCache::indexed_list::add( 136 const key_type& key 137 ) 138{ 139 this->_indices[key] = this->_data.insert(this->_data.end(), key); 140} 141 142 143inline 144void 145LRUDesignCache::indexed_list::remove_first( 146 ) 147{ 148 this->_indices.erase(*this->_data.begin()); 149 this->_data.pop_front(); 150} 151 152inline 153std::size_t 154LRUDesignCache::indexed_list::size( 155 ) 156{ 157 return this->_data.size(); 158} 159 160 161inline 162void 163LRUDesignCache::indexed_list::clear( 164 ) 165{ 166 this->_indices.clear(); 167 this->_data.clear(); 168} 169 170 171inline 172LRUDesignCache::const_reference 173LRUDesignCache::indexed_list::front( 174 ) 175{ 176 return this->_data.front(); 177} 178 179 180inline 181LRUDesignCache::const_reference 182LRUDesignCache::indexed_list::back( 183 ) 184{ 185 return this->_data.back(); 186} 187 188inline 189const DesignDVSortSet& 190LRUDesignCache::DVSortSet( 191 ) const 192{ 193 return this->_data; 194} 195 196inline 197const LRUDesignCache::size_type& 198LRUDesignCache::max_size( 199 ) const 200{ 201 return this->_maxSize; 202} 203 204inline 205void 206LRUDesignCache::max_size( 207 const size_type& newSize 208 ) 209{ 210 this->_maxSize = newSize; 211 this->manage_size(); 212} 213 214inline 215LRUDesignCache::size_type 216LRUDesignCache::size( 217 ) const 218{ 219 return this->_data.size(); 220} 221 222inline 223bool 224LRUDesignCache::empty( 225 ) const 226{ 227 return this->_data.empty(); 228} 229 230inline 231void 232LRUDesignCache::insert( 233 const key_type& key 234 ) 235{ 236 this->_data.insert(key); 237 this->_lruList.add(key); 238 this->manage_size(); 239} 240 241inline 242void 243LRUDesignCache::erase( 244 const_iterator loc 245 ) 246{ 247 if(this->_doCache) this->_lruList.remove(*loc); 248 this->_data.erase(loc); 249} 250 251inline 252LRUDesignCache::size_type 253LRUDesignCache::erase( 254 const key_type& key 255 ) 256{ 257 if(this->_doCache) this->_lruList.remove(key); 258 return this->_data.erase(key); 259} 260 261inline 262void 263LRUDesignCache::erase( 264 const_iterator b, 265 const_iterator e 266 ) 267{ 268 if(this->_doCache) for(const_iterator it(b); it!=e; ++it) 269 this->_lruList.remove(*it); 270 271 this->_data.erase(b, e); 272} 273 274inline 275DesignDVSortSet::const_iterator 276LRUDesignCache::find_exact( 277 const key_type& key 278 ) const 279{ 280 return this->on_maybe_accessed(this->_data.find_exact(key)); 281} 282 283inline 284DesignDVSortSet::const_iterator 285LRUDesignCache::find_not_exact( 286 const key_type& key 287 ) const 288{ 289 return this->on_maybe_accessed(this->_data.find_not_exact(key)); 290} 291 292inline 293DesignDVSortSet::iterator 294LRUDesignCache::find_exact( 295 const key_type& key 296 ) 297{ 298 return this->on_maybe_accessed(this->_data.find_exact(key)); 299} 300 301inline 302DesignDVSortSet::iterator 303LRUDesignCache::find_not_exact( 304 const key_type& key 305 ) 306{ 307 return this->on_maybe_accessed(this->_data.find_not_exact(key)); 308} 309 310inline 311DesignDVSortSet::size_type 312LRUDesignCache::count_non_unique( 313 ) const 314{ 315 return this->_data.count_non_unique(); 316} 317 318inline 319std::ostream& 320LRUDesignCache::stream_out( 321 std::ostream& stream 322 ) const 323{ 324 return this->_data.stream_out(stream); 325} 326 327inline 328std::ostream& 329LRUDesignCache::stream_out( 330 const key_type des, 331 std::ostream& stream 332 ) 333{ 334 return DesignDVSortSet::stream_out(des, stream); 335} 336 337inline 338void 339LRUDesignCache::flush( 340 ) 341{ 342 this->_data.flush(); 343 this->_lruList.clear(); // doCache check not needed. 344} 345 346inline 347DesignDVSortSet::const_iterator 348LRUDesignCache::test_for_clone( 349 const key_type key 350 ) const 351{ 352 return this->on_maybe_accessed(this->_data.test_for_clone(key)); 353} 354 355inline 356DesignDVSortSet::size_type 357LRUDesignCache::test_within_list_for_clones( 358 ) const 359{ 360 return this->_data.test_within_list_for_clones(); 361} 362 363inline 364LRUDesignCache::const_iterator 365LRUDesignCache::begin( 366 ) const 367{ 368 return this->_data.begin(); 369} 370 371inline 372LRUDesignCache::iterator 373LRUDesignCache::begin( 374 ) 375{ 376 return this->_data.begin(); 377} 378 379inline 380LRUDesignCache::const_iterator 381LRUDesignCache::end( 382 ) const 383{ 384 return this->_data.end(); 385} 386 387inline 388LRUDesignCache::iterator 389LRUDesignCache::end( 390 ) 391{ 392 return this->_data.end(); 393} 394 395 396 397 398// 399//const LRUDesignCache::key_type& 400//LRUDesignCache::operator []( 401// const key_type& key 402// ) const 403//{ 404// return this->retrieve(key); 405//} 406// 407// 408//void 409//LRUDesignCache::insert( 410// const key_type& key 411// ) 412//{ 413// this->_data.insert(key); 414// this->_lruList.on_accessed(key); 415// this->manage_size(); 416//} 417// 418// 419//const LRUDesignCache::key_type& 420//LRUDesignCache::retrieve( 421// const key_type& key 422// ) const 423//{ 424// const_iterator it(this->_data.find(key)); 425// 426// if(it == this->_data.end()) throw std::exception( 427// "Key not found in LRU cache." 428// ); 429// 430// this->_lruList.on_accessed(key); 431// 432// return *it; 433//} 434 435/* 436================================================================================ 437Inline Subclass Visible Methods 438================================================================================ 439*/ 440 441 442 443 444 445 446 447/* 448================================================================================ 449Inline Private Methods 450================================================================================ 451*/ 452template <typename ItT> 453const ItT& 454LRUDesignCache::on_accessed( 455 const ItT& it 456 ) const 457{ 458 if(this->_doCache) this->_lruList.on_accessed(*it); 459 return it; 460} 461 462template <typename ItT> 463const ItT& 464LRUDesignCache::on_maybe_accessed( 465 const ItT& it 466 ) const 467{ 468 if(this->_doCache && (it != this->_data.end())) 469 this->_lruList.on_accessed(*it); 470 return it; 471} 472 473 474 475 476 477 478 479 480/* 481================================================================================ 482Inline Structors 483================================================================================ 484*/ 485 486inline 487LRUDesignCache::indexed_list::indexed_list( 488 size_type initCap 489 ) : 490 _data(), 491#ifdef JEGA_HAVE_BOOST 492 _indices(initCap) 493#else 494 _indices() 495#endif 496{} 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511/* 512================================================================================ 513End Namespace 514================================================================================ 515*/ 516 } // namespace Utilities 517} // namespace JEGA 518 519