Skip to content

Commit 0d6d957

Browse files
committed
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.
1 parent 85918d5 commit 0d6d957

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/pbrt/util/hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ inline uint64_t MixBits(uint64_t v) {
7777
}
7878

7979
template <typename T>
80-
PBRT_CPU_GPU inline uint64_t HashBuffer(const T *ptr, size_t size, uint64_t seed = 0) {
81-
return MurmurHash64A((const unsigned char *)ptr, size, seed);
80+
PBRT_CPU_GPU inline uint64_t HashBuffer(const T *ptr, size_t nElements, uint64_t seed = 0) {
81+
return MurmurHash64A((const unsigned char *)ptr, nElements * sizeof(T), seed);
8282
}
8383

8484
template <typename... Args>

src/pbrt/util/hash_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace pbrt;
1313
TEST(Hash, VarArgs) {
1414
int64_t buf[] = {1, -12511, 31415821, 37};
1515
for (int i = 0; i < 4; ++i)
16-
EXPECT_EQ(HashBuffer(buf + i, sizeof(int64_t)), Hash(buf[i]));
16+
EXPECT_EQ(HashBuffer(buf + i, 1), Hash(buf[i]));
1717
}
1818

1919
TEST(Hash, Collisions) {
@@ -50,6 +50,6 @@ TEST(Hash, Unaligned) {
5050
char cbuf[sizeof(buf) + 8];
5151
for (int delta = 0; delta < 8; ++delta) {
5252
memcpy(cbuf + delta, buf, sizeof(buf));
53-
EXPECT_EQ(HashBuffer(buf, sizeof(buf)), HashBuffer(cbuf + delta, sizeof(buf)));
53+
EXPECT_EQ(HashBuffer(buf, 3), HashBuffer(cbuf + delta, sizeof(buf)));
5454
}
5555
}

0 commit comments

Comments
 (0)