From 5e5a48ff8cd08f123601cd0625ca62a86675aac9 Mon Sep 17 00:00:00 2001 From: marha Date: Sun, 4 Jan 2015 16:25:32 +0100 Subject: fontconfig libX11 mesa xserver git update 4 Jan 2015 xserver commit dc777c346d5d452a53b13b917c45f6a1bad2f20b libX11 commit 446f5f7f41317a85a0cd0efa5e6a1b37bc99fba2 fontconfig commit 4420b27c074821a1d1f9d6ebe822a610176a417d mesa commit 48094d0e6554a9df36bf00fc2793ade46cf92406 --- mesalib/src/util/hash_table.c | 75 +++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 20 deletions(-) (limited to 'mesalib/src/util/hash_table.c') diff --git a/mesalib/src/util/hash_table.c b/mesalib/src/util/hash_table.c index 920bdfd33..0ad038377 100644 --- a/mesalib/src/util/hash_table.c +++ b/mesalib/src/util/hash_table.c @@ -42,6 +42,7 @@ #include #include +#include #include "hash_table.h" #include "ralloc.h" @@ -110,6 +111,7 @@ entry_is_present(const struct hash_table *ht, struct hash_entry *entry) struct hash_table * _mesa_hash_table_create(void *mem_ctx, + uint32_t (*key_hash_function)(const void *key), bool (*key_equals_function)(const void *a, const void *b)) { @@ -123,6 +125,7 @@ _mesa_hash_table_create(void *mem_ctx, ht->size = hash_sizes[ht->size_index].size; ht->rehash = hash_sizes[ht->size_index].rehash; ht->max_entries = hash_sizes[ht->size_index].max_entries; + ht->key_hash_function = key_hash_function; ht->key_equals_function = key_equals_function; ht->table = rzalloc_array(ht, struct hash_entry, ht->size); ht->entries = 0; @@ -176,15 +179,8 @@ _mesa_hash_table_set_deleted_key(struct hash_table *ht, const void *deleted_key) ht->deleted_key = deleted_key; } -/** - * Finds a hash table entry with the given key and hash of that key. - * - * Returns NULL if no entry is found. Note that the data pointer may be - * modified by the user. - */ -struct hash_entry * -_mesa_hash_table_search(struct hash_table *ht, uint32_t hash, - const void *key) +static struct hash_entry * +hash_table_search(struct hash_table *ht, uint32_t hash, const void *key) { uint32_t start_hash_address = hash % ht->size; uint32_t hash_address = start_hash_address; @@ -210,6 +206,31 @@ _mesa_hash_table_search(struct hash_table *ht, uint32_t hash, return NULL; } +/** + * Finds a hash table entry with the given key and hash of that key. + * + * Returns NULL if no entry is found. Note that the data pointer may be + * modified by the user. + */ +struct hash_entry * +_mesa_hash_table_search(struct hash_table *ht, const void *key) +{ + assert(ht->key_hash_function); + return hash_table_search(ht, ht->key_hash_function(key), key); +} + +struct hash_entry * +_mesa_hash_table_search_pre_hashed(struct hash_table *ht, uint32_t hash, + const void *key) +{ + assert(ht->key_hash_function == NULL || hash == ht->key_hash_function(key)); + return hash_table_search(ht, hash, key); +} + +static struct hash_entry * +hash_table_insert(struct hash_table *ht, uint32_t hash, + const void *key, void *data); + static void _mesa_hash_table_rehash(struct hash_table *ht, int new_size_index) { @@ -235,22 +256,15 @@ _mesa_hash_table_rehash(struct hash_table *ht, int new_size_index) ht->deleted_entries = 0; hash_table_foreach(&old_ht, entry) { - _mesa_hash_table_insert(ht, entry->hash, - entry->key, entry->data); + hash_table_insert(ht, entry->hash, entry->key, entry->data); } ralloc_free(old_ht.table); } -/** - * Inserts the key with the given hash into the table. - * - * Note that insertion may rearrange the table on a resize or rehash, - * so previously found hash_entries are no longer valid after this function. - */ -struct hash_entry * -_mesa_hash_table_insert(struct hash_table *ht, uint32_t hash, - const void *key, void *data) +static struct hash_entry * +hash_table_insert(struct hash_table *ht, uint32_t hash, + const void *key, void *data) { uint32_t start_hash_address, hash_address; @@ -306,6 +320,27 @@ _mesa_hash_table_insert(struct hash_table *ht, uint32_t hash, return NULL; } +/** + * Inserts the key with the given hash into the table. + * + * Note that insertion may rearrange the table on a resize or rehash, + * so previously found hash_entries are no longer valid after this function. + */ +struct hash_entry * +_mesa_hash_table_insert(struct hash_table *ht, const void *key, void *data) +{ + assert(ht->key_hash_function); + return hash_table_insert(ht, ht->key_hash_function(key), key, data); +} + +struct hash_entry * +_mesa_hash_table_insert_with_hash(struct hash_table *ht, uint32_t hash, + const void *key, void *data) +{ + assert(ht->key_hash_function == NULL || hash == ht->key_hash_function(key)); + return hash_table_insert(ht, hash, key, data); +} + /** * This function deletes the given hash table entry. * -- cgit v1.2.3