diff options
author | Michael Mann <mmann78@netscape.net> | 2017-02-09 10:14:46 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-02-09 22:03:01 +0000 |
commit | e3128d98060017bd08ec6bcb17290c7ffa7784ed (patch) | |
tree | be4ad8c0b0fe85ec25c6d63ba22d19e2cc6d6547 /epan/wmem | |
parent | cd3855225935c13e8db71ca73688aadd6445a710 (diff) | |
download | wireshark-e3128d98060017bd08ec6bcb17290c7ffa7784ed.tar.gz |
Add wmem_map_steal
Mimic functionality of g_hash_table_steal
Change-Id: Iaf4aeef951b60934569143b2d119f782aeefe380
Reviewed-on: https://code.wireshark.org/review/20038
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/wmem')
-rw-r--r-- | epan/wmem/wmem_map.c | 29 | ||||
-rw-r--r-- | epan/wmem/wmem_map.h | 11 |
2 files changed, 40 insertions, 0 deletions
diff --git a/epan/wmem/wmem_map.c b/epan/wmem/wmem_map.c index 5d1a781809..f1529a02a6 100644 --- a/epan/wmem/wmem_map.c +++ b/epan/wmem/wmem_map.c @@ -293,6 +293,35 @@ wmem_map_remove(wmem_map_t *map, const void *key) return NULL; } +gboolean +wmem_map_steal(wmem_map_t *map, const void *key) +{ + wmem_map_item_t **item, *tmp; + + /* Make sure we have a table */ + if (map->table == NULL) { + return FALSE; + } + + /* get a pointer to the slot */ + item = &(map->table[HASH(map, key)]); + + /* check the items in that slot */ + while (*item) { + if (map->eql_func(key, (*item)->key)) { + /* found it */ + tmp = (*item); + (*item) = tmp->next; + map->count--; + return TRUE; + } + item = &((*item)->next); + } + + /* didn't find it */ + return FALSE; +} + 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 1ea4cf3350..8c3e90972d 100644 --- a/epan/wmem/wmem_map.h +++ b/epan/wmem/wmem_map.h @@ -120,6 +120,17 @@ WS_DLL_PUBLIC void * wmem_map_remove(wmem_map_t *map, const void *key); +/** Remove a key and value from the map but does not destroy (free) them. If no + * value is stored at that key, nothing happens. + * + * @param map The map to remove from. + * @param key The key of the value to remove. + * @return TRUE if key is found FALSE if not. + */ +WS_DLL_PUBLIC +gboolean +wmem_map_steal(wmem_map_t *map, const void *key); + /** 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. |