mirror of
https://github.com/mmp/pbrt-v4
synced 2026-09-26 16:20:07 +03:00
Fix HashBuffer to include sizeof(T) in size passed to MurmurHash64A.
Updated callers in test code that weren't expecting this. (Callers in existing code were expecting it but not getting it!) Fixes #487.
This commit is contained in:
parent
85918d59e4
commit
0d6d9573e9
2 changed files with 4 additions and 4 deletions
|
|
@ -77,8 +77,8 @@ inline uint64_t MixBits(uint64_t v) {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
PBRT_CPU_GPU inline uint64_t HashBuffer(const T *ptr, size_t size, uint64_t seed = 0) {
|
||||
return MurmurHash64A((const unsigned char *)ptr, size, seed);
|
||||
PBRT_CPU_GPU inline uint64_t HashBuffer(const T *ptr, size_t nElements, uint64_t seed = 0) {
|
||||
return MurmurHash64A((const unsigned char *)ptr, nElements * sizeof(T), seed);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using namespace pbrt;
|
|||
TEST(Hash, VarArgs) {
|
||||
int64_t buf[] = {1, -12511, 31415821, 37};
|
||||
for (int i = 0; i < 4; ++i)
|
||||
EXPECT_EQ(HashBuffer(buf + i, sizeof(int64_t)), Hash(buf[i]));
|
||||
EXPECT_EQ(HashBuffer(buf + i, 1), Hash(buf[i]));
|
||||
}
|
||||
|
||||
TEST(Hash, Collisions) {
|
||||
|
|
@ -50,6 +50,6 @@ TEST(Hash, Unaligned) {
|
|||
char cbuf[sizeof(buf) + 8];
|
||||
for (int delta = 0; delta < 8; ++delta) {
|
||||
memcpy(cbuf + delta, buf, sizeof(buf));
|
||||
EXPECT_EQ(HashBuffer(buf, sizeof(buf)), HashBuffer(cbuf + delta, sizeof(buf)));
|
||||
EXPECT_EQ(HashBuffer(buf, 3), HashBuffer(cbuf + delta, sizeof(buf)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue