summaryrefslogtreecommitdiffstats
path: root/include/utils
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-11-28 18:26:54 -0800
committerAlex Ray <aray@google.com>2013-07-30 13:57:00 -0700
commit5ca402a4e2537fa694de120264c5a5e2a4e777bf (patch)
tree247d5d3cbe5777607815a111492620d42b0213f7 /include/utils
parentbdce9baa880990f521061bc7d1498cb07d7efc01 (diff)
downloadsystem_core-5ca402a4e2537fa694de120264c5a5e2a4e777bf.zip
system_core-5ca402a4e2537fa694de120264c5a5e2a4e777bf.tar.gz
system_core-5ca402a4e2537fa694de120264c5a5e2a4e777bf.tar.bz2
Add LruCache::Iterator
Required by libhwui Change-Id: I164b9a4a82d89d132da01a56535c0df084de86f7
Diffstat (limited to 'include/utils')
-rw-r--r--include/utils/LruCache.h50
1 files changed, 26 insertions, 24 deletions
diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h
index 937fe1e..302b929 100644
--- a/include/utils/LruCache.h
+++ b/include/utils/LruCache.h
@@ -36,15 +36,38 @@ public:
void setOnEntryRemovedListener(OnEntryRemoved<TKey, TValue>* listener);
size_t size() const;
- const TKey& keyAt(size_t index) const;
- const TValue& valueAt(size_t index) const;
- void removeAt(size_t index);
const TValue& get(const TKey& key);
bool put(const TKey& key, const TValue& value);
bool remove(const TKey& key);
bool removeOldest();
void clear();
+ class Iterator {
+ public:
+ Iterator(const LruCache<TKey, TValue>& cache): mCache(cache), mIndex(-1) {
+ }
+
+ bool next() {
+ mIndex = mCache.mTable->next(mIndex);
+ return mIndex != -1;
+ }
+
+ size_t index() const {
+ return mIndex;
+ }
+
+ const TValue& value() const {
+ return mCache.mTable->entryAt(mIndex).value;
+ }
+
+ const TKey& key() const {
+ return mCache.mTable->entryAt(mIndex).key;
+ }
+ private:
+ const LruCache<TKey, TValue>& mCache;
+ size_t mIndex;
+ };
+
private:
LruCache(const LruCache& that); // disallow copy constructor
@@ -89,27 +112,6 @@ size_t LruCache<TKey, TValue>::size() const {
}
template <typename TKey, typename TValue>
-const TKey& LruCache<TKey, TValue>::keyAt(size_t index) const {
- const Entry& entry = mTable->entryAt(index);
- return entry.key;
-}
-
-template <typename TKey, typename TValue>
-const TValue& LruCache<TKey, TValue>::valueAt(size_t index) const {
- const Entry& entry = mTable->entryAt(index);
- return entry.value;
-}
-
-template <typename TKey, typename TValue>
-void LruCache<TKey, TValue>::removeAt(size_t index) {
- if (index < 0) {
- return;
- }
-
- mTable->removeAt(index);
-}
-
-template <typename TKey, typename TValue>
const TValue& LruCache<TKey, TValue>::get(const TKey& key) {
hash_t hash = hash_type(key);
ssize_t index = mTable->find(-1, hash, key);