mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 02:38:04 +02:00
util: Implement a hash table cloning function
V2: Don't rzalloc; we are about to rewrite the whole thing (Vladislav) Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
This commit is contained in:
parent
388ed47081
commit
6baaf4291b
2 changed files with 24 additions and 0 deletions
|
|
@ -141,6 +141,28 @@ _mesa_hash_table_create(void *mem_ctx,
|
|||
return ht;
|
||||
}
|
||||
|
||||
struct hash_table *
|
||||
_mesa_hash_table_clone(struct hash_table *src, void *dst_mem_ctx)
|
||||
{
|
||||
struct hash_table *ht;
|
||||
|
||||
ht = ralloc(dst_mem_ctx, struct hash_table);
|
||||
if (ht == NULL)
|
||||
return NULL;
|
||||
|
||||
memcpy(ht, src, sizeof(struct hash_table));
|
||||
|
||||
ht->table = ralloc_array(ht, struct hash_entry, ht->size);
|
||||
if (ht->table == NULL) {
|
||||
ralloc_free(ht);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(ht->table, src->table, ht->size * sizeof(struct hash_entry));
|
||||
|
||||
return ht;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the given hash table.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ _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));
|
||||
struct hash_table *
|
||||
_mesa_hash_table_clone(struct hash_table *src, void *dst_mem_ctx);
|
||||
void _mesa_hash_table_destroy(struct hash_table *ht,
|
||||
void (*delete_function)(struct hash_entry *entry));
|
||||
void _mesa_hash_table_clear(struct hash_table *ht,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue