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

core: add "callback_free_key" in hashtable

This commit is contained in:
Sebastien Helleu
2013-08-09 23:00:12 +02:00
parent 72c1af25e0
commit abb574ec4e
5 changed files with 39 additions and 13 deletions
+2
View File
@@ -3690,6 +3690,8 @@ Arguments:
* 'hashtable': hashtable pointer
* 'property' and 'value': property name, with its value:
** 'callback_free_key': set callback function used to free keys in hashtable
(_new in version 0.4.2_)
** 'callback_free_value': set callback function used to free values in hashtable
C example:
+2
View File
@@ -3734,6 +3734,8 @@ Paramètres :
* 'hashtable' : pointeur vers la hashtable
* 'property' et 'value' : nom de la propriété, avec sa valeur :
** 'callback_free_key' : définit la fonction "callback" pour libérer les clés de
la hashtable (_nouveau dans la version 0.4.2_)
** 'callback_free_value' : définit la fonction "callback" pour libérer les
valeurs de la hashtable
+3
View File
@@ -3694,6 +3694,9 @@ Argomenti:
* 'hashtable': puntatore alla tabella hash
* 'property' e 'value': nome della proprietà, con il proprio valore:
// TRANSLATION MISSING
** 'callback_free_key': set callback function used to free keys in hashtable
(_novità nella versione 0.4.2_)
** 'callback_free_value': imposta la funzione callback usata per
liberare i valori nella tabella hash
+29 -13
View File
@@ -218,6 +218,7 @@ hashtable_new (int size,
new_hashtable->callback_keycmp = (callback_keycmp) ?
callback_keycmp : &hashtable_keycmp_default_cb;
new_hashtable->callback_free_key = NULL;
new_hashtable->callback_free_value = NULL;
}
return new_hashtable;
@@ -288,18 +289,28 @@ void
hashtable_free_key (struct t_hashtable *hashtable,
struct t_hashtable_item *item)
{
switch (hashtable->type_keys)
if (hashtable->callback_free_key)
{
case HASHTABLE_INTEGER:
case HASHTABLE_STRING:
case HASHTABLE_BUFFER:
case HASHTABLE_TIME:
free (item->key);
break;
case HASHTABLE_POINTER:
break;
case HASHTABLE_NUM_TYPES:
break;
(void) (hashtable->callback_free_key) (hashtable,
item->key,
item->value);
}
else
{
switch (hashtable->type_keys)
{
case HASHTABLE_INTEGER:
case HASHTABLE_STRING:
case HASHTABLE_BUFFER:
case HASHTABLE_TIME:
if (item->key)
free (item->key);
break;
case HASHTABLE_POINTER:
break;
case HASHTABLE_NUM_TYPES:
break;
}
}
}
@@ -659,6 +670,7 @@ hashtable_dup (struct t_hashtable *hashtable)
hashtable->callback_keycmp);
if (new_hashtable)
{
new_hashtable->callback_free_key = hashtable->callback_free_key;
new_hashtable->callback_free_value = hashtable->callback_free_value;
hashtable_map (hashtable,
&hashtable_duplicate_map_cb,
@@ -1000,7 +1012,9 @@ hashtable_set_pointer (struct t_hashtable *hashtable, const char *property,
{
if (hashtable && property)
{
if (string_strcasecmp (property, "callback_free_value") == 0)
if (string_strcasecmp (property, "callback_free_key") == 0)
hashtable->callback_free_key = pointer;
else if (string_strcasecmp (property, "callback_free_value") == 0)
hashtable->callback_free_value = pointer;
}
}
@@ -1184,6 +1198,9 @@ hashtable_print_log (struct t_hashtable *hashtable, const char *name)
hashtable_type_string[hashtable->type_values]);
log_printf (" callback_hash_key. . . : 0x%lx", hashtable->callback_hash_key);
log_printf (" callback_keycmp. . . . : 0x%lx", hashtable->callback_keycmp);
log_printf (" callback_free_key. . . : 0x%lx", hashtable->callback_free_key);
log_printf (" callback_free_value. . : 0x%lx", hashtable->callback_free_value);
log_printf (" keys_values. . . . . . : '%s'", hashtable->keys_values);
for (i = 0; i < hashtable->size; i++)
{
@@ -1238,5 +1255,4 @@ hashtable_print_log (struct t_hashtable *hashtable, const char *name)
log_printf (" next_item. . . . . : 0x%lx", ptr_item->next_item);
}
}
log_printf (" keys_values. . . . . . : '%s'", hashtable->keys_values);
}
+3
View File
@@ -27,6 +27,8 @@ typedef unsigned int (t_hashtable_hash_key)(struct t_hashtable *hashtable,
const void *key);
typedef int (t_hashtable_keycmp)(struct t_hashtable *hashtable,
const void *key1, const void *key2);
typedef void (t_hashtable_free_key)(struct t_hashtable *hashtable,
void *key, const void *value);
typedef void (t_hashtable_free_value)(struct t_hashtable *hashtable,
const void *key, void *value);
typedef void (t_hashtable_map)(void *data,
@@ -102,6 +104,7 @@ struct t_hashtable
/* callbacks */
t_hashtable_hash_key *callback_hash_key; /* hash key to int value */
t_hashtable_keycmp *callback_keycmp; /* compare two keys */
t_hashtable_free_key *callback_free_key; /* callback to free key */
t_hashtable_free_value *callback_free_value; /* callback to free value */
/* keys/values as string */