3 * Copyright 2011 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
10 #ifndef GrBinHashKey_DEFINED
11 #define GrBinHashKey_DEFINED
16 * GrBinHashKey is a hash key class that can take a data chunk of any predetermined
17 * length. The hash function used is the One-at-a-Time Hash
18 * (http://burtleburtle.net/bob/hash/doobs.html).
20 template<size_t KEY_SIZE>
23 enum { kKeySize = KEY_SIZE };
36 void setKeyData(const uint32_t* SK_RESTRICT data) {
37 SK_COMPILE_ASSERT(KEY_SIZE % 4 == 0, key_size_mismatch);
38 memcpy(&fData, data, KEY_SIZE);
41 size_t len = KEY_SIZE;
57 bool operator==(const GrBinHashKey<KEY_SIZE>& key) const {
58 SkASSERT(fIsValid && key.fIsValid);
59 if (fHash != key.fHash) {
62 for (size_t i = 0; i < SK_ARRAY_COUNT(fData); ++i) {
63 if (fData[i] != key.fData[i]) {
70 bool operator<(const GrBinHashKey<KEY_SIZE>& key) const {
71 SkASSERT(fIsValid && key.fIsValid);
72 for (size_t i = 0; i < SK_ARRAY_COUNT(fData); ++i) {
73 if (fData[i] < key.fData[i]) {
75 } else if (fData[i] > key.fData[i]) {
82 uint32_t getHash() const {
87 const uint8_t* getData() const {
89 return reinterpret_cast<const uint8_t*>(fData);
94 uint32_t fData[KEY_SIZE / sizeof(uint32_t)]; // Buffer for key storage.