X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgallium%2Fauxiliary%2Futil%2Fu_hash_table.c;h=5604e3ac3746dfc10a861f58937125c1eddb8ee3;hb=a3eb0f718e19653a2ad8e49396c904183be456f3;hp=0bc8de9632cfe71fb698943b102aeb0e9260ea62;hpb=5340b6dff73a0a23531ce2a5f28fba8303adab6e;p=mesa.git diff --git a/src/gallium/auxiliary/util/u_hash_table.c b/src/gallium/auxiliary/util/u_hash_table.c index 0bc8de9632c..5604e3ac374 100644 --- a/src/gallium/auxiliary/util/u_hash_table.c +++ b/src/gallium/auxiliary/util/u_hash_table.c @@ -39,7 +39,7 @@ #include "pipe/p_compiler.h" -#include "pipe/p_debug.h" +#include "util/u_debug.h" #include "cso_cache/cso_hash.h" @@ -47,7 +47,7 @@ #include "util/u_hash_table.h" -struct hash_table +struct util_hash_table { struct cso_hash *cso; @@ -61,27 +61,27 @@ struct hash_table }; -struct hash_table_item +struct util_hash_table_item { void *key; void *value; }; -static INLINE struct hash_table_item * -hash_table_item(struct cso_hash_iter iter) +static INLINE struct util_hash_table_item * +util_hash_table_item(struct cso_hash_iter iter) { - return (struct hash_table_item *)cso_hash_iter_data(iter); + return (struct util_hash_table_item *)cso_hash_iter_data(iter); } -struct hash_table * -hash_table_create(unsigned (*hash)(void *key), - int (*compare)(void *key1, void *key2)) +struct util_hash_table * +util_hash_table_create(unsigned (*hash)(void *key), + int (*compare)(void *key1, void *key2)) { - struct hash_table *ht; + struct util_hash_table *ht; - ht = MALLOC_STRUCT(hash_table); + ht = MALLOC_STRUCT(util_hash_table); if(!ht) return NULL; @@ -99,16 +99,16 @@ hash_table_create(unsigned (*hash)(void *key), static INLINE struct cso_hash_iter -hash_table_find_iter(struct hash_table *ht, - void *key, - unsigned key_hash) +util_hash_table_find_iter(struct util_hash_table *ht, + void *key, + unsigned key_hash) { struct cso_hash_iter iter; - struct hash_table_item *item; + struct util_hash_table_item *item; iter = cso_hash_find(ht->cso, key_hash); while (!cso_hash_iter_is_null(iter)) { - item = (struct hash_table_item *)cso_hash_iter_data(iter); + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); if (!ht->compare(item->key, key)) break; iter = cso_hash_iter_next(iter); @@ -118,17 +118,17 @@ hash_table_find_iter(struct hash_table *ht, } -static INLINE struct hash_table_item * -hash_table_find_item(struct hash_table *ht, - void *key, - unsigned key_hash) +static INLINE struct util_hash_table_item * +util_hash_table_find_item(struct util_hash_table *ht, + void *key, + unsigned key_hash) { struct cso_hash_iter iter; - struct hash_table_item *item; + struct util_hash_table_item *item; iter = cso_hash_find(ht->cso, key_hash); while (!cso_hash_iter_is_null(iter)) { - item = (struct hash_table_item *)cso_hash_iter_data(iter); + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); if (!ht->compare(item->key, key)) return item; iter = cso_hash_iter_next(iter); @@ -139,26 +139,28 @@ hash_table_find_item(struct hash_table *ht, enum pipe_error -hash_table_set(struct hash_table *ht, - void *key, - void *value) +util_hash_table_set(struct util_hash_table *ht, + void *key, + void *value) { unsigned key_hash; - struct hash_table_item *item; + struct util_hash_table_item *item; struct cso_hash_iter iter; assert(ht); + if (!ht) + return PIPE_ERROR_BAD_INPUT; key_hash = ht->hash(key); - item = hash_table_find_item(ht, key, key_hash); + item = util_hash_table_find_item(ht, key, key_hash); if(item) { /* TODO: key/value destruction? */ item->value = value; return PIPE_OK; } - item = MALLOC_STRUCT(hash_table_item); + item = MALLOC_STRUCT(util_hash_table_item); if(!item) return PIPE_ERROR_OUT_OF_MEMORY; @@ -176,17 +178,19 @@ hash_table_set(struct hash_table *ht, void * -hash_table_get(struct hash_table *ht, - void *key) +util_hash_table_get(struct util_hash_table *ht, + void *key) { unsigned key_hash; - struct hash_table_item *item; + struct util_hash_table_item *item; assert(ht); + if (!ht) + return NULL; key_hash = ht->hash(key); - item = hash_table_find_item(ht, key, key_hash); + item = util_hash_table_find_item(ht, key, key_hash); if(!item) return NULL; @@ -195,22 +199,24 @@ hash_table_get(struct hash_table *ht, void -hash_table_remove(struct hash_table *ht, - void *key) +util_hash_table_remove(struct util_hash_table *ht, + void *key) { unsigned key_hash; struct cso_hash_iter iter; - struct hash_table_item *item; + struct util_hash_table_item *item; assert(ht); + if (!ht) + return; key_hash = ht->hash(key); - iter = hash_table_find_iter(ht, key, key_hash); + iter = util_hash_table_find_iter(ht, key, key_hash); if(cso_hash_iter_is_null(iter)) return; - item = hash_table_item(iter); + item = util_hash_table_item(iter); assert(item); FREE(item); @@ -219,16 +225,18 @@ hash_table_remove(struct hash_table *ht, void -hash_table_clear(struct hash_table *ht) +util_hash_table_clear(struct util_hash_table *ht) { struct cso_hash_iter iter; - struct hash_table_item *item; + struct util_hash_table_item *item; assert(ht); - + if (!ht) + return; + iter = cso_hash_first_node(ht->cso); while (!cso_hash_iter_is_null(iter)) { - item = (struct hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter)); + item = (struct util_hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter)); FREE(item); iter = cso_hash_first_node(ht->cso); } @@ -236,19 +244,22 @@ hash_table_clear(struct hash_table *ht) enum pipe_error -hash_table_foreach(struct hash_table *ht, - enum pipe_error (*callback)(void *key, void *value, void *data), - void *data) +util_hash_table_foreach(struct util_hash_table *ht, + enum pipe_error (*callback) + (void *key, void *value, void *data), + void *data) { struct cso_hash_iter iter; - struct hash_table_item *item; + struct util_hash_table_item *item; enum pipe_error result; - + assert(ht); - + if (!ht) + return PIPE_ERROR_BAD_INPUT; + iter = cso_hash_first_node(ht->cso); while (!cso_hash_iter_is_null(iter)) { - item = (struct hash_table_item *)cso_hash_iter_data(iter); + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); result = callback(item->key, item->value, data); if(result != PIPE_OK) return result; @@ -260,16 +271,18 @@ hash_table_foreach(struct hash_table *ht, void -hash_table_destroy(struct hash_table *ht) +util_hash_table_destroy(struct util_hash_table *ht) { struct cso_hash_iter iter; - struct hash_table_item *item; - + struct util_hash_table_item *item; + assert(ht); - + if (!ht) + return; + iter = cso_hash_first_node(ht->cso); while (!cso_hash_iter_is_null(iter)) { - item = (struct hash_table_item *)cso_hash_iter_data(iter); + item = (struct util_hash_table_item *)cso_hash_iter_data(iter); FREE(item); iter = cso_hash_iter_next(iter); }