summaryrefslogtreecommitdiffstats
path: root/include/utils/LruCache.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/utils/LruCache.h')
-rw-r--r--include/utils/LruCache.h23
1 files changed, 18 insertions, 5 deletions
diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h
index 053bfaf..cd9d7f9 100644
--- a/include/utils/LruCache.h
+++ b/include/utils/LruCache.h
@@ -17,8 +17,8 @@
#ifndef ANDROID_UTILS_LRU_CACHE_H
#define ANDROID_UTILS_LRU_CACHE_H
+#include <UniquePtr.h>
#include <utils/BasicHashtable.h>
-#include <utils/UniquePtr.h>
namespace android {
@@ -48,6 +48,7 @@ public:
bool remove(const TKey& key);
bool removeOldest();
void clear();
+ const TValue& peekOldestValue();
class Iterator {
public:
@@ -56,7 +57,7 @@ public:
bool next() {
mIndex = mCache.mTable->next(mIndex);
- return mIndex != -1;
+ return (ssize_t)mIndex != -1;
}
size_t index() const {
@@ -103,9 +104,13 @@ private:
// Implementation is here, because it's fully templated
template <typename TKey, typename TValue>
-LruCache<TKey, TValue>::LruCache(uint32_t maxCapacity): mMaxCapacity(maxCapacity),
- mNullValue(NULL), mTable(new BasicHashtable<TKey, Entry>), mYoungest(NULL), mOldest(NULL),
- mListener(NULL) {
+LruCache<TKey, TValue>::LruCache(uint32_t maxCapacity)
+ : mTable(new BasicHashtable<TKey, Entry>)
+ , mListener(NULL)
+ , mOldest(NULL)
+ , mYoungest(NULL)
+ , mMaxCapacity(maxCapacity)
+ , mNullValue(NULL) {
};
template<typename K, typename V>
@@ -180,6 +185,14 @@ bool LruCache<TKey, TValue>::removeOldest() {
}
template <typename TKey, typename TValue>
+const TValue& LruCache<TKey, TValue>::peekOldestValue() {
+ if (mOldest) {
+ return mOldest->value;
+ }
+ return mNullValue;
+}
+
+template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::clear() {
if (mListener) {
for (Entry* p = mOldest; p != NULL; p = p->child) {