Mercurial > hg > orthanc
annotate Core/Cache/LeastRecentlyUsedIndex.h @ 2421:d0fe5ec7eb05
playing with dicomdir
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 08 Oct 2017 11:13:56 +0200 |
parents | a3a65de1840f |
children | 878b59270859 |
rev | line source |
---|---|
282 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2244
a3a65de1840f
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
282 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #include <list> | |
37 #include <map> | |
38 #include <boost/noncopyable.hpp> | |
283 | 39 #include <cassert> |
40 | |
41 #include "../OrthancException.h" | |
284
06aa7b7b6723
implementation of a single-threaded cache mechanism
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
283
diff
changeset
|
42 #include "../Toolbox.h" |
282 | 43 |
44 namespace Orthanc | |
45 { | |
46 /** | |
47 * This class implements the index of a cache with least recently | |
48 * used (LRU) recycling policy. All the items of the cache index | |
49 * can be associated with a payload. | |
50 * Reference: http://stackoverflow.com/a/2504317 | |
51 **/ | |
52 template <typename T, typename Payload = NullType> | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
53 class LeastRecentlyUsedIndex : public boost::noncopyable |
282 | 54 { |
55 private: | |
56 typedef std::list< std::pair<T, Payload> > Queue; | |
57 typedef std::map<T, typename Queue::iterator> Index; | |
58 | |
59 Index index_; | |
60 Queue queue_; | |
61 | |
62 /** | |
63 * Internal method for debug builds to check whether the internal | |
64 * data structures are not corrupted. | |
65 **/ | |
66 void CheckInvariants() const; | |
67 | |
68 public: | |
69 /** | |
70 * Add a new element to the cache index, and make it the most | |
71 * recent element. | |
72 * \param id The ID of the element. | |
73 * \param payload The payload of the element. | |
74 **/ | |
75 void Add(T id, Payload payload = Payload()); | |
76 | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
77 void AddOrMakeMostRecent(T id, Payload payload = Payload()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
78 |
282 | 79 /** |
80 * When accessing an element of the cache, this method tags the | |
81 * element as the most recently used. | |
82 * \param id The most recently accessed item. | |
83 **/ | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
84 void MakeMostRecent(T id); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
85 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
86 void MakeMostRecent(T id, Payload updatedPayload); |
282 | 87 |
88 /** | |
89 * Remove an element from the cache index. | |
90 * \param id The item to remove. | |
91 **/ | |
92 Payload Invalidate(T id); | |
93 | |
94 /** | |
95 * Get the oldest element in the cache and remove it. | |
96 * \return The oldest item. | |
97 **/ | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
98 T RemoveOldest(); |
282 | 99 |
100 /** | |
101 * Get the oldest element in the cache, remove it and return the | |
102 * associated payload. | |
103 * \param payload Where to store the associated payload. | |
104 * \return The oldest item. | |
105 **/ | |
106 T RemoveOldest(Payload& payload); | |
107 | |
108 /** | |
109 * Check whether an element is contained in the cache. | |
110 * \param id The item. | |
111 * \return \c true iff the item is indexed by the cache. | |
112 **/ | |
113 bool Contains(T id) const | |
114 { | |
115 return index_.find(id) != index_.end(); | |
116 } | |
117 | |
283 | 118 bool Contains(T id, Payload& payload) const |
119 { | |
120 typename Index::const_iterator it = index_.find(id); | |
121 if (it == index_.end()) | |
122 { | |
123 return false; | |
124 } | |
125 else | |
126 { | |
127 payload = it->second->second; | |
128 return true; | |
129 } | |
130 } | |
131 | |
132 /** | |
133 * Return the number of elements in the cache. | |
134 * \return The number of elements. | |
135 **/ | |
136 size_t GetSize() const | |
137 { | |
138 assert(index_.size() == queue_.size()); | |
139 return queue_.size(); | |
140 } | |
141 | |
282 | 142 /** |
143 * Check whether the cache index is empty. | |
144 * \return \c true iff the cache is empty. | |
145 **/ | |
146 bool IsEmpty() const | |
147 { | |
148 return index_.empty(); | |
149 } | |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
150 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
151 const T& GetOldest() const; |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
152 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
153 const Payload& GetOldestPayload() const; |
282 | 154 }; |
283 | 155 |
156 | |
157 | |
158 | |
159 /****************************************************************** | |
160 ** Implementation of the template | |
161 ******************************************************************/ | |
162 | |
163 template <typename T, typename Payload> | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
164 void LeastRecentlyUsedIndex<T, Payload>::CheckInvariants() const |
283 | 165 { |
166 #ifndef NDEBUG | |
167 assert(index_.size() == queue_.size()); | |
168 | |
169 for (typename Index::const_iterator | |
170 it = index_.begin(); it != index_.end(); it++) | |
171 { | |
172 assert(it->second != queue_.end()); | |
173 assert(it->second->first == it->first); | |
174 } | |
175 #endif | |
176 } | |
177 | |
178 | |
179 template <typename T, typename Payload> | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
180 void LeastRecentlyUsedIndex<T, Payload>::Add(T id, Payload payload) |
283 | 181 { |
182 if (Contains(id)) | |
183 { | |
184 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
185 } | |
186 | |
187 queue_.push_front(std::make_pair(id, payload)); | |
188 index_[id] = queue_.begin(); | |
189 | |
190 CheckInvariants(); | |
191 } | |
192 | |
193 | |
194 template <typename T, typename Payload> | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
195 void LeastRecentlyUsedIndex<T, Payload>::MakeMostRecent(T id) |
283 | 196 { |
197 if (!Contains(id)) | |
198 { | |
199 throw OrthancException(ErrorCode_InexistentItem); | |
200 } | |
201 | |
202 typename Index::iterator it = index_.find(id); | |
203 assert(it != index_.end()); | |
204 | |
205 std::pair<T, Payload> item = *(it->second); | |
206 | |
207 queue_.erase(it->second); | |
208 queue_.push_front(item); | |
209 index_[id] = queue_.begin(); | |
210 | |
211 CheckInvariants(); | |
212 } | |
213 | |
214 | |
215 template <typename T, typename Payload> | |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
216 void LeastRecentlyUsedIndex<T, Payload>::AddOrMakeMostRecent(T id, Payload payload) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
217 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
218 typename Index::iterator it = index_.find(id); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
219 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
220 if (it != index_.end()) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
221 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
222 // Already existing. Make it most recent. |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
223 std::pair<T, Payload> item = *(it->second); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
224 item.second = payload; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
225 queue_.erase(it->second); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
226 queue_.push_front(item); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
227 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
228 else |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
229 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
230 // New item |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
231 queue_.push_front(std::make_pair(id, payload)); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
232 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
233 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
234 index_[id] = queue_.begin(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
235 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
236 CheckInvariants(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
237 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
238 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
239 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
240 template <typename T, typename Payload> |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
241 void LeastRecentlyUsedIndex<T, Payload>::MakeMostRecent(T id, Payload updatedPayload) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
242 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
243 if (!Contains(id)) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
244 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
245 throw OrthancException(ErrorCode_InexistentItem); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
246 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
247 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
248 typename Index::iterator it = index_.find(id); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
249 assert(it != index_.end()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
250 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
251 std::pair<T, Payload> item = *(it->second); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
252 item.second = updatedPayload; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
253 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
254 queue_.erase(it->second); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
255 queue_.push_front(item); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
256 index_[id] = queue_.begin(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
257 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
258 CheckInvariants(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
259 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
260 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
261 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
262 template <typename T, typename Payload> |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
263 Payload LeastRecentlyUsedIndex<T, Payload>::Invalidate(T id) |
283 | 264 { |
265 if (!Contains(id)) | |
266 { | |
267 throw OrthancException(ErrorCode_InexistentItem); | |
268 } | |
269 | |
270 typename Index::iterator it = index_.find(id); | |
271 assert(it != index_.end()); | |
272 | |
273 Payload payload = it->second->second; | |
274 queue_.erase(it->second); | |
275 index_.erase(it); | |
276 | |
277 CheckInvariants(); | |
278 return payload; | |
279 } | |
280 | |
281 | |
282 template <typename T, typename Payload> | |
505
f59e4518fd57
rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
283 T LeastRecentlyUsedIndex<T, Payload>::RemoveOldest(Payload& payload) |
283 | 284 { |
285 if (IsEmpty()) | |
286 { | |
287 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
288 } | |
289 | |
290 std::pair<T, Payload> item = queue_.back(); | |
291 T oldest = item.first; | |
292 payload = item.second; | |
293 | |
294 queue_.pop_back(); | |
295 assert(index_.find(oldest) != index_.end()); | |
296 index_.erase(oldest); | |
297 | |
298 CheckInvariants(); | |
299 | |
300 return oldest; | |
301 } | |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
302 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
303 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
304 template <typename T, typename Payload> |
509
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
305 T LeastRecentlyUsedIndex<T, Payload>::RemoveOldest() |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
306 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
307 if (IsEmpty()) |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
308 { |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
309 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
310 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
311 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
312 std::pair<T, Payload> item = queue_.back(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
313 T oldest = item.first; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
314 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
315 queue_.pop_back(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
316 assert(index_.find(oldest) != index_.end()); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
317 index_.erase(oldest); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
318 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
319 CheckInvariants(); |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
320 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
321 return oldest; |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
322 } |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
323 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
324 |
e7841864c97c
StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
507
diff
changeset
|
325 template <typename T, typename Payload> |
507
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
326 const T& LeastRecentlyUsedIndex<T, Payload>::GetOldest() const |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
327 { |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
328 if (IsEmpty()) |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
329 { |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
330 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
331 } |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
332 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
333 return queue_.back().first; |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
334 } |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
335 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
336 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
337 template <typename T, typename Payload> |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
338 const Payload& LeastRecentlyUsedIndex<T, Payload>::GetOldestPayload() const |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
339 { |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
340 if (IsEmpty()) |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
341 { |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
342 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
343 } |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
344 |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
345 return queue_.back().second; |
c4122c3a47c1
access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
505
diff
changeset
|
346 } |
282 | 347 } |