return trans ? trans((*node)->dat) : (*node)->dat; \
} \
\
- bool prefix ## del(Type *self, void *key, Comparator cmp, Callback call, void *arg) \
+ bool prefix ## del(Type *self, void *key, Comparator cmp, Callback call, void *arg, Transformer trans) \
{ \
Type ## Node **node = prefix ## nfd(self, key, cmp); \
\
if (!*node) \
return false; \
\
- if (call) \
- call((*node)->dat, arg); \
+ if (call) \
+ call(trans ? trans((*node)->dat) : (*node)->dat, arg); \
\
prefix ## nrm(self, node); \
return true; \
void flag_uns(Flag *flag, pthread_cond_t *cnd)
{
pthread_mutex_lock(&flag->mtx);
- list_del(&flag->cvs, cnd, &cmp_ref, NULL, NULL);
+ list_del(&flag->cvs, cnd, &cmp_ref, NULL, NULL, NULL);
pthread_mutex_unlock(&flag->mtx);
}
The first matching element is returned, or NULL if none found.
*/
-bool list_del(List *list, void *key, Comparator cmp, Callback call, void *arg);
+bool list_del(List *list, void *key, Comparator cmp, Callback call, void *arg, Transformer trans);
/*
Delete an element from the list if it is found.
Return whether an element has been deleted.
return ret;
}
-bool map_del(Map *map, void *key, Comparator cmp, Callback call, void *arg)
+bool map_del(Map *map, void *key, Comparator cmp, Callback call, void *arg, Transformer trans)
{
if (!get_lock(map, true))
return false;
- bool ret = tree_del(&map->tre, key, cmp, call, arg);
+ bool ret = tree_del(&map->tre, key, cmp, call, arg, trans);
pthread_rwlock_unlock(&map->tlk);
return ret;
}
Get an element from the map, or return NULL if none found.
*/
-bool map_del(Map *map, void *key, Comparator cmp, Callback call, void *arg);
+bool map_del(Map *map, void *key, Comparator cmp, Callback call, void *arg, Transformer trans);
/*
[Thread Safe]
Delete an element from the map if it is found.
assert(list_get(&list, &e, &cmp_int, NULL) == NULL);
printf("testing del\n");
- assert(list_del(&list, &a, &cmp_int, NULL, NULL));
+ assert(list_del(&list, &a, &cmp_int, NULL, NULL, NULL));
assert(list_get(&list, &a, &cmp_int, NULL) == NULL);
printf("testing clr\n");
while (!cancel) {
unsigned int id = rand_id();
- if (map_del(&map, &id, &data_object_compare_id, (void *) &refcount_drp, NULL))
+ if (map_del(&map, &id, &data_object_compare_id, (void *) &refcount_drp, NULL, NULL))
(*result)++;
}
assert(tree_get(&tree, &e, &cmp_int, NULL) == NULL);
printf("testing del\n");
- assert(tree_del(&tree, &a, &cmp_int, NULL, NULL));
+ assert(tree_del(&tree, &a, &cmp_int, NULL, NULL, NULL));
assert(tree_get(&tree, &a, &cmp_int, NULL) == NULL);
printf("testing clr\n");
Get an element from the tree, or return NULL if none found.
*/
-bool tree_del(Tree *tree, void *key, Comparator cmp, Callback call, void *arg);
+bool tree_del(Tree *tree, void *key, Comparator cmp, Callback call, void *arg, Transformer trans);
/*
Delete an element from the tree if it is found.
Return whether an element has been deleted.