diff options
author | Michael Mann <mmann78@netscape.net> | 2017-02-09 12:25:43 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-02-09 22:03:10 +0000 |
commit | f8b69fb349986dce4ae77da9455cd12ba804797d (patch) | |
tree | 8e8eddb9c748522373fcb81ee2c9aadecccf4149 /epan/wmem | |
parent | e3128d98060017bd08ec6bcb17290c7ffa7784ed (diff) | |
download | wireshark-f8b69fb349986dce4ae77da9455cd12ba804797d.tar.gz |
Add wmem_map_get_keys.
Mimic functionality of g_hash_table_get_keys
Change-Id: I7702854ed771a5b3bf7ea5295a67c42f0f477cdf
Reviewed-on: https://code.wireshark.org/review/20039
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/wmem')
-rw-r--r-- | epan/wmem/wmem_map.c | 24 | ||||
-rw-r--r-- | epan/wmem/wmem_map.h | 10 |
2 files changed, 34 insertions, 0 deletions
diff --git a/epan/wmem/wmem_map.c b/epan/wmem/wmem_map.c index f1529a02a6..4b4a3a4da3 100644 --- a/epan/wmem/wmem_map.c +++ b/epan/wmem/wmem_map.c @@ -25,6 +25,7 @@ #include <glib.h> #include "wmem_core.h" +#include "wmem_list.h" #include "wmem_map.h" #include "wmem_map_int.h" #include "wmem_user_cb.h" @@ -322,6 +323,29 @@ wmem_map_steal(wmem_map_t *map, const void *key) return FALSE; } +wmem_list_t* +wmem_map_get_keys(wmem_allocator_t *list_allocator, wmem_map_t *map) +{ + size_t capacity, i; + wmem_map_item_t *cur; + wmem_list_t* list = wmem_list_new(list_allocator); + + if (map->table != NULL) { + capacity = CAPACITY(map); + + /* copy all the elements into the list over from table */ + for (i=0; i<capacity; i++) { + cur = map->table[i]; + while (cur) { + wmem_list_prepend(list, (void*)cur->key); + cur = cur->next; + } + } + } + + return list; +} + void wmem_map_foreach(wmem_map_t *map, GHFunc foreach_func, gpointer user_data) { diff --git a/epan/wmem/wmem_map.h b/epan/wmem/wmem_map.h index 8c3e90972d..3a962da811 100644 --- a/epan/wmem/wmem_map.h +++ b/epan/wmem/wmem_map.h @@ -131,6 +131,16 @@ WS_DLL_PUBLIC gboolean wmem_map_steal(wmem_map_t *map, const void *key); +/** Retrieves a list of keys inside the map + * + * @param list_allocator The allocator scope for the returned list. + * @param map The map to extract keys from + * @return list of keys in the map + */ +WS_DLL_PUBLIC +wmem_list_t* +wmem_map_get_keys(wmem_allocator_t *list_allocator, wmem_map_t *map); + /** Run a function against all key/value pairs in the map. The order * of the calls is unpredictable, since it is based on the internal * storage of data. |