All implementations are relying on bool operator==(const Key&, const Key&)
anyway, which makes total sense, so just make that required.
BUG=skia:
R=bsalomon@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/
222343002
git-svn-id: http://skia.googlecode.com/svn/trunk@14027
2bbb7eff-a529-9590-31e7-
b0007b416f81
// For SkTDynamicHash.
static const SkFlatData& Identity(const SkFlatData& flat) { return flat; }
static uint32_t Hash(const SkFlatData& flat) { return flat.checksum(); }
- static bool Equal(const SkFlatData& a, const SkFlatData& b) { return a == b; }
void setIndex(int index) { fIndex = index; }
uint8_t* data() { return (uint8_t*)this + sizeof(*this); }
SkTDArray<const SkFlatData*> fIndexedData;
// For SkFlatData -> cached SkFlatData, which has index().
- SkTDynamicHash<SkFlatData, SkFlatData,
- SkFlatData::Identity, SkFlatData::Hash, SkFlatData::Equal> fHash;
+ SkTDynamicHash<SkFlatData, SkFlatData, SkFlatData::Identity, SkFlatData::Hash> fHash;
};
typedef SkFlatDictionary<SkPaint, SkPaint::FlatteningTraits> SkPaintDictionary;
return key.fHash;
}
-bool eq_rec_key(const SkScaledImageCache::Rec& rec, const SkScaledImageCache::Key& key) {
- return rec.fKey == key;
-}
-}
+} // namespace
class SkScaledImageCache::Hash : public SkTDynamicHash<SkScaledImageCache::Rec,
SkScaledImageCache::Key,
key_from_rec,
- hash_from_key,
- eq_rec_key> {};
+ hash_from_key> {};
+
///////////////////////////////////////////////////////////////////////////////
typename Key,
const Key& (GetKey)(const T&),
uint32_t (Hash)(const Key&),
- bool (Equal)(const T&, const Key&),
int kGrowPercent = 75> // Larger -> more memory efficient, but slower.
class SkTDynamicHash {
public:
if (Empty() == candidate) {
return NULL;
}
- if (Deleted() != candidate && Equal(*candidate, key)) {
+ if (Deleted() != candidate && GetKey(*candidate) == key) {
return candidate;
}
index = this->nextIndex(index, round);
int index = this->firstIndex(key);
for (int round = 0; round < fCapacity; round++) {
const T* candidate = fArray[index];
- if (Empty() == candidate || Deleted() == candidate || Equal(*candidate, key)) {
+ if (Empty() == candidate || Deleted() == candidate || GetKey(*candidate) == key) {
return round;
}
index = this->nextIndex(index, round);
continue;
}
SKTDYNAMICHASH_CHECK(fArray[i] != fArray[j]);
- SKTDYNAMICHASH_CHECK(!Equal(*fArray[i], GetKey(*fArray[j])));
- SKTDYNAMICHASH_CHECK(!Equal(*fArray[j], GetKey(*fArray[i])));
+ SKTDYNAMICHASH_CHECK(!(GetKey(*fArray[i]) == GetKey(*fArray[j])));
}
}
}
int index = firstIndex;
for (int round = 0; round < fCapacity; round++) {
const T* candidate = fArray[index];
- if (Deleted() != candidate && Equal(*candidate, key)) {
+ if (Deleted() != candidate && GetKey(*candidate) == key) {
fDeleted++;
fCount--;
fArray[index] = Deleted();
static const GrResourceKey& GetKey(const GrResourceEntry& e) { return e.key(); }
static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
- static bool Equal(const GrResourceEntry& a, const GrResourceKey& b) {
- return a.key() == b;
- }
#ifdef SK_DEBUG
void validate() const;
#else
GrTMultiMap<GrResourceEntry,
GrResourceKey,
GrResourceEntry::GetKey,
- GrResourceEntry::Hash,
- GrResourceEntry::Equal> fCache;
+ GrResourceEntry::Hash> fCache;
// We're an internal doubly linked list
typedef SkTInternalLList<GrResourceEntry> EntryList;
template <typename T,
typename Key,
const Key& (GetKey)(const T&),
- uint32_t (Hash)(const Key&),
- bool (Equal)(const T&, const Key&)>
+ uint32_t (Hash)(const Key&)>
class GrTMultiMap {
struct ValueList {
explicit ValueList(T* value) : fValue(value), fNext(NULL) {}
static const Key& ListGetKey(const ValueList& e) { return GetKey(*e.fValue); }
static uint32_t ListHash(const Key& key) { return Hash(key); }
- static bool ListEqual(const ValueList& a, const Key& b) {
- return Equal(*a.fValue, b);
- }
T* fValue;
ValueList* fNext;
};
SkTDynamicHash<ValueList,
Key,
ValueList::ListGetKey,
- ValueList::ListHash,
- ValueList::ListEqual> fHash;
+ ValueList::ListHash> fHash;
int fCount;
};
const int& GetKey(const Entry& entry) { return entry.key; }
uint32_t GetHash(const int& key) { return key; }
-bool AreEqual(const Entry& entry, const int& key) { return entry.key == key; }
-class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> {
+class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash> {
public:
Hash() : INHERITED() {}
int countCollisions(const int& key) const { return this->INHERITED::countCollisions(key); }
private:
- typedef SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> INHERITED;
+ typedef SkTDynamicHash<Entry, int, GetKey, GetHash> INHERITED;
};
} // namespace