1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: add function hashtable_dup (duplicate a hashtable)

This commit is contained in:
Sebastien Helleu
2011-08-13 12:00:25 +02:00
parent 3398c9c65b
commit 7ebb91f69b
2 changed files with 49 additions and 2 deletions
+47 -2
View File
@@ -455,8 +455,53 @@ hashtable_map (struct t_hashtable *hashtable,
}
/*
* hashtable_get_list_keys_map_cb: function called for each variable in hdata
* to build sorted list of keys
* hashtable_duplicate_map_cb: function called for each variable in hashtable
* to duplicate all keys
*/
void
hashtable_duplicate_map_cb (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable2;
/* make C compiler happy */
(void) hashtable;
hashtable2 = (struct t_hashtable *)data;
if (hashtable2)
hashtable_set (hashtable2, key, value);
}
/*
* hashtable_dup: duplicate hashtable
*/
struct t_hashtable *
hashtable_dup (struct t_hashtable *hashtable)
{
struct t_hashtable *new_hashtable;
new_hashtable = hashtable_new (hashtable->size,
hashtable_type_string[hashtable->type_keys],
hashtable_type_string[hashtable->type_values],
hashtable->callback_hash_key,
hashtable->callback_keycmp);
if (new_hashtable)
{
new_hashtable->callback_free_value = hashtable->callback_free_value;
hashtable_map (hashtable,
&hashtable_duplicate_map_cb,
new_hashtable);
}
return new_hashtable;
}
/*
* hashtable_get_list_keys_map_cb: function called for each variable in
* hashtable to build sorted list of keys
*/
void
+2
View File
@@ -121,6 +121,8 @@ extern int hashtable_has_key (struct t_hashtable *hashtable, const void *key);
extern void hashtable_map (struct t_hashtable *hashtable,
t_hashtable_map *callback_map,
void *callback_map_data);
extern struct t_hashtable *hashtable_dup (struct t_hashtable *hashtable);
struct t_weelist *hashtable_get_list_keys (struct t_hashtable *hashtable);
extern int hashtable_get_integer (struct t_hashtable *hashtable,
const char *property);
extern const char *hashtable_get_string (struct t_hashtable *hashtable,