From 184bbef33d1fff3520958c130f2b8e4fce17379c Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 7 Jan 2021 09:39:46 -0500 Subject: [PATCH] util/set: split off create() into an init() function this brings parity with the matching hash_table api Reviewed-by: Eric Anholt Part-of: --- src/util/set.c | 31 ++++++++++++++++++++----------- src/util/set.h | 6 ++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/util/set.c b/src/util/set.c index fe945e7..2e3cb92 100644 --- a/src/util/set.c +++ b/src/util/set.c @@ -116,18 +116,12 @@ entry_is_present(struct set_entry *entry) return entry->key != NULL && entry->key != deleted_key; } -struct set * -_mesa_set_create(void *mem_ctx, +bool +_mesa_set_init(struct set *ht, void *mem_ctx, uint32_t (*key_hash_function)(const void *key), bool (*key_equals_function)(const void *a, const void *b)) { - struct set *ht; - - ht = ralloc(mem_ctx, struct set); - if (ht == NULL) - return NULL; - ht->size_index = 0; ht->size = hash_sizes[ht->size_index].size; ht->rehash = hash_sizes[ht->size_index].rehash; @@ -136,11 +130,26 @@ _mesa_set_create(void *mem_ctx, 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 set_entry, ht->size); + ht->table = rzalloc_array(mem_ctx, struct set_entry, ht->size); ht->entries = 0; ht->deleted_entries = 0; - if (ht->table == NULL) { + return ht->table != NULL; +} + +struct set * +_mesa_set_create(void *mem_ctx, + uint32_t (*key_hash_function)(const void *key), + bool (*key_equals_function)(const void *a, + const void *b)) +{ + struct set *ht; + + ht = ralloc(mem_ctx, struct set); + if (ht == NULL) + return NULL; + + if (!_mesa_set_init(ht, ht, key_hash_function, key_equals_function)) { ralloc_free(ht); return NULL; } @@ -333,7 +342,7 @@ set_rehash(struct set *ht, unsigned new_size_index) if (new_size_index >= ARRAY_SIZE(hash_sizes)) return; - table = rzalloc_array(ht, struct set_entry, + table = rzalloc_array(ralloc_parent(ht->table), struct set_entry, hash_sizes[new_size_index].size); if (table == NULL) return; diff --git a/src/util/set.h b/src/util/set.h index cabff35..5498313 100644 --- a/src/util/set.h +++ b/src/util/set.h @@ -55,6 +55,12 @@ struct set { uint32_t deleted_entries; }; +bool +_mesa_set_init(struct set *ht, void *mem_ctx, + uint32_t (*key_hash_function)(const void *key), + bool (*key_equals_function)(const void *a, + const void *b)); + struct set * _mesa_set_create(void *mem_ctx, uint32_t (*key_hash_function)(const void *key), -- 2.7.4