forked from hkc/sfxd
1
0
Fork 0

Compare commits

..

No commits in common. "exponential-probe-test" and "master" have entirely different histories.

1 changed files with 6 additions and 6 deletions

View File

@ -16,9 +16,6 @@
#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;
@ -364,7 +361,8 @@ 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_OFFSET_PROBE (new_hash, offset, index, size) {
for (int offset = 0; offset < size; offset++) {
int index = (new_hash + offset) % size;
#ifndef NO_COUNTERS
global_counters.pool_write++;
if (offset != 0) {
@ -388,7 +386,8 @@ 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_OFFSET_PROBE (hash, offset, index, sounds_pool.cap) {
for (int offset = 0; offset < sounds_pool.cap; offset++) {
int index = (hash + offset) % sounds_pool.cap;
if (0 == strncmp(key, sounds_pool.sounds[index].key, KEY_LENGTH)) {
#ifndef NO_COUNTERS
global_counters.pool_read++;
@ -404,7 +403,8 @@ 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_OFFSET_PROBE (hash, offset, index, sounds_pool.cap) {
for (int offset = 0; offset < sounds_pool.cap; offset++) {
int index = (hash + offset) % 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++;