Skip to content

Commit 0a08387

Browse files
Remove obsolete hash quality comparison
The projection test specifically required the rejected combine_hash implementation to outperform the restored combiner. Keep the functional chained-hashtable coverage while removing that incompatible A/B guard. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d32a199 commit 0a08387

1 file changed

Lines changed: 0 additions & 84 deletions

File tree

src/test/chashtable.cpp

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ Revision History:
2121
#include "util/hash.h"
2222
#include "util/util.h"
2323
#include <iostream>
24-
#include <cstdint>
25-
#include <vector>
2624

2725
typedef chashtable<int, int_hash, default_eq<int> > int_table;
2826
typedef cmap<int, int, int_hash, default_eq<int> > int_map;
@@ -174,87 +172,6 @@ static void tst6() {
174172
});
175173
}
176174

177-
static unsigned combine_hash_old(unsigned h1, unsigned h2) {
178-
// Pre-change combine_hash implementation kept for A/B quality checks.
179-
h2 -= h1; h2 ^= (h1 << 8);
180-
h1 -= h2; h2 ^= (h1 << 16);
181-
h2 -= h1; h2 ^= (h1 << 10);
182-
return h2;
183-
}
184-
185-
constexpr unsigned hash_compare_num_samples = 1u << 16;
186-
constexpr unsigned hash_compare_seed = 0x12345678u;
187-
constexpr unsigned hash_compare_alignment_shift = 12;
188-
189-
struct hash_projection_stats_t {
190-
unsigned m_occupied = 0;
191-
uint64_t m_uniform_error = 0;
192-
};
193-
194-
template<typename CombineHash>
195-
static hash_projection_stats_t get_projection_stats(CombineHash const& combine, unsigned bits, bool low_bits) {
196-
// Project hashes to either a suffix (low bits) or prefix (high bits), then
197-
// collect occupancy and a scaled squared-error uniformity score.
198-
SASSERT(bits <= 16);
199-
unsigned const num_buckets = 1u << bits;
200-
unsigned const mask = num_buckets - 1;
201-
int64_t const signed_num_samples = static_cast<int64_t>(hash_compare_num_samples);
202-
int64_t const signed_num_buckets = static_cast<int64_t>(num_buckets);
203-
std::vector<unsigned> counts(num_buckets, 0);
204-
for (unsigned i = 0; i < hash_compare_num_samples; ++i) {
205-
unsigned h = combine(i << hash_compare_alignment_shift, hash_compare_seed);
206-
unsigned b = low_bits ? (h & mask) : (h >> (32 - bits));
207-
counts[b]++;
208-
}
209-
210-
hash_projection_stats_t stats;
211-
for (unsigned c : counts) {
212-
if (c != 0)
213-
++stats.m_occupied;
214-
// Scaled squared deviation from ideal per-bucket load num_samples/num_buckets.
215-
int64_t diff = static_cast<int64_t>(c) * signed_num_buckets - signed_num_samples;
216-
stats.m_uniform_error += static_cast<uint64_t>(diff * diff);
217-
}
218-
return stats;
219-
}
220-
221-
static void tst_combine_hash_low_bits() {
222-
constexpr unsigned bits8 = 8;
223-
constexpr unsigned bits16 = 16;
224-
225-
auto old_low8 = get_projection_stats(combine_hash_old, bits8, true);
226-
auto new_low8 = get_projection_stats(combine_hash, bits8, true);
227-
auto old_low16 = get_projection_stats(combine_hash_old, bits16, true);
228-
auto new_low16 = get_projection_stats(combine_hash, bits16, true);
229-
auto old_high8 = get_projection_stats(combine_hash_old, bits8, false);
230-
auto new_high8 = get_projection_stats(combine_hash, bits8, false);
231-
auto old_high16 = get_projection_stats(combine_hash_old, bits16, false);
232-
auto new_high16 = get_projection_stats(combine_hash, bits16, false);
233-
234-
unsigned old_low8_collisions = hash_compare_num_samples - old_low8.m_occupied;
235-
unsigned new_low8_collisions = hash_compare_num_samples - new_low8.m_occupied;
236-
unsigned old_low16_collisions = hash_compare_num_samples - old_low16.m_occupied;
237-
unsigned new_low16_collisions = hash_compare_num_samples - new_low16.m_occupied;
238-
239-
ENSURE(new_low8_collisions < old_low8_collisions);
240-
ENSURE(new_low16_collisions < old_low16_collisions);
241-
ENSURE(new_low8.m_uniform_error < old_low8.m_uniform_error);
242-
ENSURE(new_low16.m_uniform_error < old_low16.m_uniform_error);
243-
244-
std::cout << "combine_hash old/new low8 collisions: "
245-
<< old_low8_collisions << "/" << new_low8_collisions << "\n";
246-
std::cout << "combine_hash old/new low16 collisions: "
247-
<< old_low16_collisions << "/" << new_low16_collisions << "\n";
248-
std::cout << "combine_hash old/new low8 uniform_error: "
249-
<< old_low8.m_uniform_error << "/" << new_low8.m_uniform_error << "\n";
250-
std::cout << "combine_hash old/new low16 uniform_error: "
251-
<< old_low16.m_uniform_error << "/" << new_low16.m_uniform_error << "\n";
252-
std::cout << "combine_hash old/new high8 uniform_error: "
253-
<< old_high8.m_uniform_error << "/" << new_high8.m_uniform_error << "\n";
254-
std::cout << "combine_hash old/new high16 uniform_error: "
255-
<< old_high16.m_uniform_error << "/" << new_high16.m_uniform_error << "\n";
256-
}
257-
258175
void tst_chashtable() {
259176
tst1();
260177
tst2();
@@ -263,6 +180,5 @@ void tst_chashtable() {
263180
tst4<dint_table>(1000,10);
264181
tst4<dint_table>(10000,10);
265182
tst4<int_table>(50000,1000);
266-
tst_combine_hash_low_bits();
267183
tst5();
268184
}

0 commit comments

Comments
 (0)