1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-07-19 09:22:49 +00:00

improved buckethash

This commit is contained in:
Zeno Rogue 2025-06-07 16:18:00 +02:00
parent bf5e61d4bd
commit c8483b570c
2 changed files with 24 additions and 15 deletions

View File

@ -1834,22 +1834,31 @@ EX ld raddif(ld a, ld b) {
EX int bucket_scale = 10000;
EX unsigned bucketer(ld x) {
return (unsigned) (long long) (floor(x * bucket_scale + .5));
#if HDR
using buckethash_t = uint64_t;
inline void hashmix(buckethash_t& seed, buckethash_t i) { seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2); }
inline buckethash_t hashmix_to(buckethash_t seed, buckethash_t i) { hashmix(seed, i); return seed; }
#endif
EX buckethash_t bucketer(ld x) {
return (buckethash_t) (long long) (floor(x * bucket_scale + .5));
}
EX unsigned bucketer(hyperpoint h) {
unsigned dx = 0;
EX buckethash_t bucketer(hyperpoint h) {
buckethash_t seed = 0;
if(gproduct) {
auto d = product_decompose(h);
h = d.second;
dx += bucketer(d.first) * 50;
hashmix(seed, bucketer(d.first));
if(cgi.emb->is_euc_in_product() && in_h2xe()) h /= h[2];
}
dx += bucketer(h[0]) + 1000 * bucketer(h[1]) + 1000000 * bucketer(h[2]);
if(MDIM == 4) dx += bucketer(h[3]) * 1000000001;
if(elliptic) dx = min(dx, -dx);
return dx;
if(elliptic && make_tuple(h[0], h[1], h[2], h[3]) < make_tuple(-h[0], -h[1], -h[2], -h[3])) h = -h;
hashmix(seed, bucketer(h[0]));
hashmix(seed, bucketer(h[1]));
hashmix(seed, bucketer(h[2]));
if(MDIM == 4) hashmix(seed, bucketer(h[3]));
return seed;
}
#if MAXMDIM >= 4

View File

@ -3272,12 +3272,12 @@ EX shiftmatrix optimized_shift(const shiftmatrix& T) {
EX namespace dq {
EX queue<pair<heptagon*, shiftmatrix>> drawqueue;
EX unsigned bucketer(const shiftpoint& T) {
EX buckethash_t bucketer(const shiftpoint& T) {
if(cgi.emb->is_euc_in_sl2()) {
auto T1 = T; optimize_shift(T1);
return bucketer(T1.h) + unsigned(floor(T1.shift*81527+.5));
return hashmix_to(bucketer(T1.h), hr::bucketer(T1.shift));
}
return bucketer(T.h) + unsigned(floor(T.shift*81527+.5));
return hashmix_to(bucketer(T.h), hr::bucketer(T.shift));
}
EX set<heptagon*> visited;
@ -3287,10 +3287,10 @@ EX namespace dq {
drawqueue.emplace(h, T);
}
EX set<unsigned> visited_by_matrix;
EX set<buckethash_t> visited_by_matrix;
EX void enqueue_by_matrix(heptagon *h, const shiftmatrix& T) {
if(!h) return;
unsigned b = bucketer(T * tile_center());
buckethash_t b = bucketer(T * tile_center());
if(visited_by_matrix.count(b)) { return; }
visited_by_matrix.insert(b);
drawqueue.emplace(h, T);
@ -3307,7 +3307,7 @@ EX namespace dq {
EX void enqueue_by_matrix_c(cell *c, const shiftmatrix& T) {
if(!c) return;
unsigned b = bucketer(T * tile_center());
buckethash_t b = bucketer(T * tile_center());
if(visited_by_matrix.count(b)) { return; }
visited_by_matrix.insert(b);
drawqueue_c.emplace(c, T);