diff options
author | 2012-11-28 17:37:03 -0800 | |
---|---|---|
committer | 2012-11-28 17:37:03 -0800 | |
commit | e402f1fde2deca0b1120e6d582ab9dce59879ae1 (patch) | |
tree | 69654c790917913b464ed59c26070655abe5a20f | |
parent | 98fc88d3ce6c8e177afd91d4a80ad71a9f9af2af (diff) |
Add another ifndef and a couple of methods to LruCache
The new methods on LruCache are needed by libhwui to manage
the cache of paths.
Change-Id: If54fa325c54e2b04e7fe5dfe6dad66066c40127c
-rw-r--r-- | include/utils/JenkinsHash.h | 4 | ||||
-rw-r--r-- | include/utils/LruCache.h | 24 |
2 files changed, 28 insertions, 0 deletions
diff --git a/include/utils/JenkinsHash.h b/include/utils/JenkinsHash.h index e964e6f926..7da5dbd6a9 100644 --- a/include/utils/JenkinsHash.h +++ b/include/utils/JenkinsHash.h @@ -19,6 +19,9 @@ * should still be quite good. **/ +#ifndef ANDROID_JENKINS_HASH_H +#define ANDROID_JENKINS_HASH_H + #include <utils/TypeHelpers.h> namespace android { @@ -42,3 +45,4 @@ uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size } +#endif // ANDROID_JENKINS_HASH_H diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h index 2a70d760aa..937fe1e01c 100644 --- a/include/utils/LruCache.h +++ b/include/utils/LruCache.h @@ -36,6 +36,9 @@ 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); @@ -86,6 +89,27 @@ 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); |