Remove GrBinHashKey
Review URL: https://codereview.chromium.org/861323002
This commit is contained in:
parent
016dffb7b3
commit
1ea1ebce10
@ -8,7 +8,6 @@
|
||||
{
|
||||
'variables': {
|
||||
'skgpu_sources': [
|
||||
'<(skia_include_path)/gpu/GrBinHashKey.h',
|
||||
'<(skia_include_path)/gpu/GrClipData.h',
|
||||
'<(skia_include_path)/gpu/GrColor.h',
|
||||
'<(skia_include_path)/gpu/GrConfig.h',
|
||||
|
@ -106,7 +106,6 @@
|
||||
'../tests/GpuDrawPathTest.cpp',
|
||||
'../tests/GpuLayerCacheTest.cpp',
|
||||
'../tests/GpuRectanizerTest.cpp',
|
||||
'../tests/GrBinHashKeyTest.cpp',
|
||||
'../tests/GrContextFactoryTest.cpp',
|
||||
'../tests/GrDrawTargetTest.cpp',
|
||||
'../tests/GrAllocatorTest.cpp',
|
||||
|
@ -1,102 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GrBinHashKey_DEFINED
|
||||
#define GrBinHashKey_DEFINED
|
||||
|
||||
#include "GrTypes.h"
|
||||
|
||||
/**
|
||||
* GrBinHashKey is a hash key class that can take a data chunk of any predetermined
|
||||
* length. The hash function used is the One-at-a-Time Hash
|
||||
* (http://burtleburtle.net/bob/hash/doobs.html).
|
||||
*/
|
||||
template<size_t KEY_SIZE>
|
||||
class GrBinHashKey {
|
||||
public:
|
||||
enum { kKeySize = KEY_SIZE };
|
||||
|
||||
GrBinHashKey() {
|
||||
this->reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
fHash = 0;
|
||||
#ifdef SK_DEBUG
|
||||
fIsValid = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void setKeyData(const uint32_t* SK_RESTRICT data) {
|
||||
SK_COMPILE_ASSERT(KEY_SIZE % 4 == 0, key_size_mismatch);
|
||||
memcpy(&fData, data, KEY_SIZE);
|
||||
|
||||
uint32_t hash = 0;
|
||||
size_t len = KEY_SIZE;
|
||||
while (len >= 4) {
|
||||
hash += *data++;
|
||||
hash += (hash << 10);
|
||||
hash ^= (hash >> 6);
|
||||
len -= 4;
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash >> 11);
|
||||
hash += (hash << 15);
|
||||
#ifdef SK_DEBUG
|
||||
fIsValid = true;
|
||||
#endif
|
||||
fHash = hash;
|
||||
}
|
||||
|
||||
bool operator==(const GrBinHashKey<KEY_SIZE>& key) const {
|
||||
SkASSERT(fIsValid && key.fIsValid);
|
||||
if (fHash != key.fHash) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fData); ++i) {
|
||||
if (fData[i] != key.fData[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator<(const GrBinHashKey<KEY_SIZE>& key) const {
|
||||
SkASSERT(fIsValid && key.fIsValid);
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fData); ++i) {
|
||||
if (fData[i] < key.fData[i]) {
|
||||
return true;
|
||||
} else if (fData[i] > key.fData[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t getHash() const {
|
||||
SkASSERT(fIsValid);
|
||||
return fHash;
|
||||
}
|
||||
|
||||
const uint8_t* getData() const {
|
||||
SkASSERT(fIsValid);
|
||||
return reinterpret_cast<const uint8_t*>(fData);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t fHash;
|
||||
uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key storage.
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
public:
|
||||
bool fIsValid;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "GrTypes.h"
|
||||
#include "SkTemplates.h"
|
||||
#include "GrBinHashKey.h"
|
||||
|
||||
uint32_t GrResourceKeyHash(const uint32_t* data, size_t size);
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
/**
|
||||
* GrMurmur3HashKey is a hash key class that can take a data chunk of any predetermined
|
||||
* length. It uses the Murmur3 hash function. It is intended to be used with
|
||||
* SkTDynamicHash (where GrBinHashKey is for GrTHashTable).
|
||||
* SkTDynamicHash.
|
||||
*/
|
||||
template<size_t KEY_SIZE_IN_BYTES>
|
||||
class GrMurmur3HashKey {
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
// This is a GPU-backend specific test
|
||||
#if SK_SUPPORT_GPU
|
||||
|
||||
#include "GrMurmur3HashKey.h"
|
||||
#include "GrBinHashKey.h"
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
struct AlignedKey {
|
||||
uint32_t align;
|
||||
char key[8];
|
||||
};
|
||||
|
||||
template<typename KeyType> static void TestHash(skiatest::Reporter* reporter) {
|
||||
AlignedKey a, b;
|
||||
memcpy(&a.key, "abcdABCD", 8);
|
||||
memcpy(&b.key, "abcdBBCD", 8);
|
||||
const uint32_t* testStringA = reinterpret_cast<const uint32_t*>(&a.key);
|
||||
const uint32_t* testStringB = reinterpret_cast<const uint32_t*>(&b.key);
|
||||
|
||||
KeyType keyA;
|
||||
keyA.setKeyData(testStringA);
|
||||
// test copy constructor and comparison
|
||||
KeyType keyA2(keyA);
|
||||
REPORTER_ASSERT(reporter, keyA == keyA2);
|
||||
REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
|
||||
// test re-init
|
||||
keyA2.setKeyData(testStringA);
|
||||
REPORTER_ASSERT(reporter, keyA == keyA2);
|
||||
REPORTER_ASSERT(reporter, keyA.getHash() == keyA2.getHash());
|
||||
// test sorting
|
||||
KeyType keyB;
|
||||
keyB.setKeyData(testStringB);
|
||||
REPORTER_ASSERT(reporter, keyA.getHash() != keyB.getHash());
|
||||
}
|
||||
|
||||
|
||||
DEF_TEST(GrBinHashKey, reporter) {
|
||||
enum {
|
||||
kDataLenUsedForKey = 8
|
||||
};
|
||||
|
||||
TestHash<GrBinHashKey<kDataLenUsedForKey> >(reporter);
|
||||
TestHash<GrMurmur3HashKey<kDataLenUsedForKey> >(reporter);
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user