Skip to content
Snippets Groups Projects
Commit e00befcd authored by Marek Vavruša's avatar Marek Vavruša
Browse files

lib/generic: 'map' walk callback contains value

parent 23c30b99
Branches
Tags
No related merge requests found
......@@ -78,7 +78,7 @@ static void cbt_traverse_delete(map_t *map, void *top)
}
static int cbt_traverse_prefixed(void *top,
int (*callback)(const char *, void *), void *baton)
int (*callback)(const char *, void *, void *), void *baton)
{
uint8_t *p = top;
cb_data_t *x = (cb_data_t *)top;
......@@ -98,7 +98,7 @@ static int cbt_traverse_prefixed(void *top,
return 0;
}
return (callback)((const char *)x->key, baton);
return (callback)((const char *)x->key, x->value, baton);
}
static cb_data_t *cbt_make_data(map_t *map, const uint8_t *str, size_t len, void *value)
......@@ -316,7 +316,7 @@ void map_clear(map_t *map)
/*! Calls callback for all strings in map with the given prefix */
int map_walk_prefixed(map_t *map, const char *prefix,
int (*callback)(const char *, void *), void *baton)
int (*callback)(const char *, void *, void *), void *baton)
{
const uint8_t *ubytes = (void *)prefix;
const size_t ulen = strlen(prefix);
......
......@@ -81,9 +81,13 @@ int map_del(map_t *map, const char *str);
/*! Clears the given map */
void map_clear(map_t *map);
/*! Calls callback for all strings in map */
#define map_walk(map, callback, baton) \
map_walk_prefixed((map), "", (callback), (baton))
/*! Calls callback for all strings in map with the given prefix */
int map_walk_prefixed(map_t *map, const char *prefix,
int (*callback)(const char *, void *), void *baton);
int (*callback)(const char *, void *, void *), void *baton);
#ifdef __cplusplus
......
......@@ -70,9 +70,13 @@ typedef int (set_walk_cb)(const char *, void *);
#define set_clear(set) \
map_clear(set)
/*! Calls callback for all strings in map */
#define set_walk(set, callback, baton) \
map_walk_prefixed((set), "", (callback), (baton))
/*! Calls callback for all strings in set with the given prefix */
#define set_walk_prefixed(set, prefix, callback, baton) \
map_walk_prefixed((set), (prefix), (callback), baton)
map_walk_prefixed((set), (prefix), (callback), (baton))
#ifdef __cplusplus
......
......@@ -93,11 +93,11 @@ static void test_contains(void **state)
}
/* Count number of items */
static int count_cb(const char *s, void *n) { (*(int *)n)++; return 0; }
static int count_cb(const char *s, void *_, void *n) { (*(int *)n)++; return 0; }
static void test_complete(set_t *set, int n)
{
int i = 0;
if (set_walk_prefixed(set, "", count_cb, &i) != 0) {
if (set_walk(set, count_cb, &i) != 0) {
abort();
}
if (i != n) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment