forked from hkc/sfxd
1
0
Fork 0

Compare commits

...

5 Commits

Author SHA1 Message Date
Vftdan c3af4ce4be Also use exponential probing during lookups 2024-02-25 15:37:11 +01:00
Vftdan c5035fba81 Fix infinite loop in the fix from the last commit 2024-02-25 00:50:21 +01:00
Vftdan c118454ea5 Fix offset calculation to avoid additive identity of the ring
Zero is not a part of the multiplicative group of the ring
2024-02-25 00:42:09 +01:00
Vftdan 4fc7f1d043 Take `base` argument into parenthesis too in the macro 2024-02-24 23:56:56 +01:00
Vftdan 1e8bad5dd2 Create a macro for exponential probe loop 2024-02-24 23:51:45 +01:00
1 changed files with 6 additions and 6 deletions

View File

@ -16,6 +16,9 @@
#define MAX_SOUNDS_PER_KEY 32
#define MAX_SOURCE_DEPTH 32
// Set initial offset to size to distinguish start and end
#define FOR_OFFSET_PROBE(base, offset, index, size) for (int offset = 0, index = (base) % (size); offset >= 0; offset = ((offset + 1) << 1L) % (((size) + 1) | 1) - 1, offset = offset == (size) ? (size) - 1 /* n * 2 = n - 1 (mod n + 1) */ : offset, index = ((base) + offset) % (size), offset = offset == 0 ? -1 : offset)
struct msg_target {
FILE *file_handle;
int sock_fd;
@ -361,8 +364,7 @@ void sfx_pool_grow(int size) {
for (int i = 0; i < sounds_pool.cap; i++) {
if (sounds_pool.sounds[i].key[0] == '\0') continue;
uint32_t new_hash = adler32(sounds_pool.sounds[i].key, strlen(sounds_pool.sounds[i].key));
for (int offset = 0; offset < size; offset++) {
int index = (new_hash + offset) % size;
FOR_OFFSET_PROBE (new_hash, offset, index, size) {
#ifndef NO_COUNTERS
global_counters.pool_write++;
if (offset != 0) {
@ -386,8 +388,7 @@ void sfx_pool_grow(int size) {
struct sfx_pool_item *sfx_pool_lookup(const char *key) {
if (key == NULL) return NULL;
uint32_t hash = adler32(key, strlen(key));
for (int offset = 0; offset < sounds_pool.cap; offset++) {
int index = (hash + offset) % sounds_pool.cap;
FOR_OFFSET_PROBE (hash, offset, index, sounds_pool.cap) {
if (0 == strncmp(key, sounds_pool.sounds[index].key, KEY_LENGTH)) {
#ifndef NO_COUNTERS
global_counters.pool_read++;
@ -403,8 +404,7 @@ struct sfx_pool_item *sfx_pool_lookup(const char *key) {
struct sfx_pool_item *sfx_pool_find_place_for(const char *key) {
uint32_t hash = adler32(key, strlen(key));
for (int offset = 0; offset < sounds_pool.cap; offset++) {
int index = (hash + offset) % sounds_pool.cap;
FOR_OFFSET_PROBE (hash, offset, index, sounds_pool.cap) {
if (sounds_pool.sounds[index].key[0] == '\0' || 0 == strncmp(sounds_pool.sounds[index].key, key, KEY_LENGTH)) {
#ifndef NO_COUNTERS
global_counters.pool_write++;