All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LFUCachePolicy .cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file LFUCachePolicy.cpp
22 
23  \brief This class is used to implement the LFU cache policy.
24 */
25 
26 #include "LFUCachePolicy.h"
27 
28 #include <limits>
29 
31 {
32 }
33 
35 {
36  m_LFU.clear();
37 }
38 
40 {
41  m_LFU.insert(std::map<int, double>::value_type(value, 1.));
42 }
43 
45 {
46  accessed(value);
47 }
48 
50 {
51  std::map<int, double>::iterator itLFU = m_LFU.begin();
52  std::map<int, double>::iterator itMin = m_LFU.end();
53 
54  double minValue = std::numeric_limits<double>::max();
55 
56  while(itLFU != m_LFU.end())
57  {
58  if(itLFU->second < minValue)
59  {
60  minValue = itLFU->second;
61  itMin = itLFU;
62  }
63  ++itLFU;
64  }
65 
66  if(itMin != m_LFU.end())
67  {
68  value = itMin->first;
69  m_LFU.erase(itMin);
70  }
71 }
72 
74 {
75  std::map<int, double>::iterator itLFU = m_LFU.begin();
76 
77  while(itLFU != m_LFU.end())
78  {
79  if(itLFU->first == value)
80  {
81  itLFU->second += 1.;
82  break;
83  }
84  ++itLFU;
85  }
86 }
87 
88 
virtual void toRemove(int &value)
Function used to check what index has to be removed from the cache.
This class is used to implement the LFU cache policy.
virtual void accessed(int value)
Function used to inform that an index was accessed.
virtual ~LFUCachePolicy()
Virtual destructor.
virtual void added(int value)
Function used to add a new index to be controlled.
LFUCachePolicy()
Default constructor.
virtual void update(int value)
Function used to inform that an index must be updated.