gallium/hash_table: use the same callback signatures as util/hash_table

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3722>
This commit is contained in:
Marek Olšák 2020-02-05 14:19:40 -05:00 committed by Marge Bot
parent 76dff2fabe
commit 10d235a843
5 changed files with 40 additions and 40 deletions

View file

@ -57,10 +57,10 @@ struct util_hash_table
struct cso_hash cso;
/** Hash function */
unsigned (*hash)(void *key);
uint32_t (*hash)(const void *key);
/** Compare two keys */
int (*compare)(void *key1, void *key2);
bool (*equal)(const void *key1, const void *key2);
/* TODO: key, value destructors? */
};
@ -81,8 +81,8 @@ util_hash_table_item(struct cso_hash_iter iter)
struct util_hash_table *
util_hash_table_create(unsigned (*hash)(void *key),
int (*compare)(void *key1, void *key2))
util_hash_table_create(uint32_t (*hash)(const void *key),
bool (*equal)(const void *key1, const void *key2))
{
struct util_hash_table *ht;
@ -93,34 +93,34 @@ util_hash_table_create(unsigned (*hash)(void *key),
cso_hash_init(&ht->cso);
ht->hash = hash;
ht->compare = compare;
ht->equal = equal;
return ht;
}
static unsigned
pointer_hash(void *key)
static uint32_t
pointer_hash(const void *key)
{
return _mesa_hash_pointer(key);
}
static int
pointer_compare(void *a, void *b)
static bool
pointer_equal(const void *a, const void *b)
{
return a != b;
return a == b;
}
struct util_hash_table *
util_hash_table_create_ptr_keys(void)
{
return util_hash_table_create(pointer_hash, pointer_compare);
return util_hash_table_create(pointer_hash, pointer_equal);
}
static unsigned hash_fd(void *key)
static uint32_t hash_fd(const void *key)
{
#if DETECT_OS_UNIX
int fd = pointer_to_intptr(key);
@ -135,7 +135,7 @@ static unsigned hash_fd(void *key)
}
static int compare_fd(void *key1, void *key2)
static bool equal_fd(const void *key1, const void *key2)
{
#if DETECT_OS_UNIX
int fd1 = pointer_to_intptr(key1);
@ -145,9 +145,9 @@ static int compare_fd(void *key1, void *key2)
fstat(fd1, &stat1);
fstat(fd2, &stat2);
return stat1.st_dev != stat2.st_dev ||
stat1.st_ino != stat2.st_ino ||
stat1.st_rdev != stat2.st_rdev;
return stat1.st_dev == stat2.st_dev &&
stat1.st_ino == stat2.st_ino &&
stat1.st_rdev == stat2.st_rdev;
#else
return 0;
#endif
@ -157,7 +157,7 @@ static int compare_fd(void *key1, void *key2)
struct util_hash_table *
util_hash_table_create_fd_keys(void)
{
return util_hash_table_create(hash_fd, compare_fd);
return util_hash_table_create(hash_fd, equal_fd);
}
@ -172,7 +172,7 @@ util_hash_table_find_iter(struct util_hash_table *ht,
iter = cso_hash_find(&ht->cso, key_hash);
while (!cso_hash_iter_is_null(iter)) {
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
if (!ht->compare(item->key, key))
if (ht->equal(item->key, key))
break;
iter = cso_hash_iter_next(iter);
}
@ -192,7 +192,7 @@ util_hash_table_find_item(struct util_hash_table *ht,
iter = cso_hash_find(&ht->cso, key_hash);
while (!cso_hash_iter_is_null(iter)) {
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
if (!ht->compare(item->key, key))
if (ht->equal(item->key, key))
return item;
iter = cso_hash_iter_next(iter);
}

View file

@ -53,11 +53,11 @@ struct util_hash_table;
* Create an hash table.
*
* @param hash hash function
* @param compare should return 0 for two equal keys.
* @param equal should return true for two equal keys.
*/
struct util_hash_table *
util_hash_table_create(unsigned (*hash)(void *key),
int (*compare)(void *key1, void *key2));
util_hash_table_create(uint32_t (*hash)(const void *key),
bool (*equal)(const void *key1, const void *key2));
/**
* Create a hash table where the keys are generic pointers.

View file

@ -124,7 +124,7 @@ struct nine_ff_ps_key
};
};
static unsigned nine_ff_vs_key_hash(void *key)
static uint32_t nine_ff_vs_key_hash(const void *key)
{
struct nine_ff_vs_key *vs = key;
unsigned i;
@ -133,14 +133,14 @@ static unsigned nine_ff_vs_key_hash(void *key)
hash ^= vs->value32[i];
return hash;
}
static int nine_ff_vs_key_comp(void *key1, void *key2)
static bool nine_ff_vs_key_comp(const void *key1, const void *key2)
{
struct nine_ff_vs_key *a = (struct nine_ff_vs_key *)key1;
struct nine_ff_vs_key *b = (struct nine_ff_vs_key *)key2;
return memcmp(a->value64, b->value64, sizeof(a->value64));
return memcmp(a->value64, b->value64, sizeof(a->value64)) == 0;
}
static unsigned nine_ff_ps_key_hash(void *key)
static uint32_t nine_ff_ps_key_hash(const void *key)
{
struct nine_ff_ps_key *ps = key;
unsigned i;
@ -149,20 +149,20 @@ static unsigned nine_ff_ps_key_hash(void *key)
hash ^= ps->value32[i];
return hash;
}
static int nine_ff_ps_key_comp(void *key1, void *key2)
static bool nine_ff_ps_key_comp(const void *key1, const void *key2)
{
struct nine_ff_ps_key *a = (struct nine_ff_ps_key *)key1;
struct nine_ff_ps_key *b = (struct nine_ff_ps_key *)key2;
return memcmp(a->value64, b->value64, sizeof(a->value64));
return memcmp(a->value64, b->value64, sizeof(a->value64)) == 0;
}
static unsigned nine_ff_fvf_key_hash(void *key)
static uint32_t nine_ff_fvf_key_hash(const void *key)
{
return *(DWORD *)key;
}
static int nine_ff_fvf_key_comp(void *key1, void *key2)
static bool nine_ff_fvf_key_comp(const void *key1, const void *key2)
{
return *(DWORD *)key1 != *(DWORD *)key2;
return *(DWORD *)key1 == *(DWORD *)key2;
}
static void nine_ff_prune_vs(struct NineDevice9 *);

View file

@ -9,15 +9,15 @@ struct pheader
DWORD size;
};
static int
ht_guid_compare( void *a,
void *b )
static bool
ht_guid_compare( const void *a,
const void *b )
{
return GUID_equal(a, b) ? 0 : 1;
return GUID_equal(a, b);
}
static unsigned
ht_guid_hash( void *key )
static uint32_t
ht_guid_hash( const void *key )
{
unsigned i, hash = 0;
const unsigned char *str = key;

View file

@ -43,13 +43,13 @@
static struct util_hash_table *dev_hash = NULL;
static int vmw_dev_compare(void *key1, void *key2)
static bool vmw_dev_compare(const void *key1, const void *key2)
{
return (major(*(dev_t *)key1) == major(*(dev_t *)key2) &&
minor(*(dev_t *)key1) == minor(*(dev_t *)key2)) ? 0 : 1;
minor(*(dev_t *)key1) == minor(*(dev_t *)key2));
}
static unsigned vmw_dev_hash(void *key)
static uint32_t vmw_dev_hash(const void *key)
{
return (major(*(dev_t *) key) << 16) | minor(*(dev_t *) key);
}