Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: src/core/SkTDynamicHash.h

Issue 21028008: add dox to SkTDynamicHash, fix typo of Key instead of KEY (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTDynamicHash.h
diff --git a/src/core/SkTDynamicHash.h b/src/core/SkTDynamicHash.h
index 823fde8db1a0be681c47cc8e6457c574dff268e9..b3d4b26476b34ede5c39d9b6d2699da1cd2c4911 100644
--- a/src/core/SkTDynamicHash.h
+++ b/src/core/SkTDynamicHash.h
@@ -10,21 +10,32 @@
#include "SkTypes.h"
-template <typename T, typename KEY, const KEY& (KEY_FROM_T)(const T&),
-uint32_t (HASH_FROM_KEY)(const Key&), bool (EQ_T_KEY)(const T&, const Key&)>
+template <typename T,
+ typename KEY,
+ const KEY& (KEY_FROM_T)(const T&),
+ uint32_t (HASH_FROM_KEY)(const KEY&),
+ bool (EQ_T_KEY)(const T&, const KEY&)>
class SkTDynamicHash {
private:
- T* fStorage[4];
+ T* fStorage[4]; // cheap storage for small arrays
T** fArray;
- int fCapacity;
- int fCountUsed;
- int fCountDeleted;
+ int fCapacity; // number of slots in fArray. Must be pow2
+ int fCountUsed; // number of valid entries in fArray
+ int fCountDeleted; // number of deletedValue() entries in fArray
+ // Need an illegal ptr value different from NULL (which we use to
+ // signal empty/unused.
mtklein 2013/07/29 18:51:22 add a ) ?
const T* deletedValue() const { return reinterpret_cast<const T*>(-1); }
+
+ // fCapacity is a pow2, so that minus one is a clean mask to grab
+ // the low bits of hash to use as an index.
uint32_t hashMask() const { return fCapacity - 1; }
+
int hashToIndex(uint32_t hash) const {
- return ((hash >> 16) ^ hash) & (fCapacity - 1);
+ // this 16bit fold may be overkill, if we trust that hash is good
+ return ((hash >> 16) ^ hash) & this->hashMask();
}
+
public:
SkTDynamicHash() {
sk_bzero(fStorage, sizeof(fStorage));
@@ -112,7 +123,7 @@ public:
}
private:
- int countCollisions(const Key& key) const {
+ int countCollisions(const KEY& key) const {
const T* const deleted = this->deletedValue();
const unsigned mask = this->hashMask();
int index = this->hashToIndex(HASH_FROM_KEY(key));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698