|
WS_DLL_PUBLIC wmem_map_t * | wmem_map_new (wmem_allocator_t *allocator, GHashFunc hash_func, GEqualFunc eql_func) G_GNUC_MALLOC |
|
WS_DLL_PUBLIC wmem_map_t * | wmem_map_new_autoreset (wmem_allocator_t *master, wmem_allocator_t *slave, GHashFunc hash_func, GEqualFunc eql_func) G_GNUC_MALLOC |
|
WS_DLL_PUBLIC void * | wmem_map_insert (wmem_map_t *map, const void *key, void *value) |
|
WS_DLL_PUBLIC gboolean | wmem_map_contains (wmem_map_t *map, const void *key) |
|
WS_DLL_PUBLIC void * | wmem_map_lookup (wmem_map_t *map, const void *key) |
|
WS_DLL_PUBLIC gboolean | wmem_map_lookup_extended (wmem_map_t *map, const void *key, const void **orig_key, void **value) |
|
WS_DLL_PUBLIC void * | wmem_map_remove (wmem_map_t *map, const void *key) |
|
WS_DLL_PUBLIC gboolean | wmem_map_steal (wmem_map_t *map, const void *key) |
|
WS_DLL_PUBLIC wmem_list_t * | wmem_map_get_keys (wmem_allocator_t *list_allocator, wmem_map_t *map) |
|
WS_DLL_PUBLIC void | wmem_map_foreach (wmem_map_t *map, GHFunc foreach_func, gpointer user_data) |
|
WS_DLL_PUBLIC guint | wmem_map_size (wmem_map_t *map) |
|
WS_DLL_PUBLIC guint32 | wmem_strong_hash (const guint8 *buf, const size_t len) |
|
WS_DLL_PUBLIC guint | wmem_str_hash (gconstpointer key) |
|
WS_DLL_PUBLIC guint | wmem_int64_hash (gconstpointer key) |
|
WS_DLL_PUBLIC guint | wmem_double_hash (gconstpointer key) |
|
A hash map implementation on top of wmem. Provides insertion, deletion and lookup in expected amortized constant time. Uses universal hashing to map keys into buckets, and provides a generic strong hash function that makes it secure against algorithmic complexity attacks, and suitable for use even with untrusted data.
WS_DLL_PUBLIC guint wmem_double_hash |
( |
gconstpointer |
key | ) |
|
An implementation of GHashFunc using wmem_strong_hash. Prefer this over g_double_hash when the data comes from an untrusted source.
WS_DLL_PUBLIC guint wmem_int64_hash |
( |
gconstpointer |
key | ) |
|
An implementation of GHashFunc using wmem_strong_hash. Prefer this over g_int64_hash when the data comes from an untrusted source.
WS_DLL_PUBLIC gboolean wmem_map_contains |
( |
wmem_map_t * |
map, |
|
|
const void * |
key |
|
) |
| |
Check if a value is in the map.
- Parameters
-
map | The map to search in. |
key | The key to lookup. |
- Returns
- true if the key is in the map, otherwise false.
WS_DLL_PUBLIC void wmem_map_foreach |
( |
wmem_map_t * |
map, |
|
|
GHFunc |
foreach_func, |
|
|
gpointer |
user_data |
|
) |
| |
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.
- Parameters
-
map | The map to use |
foreach_func | the function to call for each key/value pair |
user_data | user data to pass to the function |
Retrieves a list of keys inside the map
- Parameters
-
list_allocator | The allocator scope for the returned list. |
map | The map to extract keys from |
- Returns
- list of keys in the map
WS_DLL_PUBLIC void* wmem_map_insert |
( |
wmem_map_t * |
map, |
|
|
const void * |
key, |
|
|
void * |
value |
|
) |
| |
Inserts a value into the map.
- Parameters
-
map | The map to insert into. |
key | The key to insert by. |
value | The value to insert. |
- Returns
- The previous value stored at this key if any, or NULL.
WS_DLL_PUBLIC void* wmem_map_lookup |
( |
wmem_map_t * |
map, |
|
|
const void * |
key |
|
) |
| |
Lookup a value in the map.
- Parameters
-
map | The map to search in. |
key | The key to lookup. |
- Returns
- The value stored at the key if any, or NULL.
WS_DLL_PUBLIC gboolean wmem_map_lookup_extended |
( |
wmem_map_t * |
map, |
|
|
const void * |
key, |
|
|
const void ** |
orig_key, |
|
|
void ** |
value |
|
) |
| |
Lookup a value in the map, returning the key, value, and a boolean which is true if the key is found.
- Parameters
-
map | The map to search in. |
key | The key to lookup. |
orig_key | (optional) The key that was determined to be a match, if any. |
value | (optional) The value stored at the key, if any. |
- Returns
- true if the key is in the map, otherwise false.
Creates a map with the given allocator scope. When the scope is emptied, the map is fully destroyed. Items stored in it will not be freed unless they were allocated from the same scope. For details on the GHashFunc and GEqualFunc parameters, see the glib documentation at: https://developer.gnome.org/glib/unstable/glib-Hash-Tables.html
If the keys are coming from untrusted data, do not use glib's default hash functions for strings, int64s or doubles. Wmem provides stronger equivalents below. Feel free to use the g_direct_hash, g_int_hash, and any of the g_*_equal functions though, as they should be safe.
- Parameters
-
allocator | The allocator scope with which to create the map. |
hash_func | The hash function used to place inserted keys. |
eql_func | The equality function used to compare inserted keys. |
- Returns
- The newly-allocated map.
Creates a map with two allocator scopes. The base structure lives in the master scope, however the data lives in the slave scope. Every time free_all occurs in the slave scope the map is transparently emptied without affecting the location of the master structure.
WARNING: None of the map (even the part in the master scope) can be used after the slave scope has been destroyed.
The primary use for this function is to create maps that reset for each new capture file that is loaded. This can be done by specifying wmem_epan_scope() as the master and wmem_file_scope() as the slave.
WS_DLL_PUBLIC void* wmem_map_remove |
( |
wmem_map_t * |
map, |
|
|
const void * |
key |
|
) |
| |
Remove a value from the map. If no value is stored at that key, nothing happens.
- Parameters
-
map | The map to remove from. |
key | The key of the value to remove. |
- Returns
- The (removed) value stored at the key if any, or NULL.
WS_DLL_PUBLIC guint wmem_map_size |
( |
wmem_map_t * |
map | ) |
|
Return the number of elements of the map.
- Parameters
-
- Returns
- the number of elements
WS_DLL_PUBLIC gboolean wmem_map_steal |
( |
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.
- Parameters
-
map | The map to remove from. |
key | The key of the value to remove. |
- Returns
- TRUE if key is found FALSE if not.
WS_DLL_PUBLIC guint wmem_str_hash |
( |
gconstpointer |
key | ) |
|
An implementation of GHashFunc using wmem_strong_hash. Prefer this over g_str_hash when the data comes from an untrusted source.
WS_DLL_PUBLIC guint32 wmem_strong_hash |
( |
const guint8 * |
buf, |
|
|
const size_t |
len |
|
) |
| |
Compute a strong hash value for an arbitrary sequence of bytes. Use of this hash value should be secure against algorithmic complexity attacks, even for short keys. The computation uses a random seed which is generated on wmem initialization, so the same key will hash to different values on different runs of the application.
- Parameters
-
buf | The buffer of bytes (does not have to be aligned). |
len | The length of buf to use for the hash computation. |
- Returns
- The hash value.