#include "callback.h" // for Transformer, Callback
#define WRAP_NODE_FUNCTIONS(Type, prefix) \
- bool prefix ## add(Type *self, void *dat, void *cmp, void *trans) \
+ bool prefix ## add(Type *self, void *key, void *dat, void *cmp, void *trans) \
{ \
- Type ## Node **node = prefix ## nfd(self, dat, cmp); \
+ Type ## Node **node = prefix ## nfd(self, key, cmp); \
\
if (*node) \
return false; \
void flag_sub(Flag *flag, pthread_cond_t *cnd)
{
pthread_mutex_lock(&flag->mtx);
- list_add(&flag->cvs, cnd, &cmp_ref, NULL);
+ list_add(&flag->cvs, cnd, cnd, &cmp_ref, NULL);
pthread_mutex_unlock(&flag->mtx);
}
This function should be called before any other function is called on the list.
*/
-bool list_add(List *list, void *dat, void *cmp, void *trans);
+bool list_add(List *list, void *key, void *dat, void *cmp, void *trans);
/*
Add an element to the list.
pthread_rwlock_unlock(&map->tlk);
}
-bool map_add(Map *map, void *dat, void *cmp, void *trans)
+bool map_add(Map *map, void *key, void *dat, void *cmp, void *trans)
{
if (!get_lock(map, true))
return false;
- bool ret = tree_add(&map->tre, dat, cmp, trans);
+ bool ret = tree_add(&map->tre, key, dat, cmp, trans);
pthread_rwlock_unlock(&map->tlk);
return ret;
}
If no callback is given, the traversion order is irrelevant.
*/
-bool map_add(Map *map, void *dat, void *cmp, void *trans);
+bool map_add(Map *map, void *key, void *dat, void *cmp, void *trans);
/*
[Thread Safe]
Add an element to the map.
int e = 3;
printf("testing add\n");
- assert(list_add(&list, &a, &cmp_int, NULL));
- assert(list_add(&list, &b, &cmp_int, NULL));
- assert(list_add(&list, &c, &cmp_int, NULL));
- assert(!list_add(&list, &d, &cmp_int, NULL));
+ assert(list_add(&list, &a, &a, &cmp_int, NULL));
+ assert(list_add(&list, &b, &b, &cmp_int, NULL));
+ assert(list_add(&list, &c, &c, &cmp_int, NULL));
+ assert(!list_add(&list, &d, &d, &cmp_int, NULL));
printf("testing get\n");
assert(list_get(&list, &a, &cmp_int, NULL) == &a);
return ((DataObject *) rc->obj)->id - *id;
}
-int cmp_obj_sym(const Refcount *rc1, const Refcount *rc2)
-{
- return cmp_obj(rc1, &((DataObject *) rc2->obj)->id);
-}
-
static void *thread_create(unsigned int *result)
{
while (!cancel) {
refcount_ini(&obj->rc, obj, &delete_obj);
- if (map_add(&map, &obj->rc, &cmp_obj_sym, &refcount_inc))
+ if (map_add(&map, &obj->id, &obj->rc, &cmp_obj, &refcount_inc))
(*result)++;
refcount_drp(&obj->rc);
int e = 3;
printf("testing add\n");
- assert(tree_add(&tree, &a, &cmp_int, NULL));
- assert(tree_add(&tree, &b, &cmp_int, NULL));
- assert(tree_add(&tree, &c, &cmp_int, NULL));
- assert(!tree_add(&tree, &d, &cmp_int, NULL));
+ assert(tree_add(&tree, &a, &a, &cmp_int, NULL));
+ assert(tree_add(&tree, &b, &b, &cmp_int, NULL));
+ assert(tree_add(&tree, &c, &c, &cmp_int, NULL));
+ assert(!tree_add(&tree, &d, &d, &cmp_int, NULL));
printf("testing get\n");
assert(tree_get(&tree, &a, &cmp_int, NULL) == &a);
int *n = malloc(sizeof *n);
*n = rand();
- if (!tree_add(&tree, n, &cmp_int, NULL))
+ if (!tree_add(&tree, n, n, &cmp_int, NULL))
free(n);
}
This function should be called before any other function is called on the tree.
*/
-bool tree_add(Tree *tree, void *dat, void *cmp, void *trans);
+bool tree_add(Tree *tree, void *key, void *dat, void *cmp, void *trans);
/*
Add an element to the tree.