本文整理汇总了C++中KeyType::getHash方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyType::getHash方法的具体用法?C++ KeyType::getHash怎么用?C++ KeyType::getHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyType
的用法示例。
在下文中一共展示了KeyType::getHash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_binHashKey
static void test_binHashKey()
{
const char* testStringA = "abcdABCD";
const char* testStringB = "abcdBBCD";
enum {
kDataLenUsedForKey = 8
};
typedef GrBinHashKey<BogusEntry, kDataLenUsedForKey> KeyType;
KeyType keyA;
int passCnt = 0;
while (keyA.doPass()) {
++passCnt;
keyA.keyData(reinterpret_cast<const uint32_t*>(testStringA), kDataLenUsedForKey);
}
GrAssert(passCnt == 1); //We expect the static allocation to suffice
GrBinHashKey<BogusEntry, kDataLenUsedForKey-1> keyBust;
passCnt = 0;
while (keyBust.doPass()) {
++passCnt;
// Exceed static storage by 1
keyBust.keyData(reinterpret_cast<const uint32_t*>(testStringA), kDataLenUsedForKey);
}
GrAssert(passCnt == 2); //We expect dynamic allocation to be necessary
GrAssert(keyA.getHash() == keyBust.getHash());
// Test that adding keyData in chunks gives
// the same hash as with one chunk
KeyType keyA2;
while (keyA2.doPass()) {
keyA2.keyData(reinterpret_cast<const uint32_t*>(testStringA), 4);
keyA2.keyData(&reinterpret_cast<const uint32_t*>(testStringA)[4], kDataLenUsedForKey-4);
}
GrAssert(keyA.getHash() == keyA2.getHash());
KeyType keyB;
while (keyB.doPass()){
keyB.keyData(reinterpret_cast<const uint32_t*>(testStringB), kDataLenUsedForKey);
}
GrAssert(keyA.compare(keyB) < 0);
GrAssert(keyA.compare(keyA2) == 0);
//Test ownership tranfer and copying
keyB.copyAndTakeOwnership(keyA);
GrAssert(keyA.fIsValid == false);
GrAssert(keyB.fIsValid);
GrAssert(keyB.getHash() == keyA2.getHash());
GrAssert(keyB.compare(keyA2) == 0);
keyA.deepCopyFrom(keyB);
GrAssert(keyA.fIsValid);
GrAssert(keyB.fIsValid);
GrAssert(keyA.getHash() == keyA2.getHash());
GrAssert(keyA.compare(keyA2) == 0);
//Test ownership tranfer and copying with key on heap
GrBinHashKey<BogusEntry, kDataLenUsedForKey-1> keyBust2;
keyBust2.deepCopyFrom(keyBust);
GrAssert(keyBust.fIsValid);
GrAssert(keyBust2.fIsValid);
GrAssert(keyBust.getHash() == keyBust2.getHash());
GrAssert(keyBust.compare(keyBust2) == 0);
GrBinHashKey<BogusEntry, kDataLenUsedForKey-1> keyBust3;
keyBust3.deepCopyFrom(keyBust);
GrAssert(keyBust.fIsValid == false);
GrAssert(keyBust3.fIsValid);
GrAssert(keyBust3.getHash() == keyBust2.getHash());
GrAssert(keyBust3.compare(keyBust2) == 0);
}