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? */
};
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;
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);
}
-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);
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
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);
}
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);
}
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);
}
* 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.
};
};
-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;
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;
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 *);
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;
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);
}