Use uint32_t for hashtable indicies

This commit is contained in:
Vladimir Dubrovin 2026-04-18 15:36:14 +03:00
parent bba9871ed8
commit 260cbf7a3d
2 changed files with 11 additions and 11 deletions

View File

@ -1,7 +1,7 @@
#include "proxy.h" #include "proxy.h"
#include "libs/blake2.h" #include "libs/blake2.h"
static unsigned hashindex(struct hashtable *ht, const uint8_t* hash){ static uint32_t hashindex(struct hashtable *ht, const uint8_t* hash){
return (*(unsigned *)hash ) % (ht->tablesize); return (*(unsigned *)hash ) % (ht->tablesize);
} }
@ -80,7 +80,7 @@ int inithashtable(struct hashtable *ht, unsigned nhashsize){
static void hashcompact(struct hashtable *ht){ static void hashcompact(struct hashtable *ht){
int i; int i;
int he, *hep; uint32_t he, *hep;
if((conf.time - ht->compacted) < 60 || !ht->tablesize || !ht->hashsize || ht->hashsize/ht->tablesize >= 4 ) return; if((conf.time - ht->compacted) < 60 || !ht->tablesize || !ht->hashsize || ht->hashsize/ht->tablesize >= 4 ) return;
for(i = 0; i < ht->tablesize; i++){ for(i = 0; i < ht->tablesize; i++){
@ -98,10 +98,10 @@ static void hashcompact(struct hashtable *ht){
} }
void hashadd(struct hashtable *ht, const void* name, const void* value, time_t expires){ void hashadd(struct hashtable *ht, const void* name, const void* value, time_t expires){
int hen, he; uint32_t hen, he;
int *hep; uint32_t *hep;
unsigned index; uint32_t index;
pthread_mutex_lock(&hash_mutex); pthread_mutex_lock(&hash_mutex);
if(!ht->ihashempty){ if(!ht->ihashempty){
@ -135,9 +135,9 @@ void hashadd(struct hashtable *ht, const void* name, const void* value, time_t e
int hashresolv(struct hashtable *ht, const void* name, void* value, uint32_t *ttl){ int hashresolv(struct hashtable *ht, const void* name, void* value, uint32_t *ttl){
uint8_t hash[HASH_SIZE]; uint8_t hash[HASH_SIZE];
int *hep; uint32_t *hep;
int he; uint32_t he;
unsigned index; uint32_t index;
pthread_mutex_lock(&hash_mutex); pthread_mutex_lock(&hash_mutex);
if(!ht || !ht->ihashtable || !name) { if(!ht || !ht->ihashtable || !name) {

View File

@ -759,7 +759,7 @@ struct child {
struct hashentry { struct hashentry {
uint8_t hash[HASH_SIZE]; uint8_t hash[HASH_SIZE];
time_t expires; time_t expires;
int inext; uint32_t inext;
char value[4]; char value[4];
}; };
@ -767,9 +767,9 @@ struct hashtable {
unsigned hashsize; unsigned hashsize;
unsigned recsize; unsigned recsize;
unsigned rnd[4]; unsigned rnd[4];
int * ihashtable; uint32_t * ihashtable;
uint8_t * hashvalues; uint8_t * hashvalues;
int ihashempty; uint32_t ihashempty;
void (*index2hash)(const void *index, unsigned char *hash, const unsigned char *rnd); void (*index2hash)(const void *index, unsigned char *hash, const unsigned char *rnd);
int grow; int grow;
time_t compacted; time_t compacted;