use only generic structures

This commit is contained in:
Alessandro Mauri 2023-03-07 23:05:58 +01:00
parent 440e4499c7
commit 6503897ece
No known key found for this signature in database
GPG key ID: 2B7BF9531FF03BE8
7 changed files with 35 additions and 121 deletions

View file

@ -14,21 +14,21 @@
/* Ready-made compares */
int hash_compare_u32(unsigned int a, unsigned int b) { return a == b; }
int hash_compare_u64(unsigned long long int a, unsigned long long int b) { return a == b; }
int hash_compare_str(const char *a, const char *b) { return strcmp(a, b) == 0; }
static int hash_cp_u32(unsigned int a, unsigned int b) { return a == b; }
static int hash_cp_u64(unsigned long long int a, unsigned long long int b) { return a == b; }
static int hash_cp_str(const char *a, const char *b) { return strcmp(a, b) == 0; }
/* Ready-made hashes */
unsigned int hash_u64(unsigned long long int c)
static unsigned int hash_u64(unsigned long long int c)
{
return (unsigned long long int)((unsigned long long int)(c*HASH_RATIO64)>>32);
}
unsigned int hash_u32(unsigned int c)
static unsigned int hash_u32(unsigned int c)
{
return (unsigned int)((unsigned long long int)(c*HASH_RATIO32)>>32);
}
unsigned int hash_str(const char *s)
static unsigned int hash_str(const char *s)
{
unsigned int h = HASH_STRSALT;
const unsigned char *v = (const unsigned char *)(s);
@ -76,7 +76,7 @@ struct hashname##_ref * hashname##_create(unsigned int size, unsigned int (*hash
h->size = size; \
h->hash = hash; \
h->compare = compare; \
memset(h->bucket, 0, sizeof(struct hashname##_ref)*size); \
memset(h->bucket, 0, sizeof(struct hashname##_entry)*size); \
} \
return h; \
} \