Skip to content

Commit

Permalink
[libu] hmap += u_hmap_foreach_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
tho committed Dec 22, 2009
1 parent 8a54806 commit 3fb87bf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion ChangeLog
@@ -1,10 +1,11 @@
$Id: ChangeLog,v 1.70 2009/12/21 14:06:12 tho Exp $
$Id: ChangeLog,v 1.71 2009/12/22 12:13:03 tho Exp $

ChangeLog file of LibU - http://www.koanlogic.com/libu/index.html

LibU X.Y.Z
- [config] u_config_print_to_fp with brace delimiters for
children records + doxy fixes (by Mickael Auger)
- [hmap] added u_hmap_foreach_arg which accepts a user defined parameter

LibU 1.4.1
- [missing] u_va_copy added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.4.2rc0
1.4.2rc1
1 change: 1 addition & 0 deletions include/toolbox/hmap.h
Expand Up @@ -95,6 +95,7 @@ int u_hmap_copy (u_hmap_t *to, u_hmap_t *from);
void u_hmap_free (u_hmap_t *hmap);
int u_hmap_foreach (u_hmap_t *hmap, int f(void *val));
int u_hmap_foreach_keyval (u_hmap_t *hmap, int f(void *key, void *val));
int u_hmap_foreach_arg (u_hmap_t *hmap, int f(void *val, void *arg), void *arg);

/* u_hmap_o_t */
u_hmap_o_t *u_hmap_o_new (void *key, void *val);
Expand Down
33 changes: 32 additions & 1 deletion srcs/toolbox/hmap.c
Expand Up @@ -860,7 +860,38 @@ int u_hmap_foreach (u_hmap_t *hmap, int f(void *val))
}

return U_HMAP_ERR_NONE;
err:
return U_HMAP_ERR_FAIL;
}

/**
* \brief \c u_hmap_foreach with user supplied parameter
*
* Execute function \a f on all objects within \a hmap supplying \a arg
* as custom argument. These functions should return \c U_HMAP_ERR_NONE on
* success, and take an hmap object and \a arg as parameters.
*
* \param hmap hmap object
* \param f function
* \param arg custom arg that will be supplied to \a f
*
* \return U_HMAP_ERR_NONE on success, U_HMAP_ERR_FAIL on failure
*/
int u_hmap_foreach_arg (u_hmap_t *hmap, int f(void *val, void *arg), void *arg)
{
size_t i;
u_hmap_o_t *obj;

dbg_err_if (hmap == NULL);
dbg_err_if (f == NULL);

for (i = 0; i < hmap->size; ++i)
{
LIST_FOREACH(obj, &hmap->hmap[i], next)
dbg_err_if (f(obj->val, arg));
}

return U_HMAP_ERR_NONE;
err:
return U_HMAP_ERR_FAIL;
}
Expand All @@ -887,7 +918,7 @@ int u_hmap_foreach_keyval(u_hmap_t *hmap, int f(void *key, void *val))
for (i = 0; i < hmap->size; ++i)
{
LIST_FOREACH(obj, &hmap->hmap[i], next)
dbg_err_if (f(obj->key,obj->val));
dbg_err_if (f(obj->key, obj->val));
}

return U_HMAP_ERR_NONE;
Expand Down

0 comments on commit 3fb87bf

Please sign in to comment.