Zephyr Project API
3.4.0
A Scalable Open Source RTOS
|
Data Structures | |
struct | sys_hashmap_iterator |
Generic Hashmap iterator interface. More... | |
struct | sys_hashmap_api |
Generic Hashmap API. More... | |
struct | sys_hashmap_config |
Generic Hashmap configuration. More... | |
struct | sys_hashmap_data |
Generic Hashmap data. More... | |
Macros | |
#define | SYS_HASHMAP_CONFIG(_max_size, _load_factor) |
Initializer for sys_hashmap_config . More... | |
Typedefs | |
typedef void *(* | sys_hashmap_allocator_t) (void *ptr, size_t new_size) |
Allocator interface for sys_hashmap. More... | |
typedef void(* | sys_hashmap_iterator_t) (const struct sys_hashmap *map, struct sys_hashmap_iterator *it) |
In-place iterator constructor for sys_hashmap. More... | |
typedef void(* | sys_hashmap_callback_t) (uint64_t key, uint64_t value, void *cookie) |
Callback interface for sys_hashmap. More... | |
typedef void(* | sys_hashmap_clear_t) (struct sys_hashmap *map, sys_hashmap_callback_t cb, void *cookie) |
Clear all entries contained in a sys_hashmap. More... | |
typedef int(* | sys_hashmap_insert_t) (struct sys_hashmap *map, uint64_t key, uint64_t value, uint64_t *old_value) |
Insert a new entry into a sys_hashmap. More... | |
typedef bool(* | sys_hashmap_remove_t) (struct sys_hashmap *map, uint64_t key, uint64_t *value) |
Remove an entry from a sys_hashmap. More... | |
typedef bool(* | sys_hashmap_get_t) (const struct sys_hashmap *map, uint64_t key, uint64_t *value) |
Get a value from a sys_hashmap. More... | |
Functions | |
static bool | sys_hashmap_iterator_has_next (const struct sys_hashmap_iterator *it) |
Check if a Hashmap iterator has a next entry. More... | |
static void * | sys_hashmap_default_allocator (void *ptr, size_t size) |
static void | sys_hashmap_foreach (const struct sys_hashmap *map, sys_hashmap_callback_t cb, void *cookie) |
Iterate over all values contained in a sys_hashmap. More... | |
static void | sys_hashmap_clear (struct sys_hashmap *map, sys_hashmap_callback_t cb, void *cookie) |
Clear all entries contained in a sys_hashmap. More... | |
static int | sys_hashmap_insert (struct sys_hashmap *map, uint64_t key, uint64_t value, uint64_t *old_value) |
Insert a new entry into a sys_hashmap. More... | |
static bool | sys_hashmap_remove (struct sys_hashmap *map, uint64_t key, uint64_t *value) |
Remove an entry from a sys_hashmap. More... | |
static bool | sys_hashmap_get (const struct sys_hashmap *map, uint64_t key, uint64_t *value) |
Get a value from a sys_hashmap. More... | |
static bool | sys_hashmap_contains_key (const struct sys_hashmap *map, uint64_t key) |
Check if map contains a value associated with key . More... | |
static size_t | sys_hashmap_size (const struct sys_hashmap *map) |
Query the number of entries contained within map . More... | |
static bool | sys_hashmap_is_empty (const struct sys_hashmap *map) |
Check if map is empty. More... | |
static uint8_t | sys_hashmap_load_factor (const struct sys_hashmap *map) |
Query the load factor of map . More... | |
static size_t | sys_hashmap_num_buckets (const struct sys_hashmap *map) |
Query the number of buckets used in map . More... | |
static bool | sys_hashmap_should_rehash (const struct sys_hashmap *map, bool grow, size_t num_reserved, size_t *new_num_buckets) |
Decide whether the Hashmap should be resized. More... | |
#define | SYS_HASHMAP_DEFINE_ADVANCED(_name, _api, _config_type, _data_type, _hash_func, _alloc_func, ...) |
Declare a Hashmap (advanced) More... | |
#define | SYS_HASHMAP_DEFINE_STATIC_ADVANCED(_name, _api, _config_type, _data_type, _hash_func, _alloc_func, ...) |
Declare a Hashmap (advanced) More... | |
#define | SYS_HASHMAP_DEFINE(_name) SYS_HASHMAP_DEFAULT_DEFINE(_name) |
Declare a Hashmap. More... | |
#define | SYS_HASHMAP_DEFINE_STATIC(_name) SYS_HASHMAP_DEFAULT_DEFINE_STATIC(_name) |
Declare a Hashmap statically. More... | |
#define | SYS_HASHMAP_DEFAULT_ALLOCATOR sys_hashmap_default_allocator |
#define | SYS_HASHMAP_DEFAULT_LOAD_FACTOR 75 |
The default Hashmap load factor (in hundredths) More... | |
#define SYS_HASHMAP_CONFIG | ( | _max_size, | |
_load_factor | |||
) |
#include <include/zephyr/sys/hash_map_api.h>
Initializer for sys_hashmap_config
.
This macro helps to initialize a structure of type sys_hashmap_config
.
_max_size | Maximum number of entries |
_load_factor | Maximum load factor of expressed in hundredths |
#define SYS_HASHMAP_DEFAULT_ALLOCATOR sys_hashmap_default_allocator |
#include <include/zephyr/sys/hash_map.h>
#define SYS_HASHMAP_DEFAULT_LOAD_FACTOR 75 |
#include <include/zephyr/sys/hash_map.h>
The default Hashmap load factor (in hundredths)
#define SYS_HASHMAP_DEFINE | ( | _name | ) | SYS_HASHMAP_DEFAULT_DEFINE(_name) |
#include <include/zephyr/sys/hash_map.h>
Declare a Hashmap.
Declare a Hashmap with default parameters.
_name | Name of the Hashmap. |
#define SYS_HASHMAP_DEFINE_ADVANCED | ( | _name, | |
_api, | |||
_config_type, | |||
_data_type, | |||
_hash_func, | |||
_alloc_func, | |||
... | |||
) |
#include <include/zephyr/sys/hash_map.h>
Declare a Hashmap (advanced)
Declare a Hashmap with control over advanced parameters.
_alloc
is used for allocating internal Hashmap entries and does not interact with any user-provided keys or values._name | Name of the Hashmap. |
_api | API pointer of type sys_hashmap_api. |
_config_type | Variant of sys_hashmap_config. |
_data_type | Variant of sys_hashmap_data. |
_hash_func | Hash function pointer of type sys_hash_func32_t. |
_alloc_func | Allocator function pointer of type sys_hashmap_allocator_t. |
... | Variant-specific details for _config_type . |
#define SYS_HASHMAP_DEFINE_STATIC | ( | _name | ) | SYS_HASHMAP_DEFAULT_DEFINE_STATIC(_name) |
#include <include/zephyr/sys/hash_map.h>
Declare a Hashmap statically.
Declare a Hashmap statically with default parameters.
_name | Name of the Hashmap. |
#define SYS_HASHMAP_DEFINE_STATIC_ADVANCED | ( | _name, | |
_api, | |||
_config_type, | |||
_data_type, | |||
_hash_func, | |||
_alloc_func, | |||
... | |||
) |
#include <include/zephyr/sys/hash_map.h>
Declare a Hashmap (advanced)
Declare a Hashmap with control over advanced parameters.
_alloc
is used for allocating internal Hashmap entries and does not interact with any user-provided keys or values._name | Name of the Hashmap. |
_api | API pointer of type sys_hashmap_api. |
_config_type | Variant of sys_hashmap_config. |
_data_type | Variant of sys_hashmap_data. |
_hash_func | Hash function pointer of type sys_hash_func32_t. |
_alloc_func | Allocator function pointer of type sys_hashmap_allocator_t. |
... | Variant-specific details for _config_type . |
#include <include/zephyr/sys/hash_map_api.h>
Allocator interface for sys_hashmap.
The Hashmap allocator can be any allocator that behaves similarly to realloc()
with the additional specification that the allocator behaves like free()
when new_size
is zero.
ptr | Previously allocated memory region or NULL to make a new vallocation. |
new_size | the new size of the allocation, in bytes. |
#include <include/zephyr/sys/hash_map_api.h>
Callback interface for sys_hashmap.
This callback is used by some Hashmap methods.
key | Key corresponding to value |
value | Value corresponding to key |
cookie | User-specified variable |
typedef void(* sys_hashmap_clear_t) (struct sys_hashmap *map, sys_hashmap_callback_t cb, void *cookie) |
#include <include/zephyr/sys/hash_map_api.h>
Clear all entries contained in a sys_hashmap.
map | Hashmap to clear |
cb | Callback to call for each entry |
cookie | User-specified variable |
#include <include/zephyr/sys/hash_map_api.h>
Get a value from a sys_hashmap.
Look-up the uint64_t associated with key
, if one exists.
map | Hashmap to search through |
key | Key with which to search map |
value | Location to store a potential value associated with key or NULL |
true | if map contains a value associated with key . |
false | if map does not contain a value associated with key . |
typedef int(* sys_hashmap_insert_t) (struct sys_hashmap *map, uint64_t key, uint64_t value, uint64_t *old_value) |
#include <include/zephyr/sys/hash_map_api.h>
Insert a new entry into a sys_hashmap.
Insert a new key
- value
pair into map
.
map | Hashmap to insert into |
key | Key to associate with value |
value | Value to associate with key |
old_value | Location to store the value previously associated with key or NULL |
0 | if value was inserted for an existing key, in which case old_value will contain the previous value |
1 | if a new entry was inserted for the key - value pair |
-ENOMEM | if memory allocation failed |
typedef void(* sys_hashmap_iterator_t) (const struct sys_hashmap *map, struct sys_hashmap_iterator *it) |
#include <include/zephyr/sys/hash_map_api.h>
In-place iterator constructor for sys_hashmap.
Construct an iterator, it
, for map
.
map | Hashmap to iterate over. |
it | Iterator to initialize. |
#include <include/zephyr/sys/hash_map_api.h>
Remove an entry from a sys_hashmap.
Erase the entry associated with key key
, if one exists.
map | Hashmap to remove from |
key | Key to remove from map |
value | Location to store a potential value associated with key or NULL |
true | if map was modified as a result of this operation. |
false | if map does not contain a value associated with key . |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Clear all entries contained in a sys_hashmap.
map | Hashmap to clear |
cb | Callback to call for each entry |
cookie | User-specified variable |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Check if map
contains a value associated with key
.
map | Hashmap to search through |
key | Key with which to search map |
true | if map contains a value associated with key . |
false | if map does not contain a value associated with key . |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Iterate over all values contained in a sys_hashmap.
map | Hashmap to iterate over |
cb | Callback to call for each entry |
cookie | User-specified variable |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Get a value from a sys_hashmap.
Look-up the uint64_t associated with key
, if one exists.
map | Hashmap to search through |
key | Key with which to search map |
value | Location to store a potential value associated with key or NULL |
true | if map contains a value associated with key . |
false | if map does not contain a value associated with key . |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Insert a new entry into a sys_hashmap.
Insert a new key
- value
pair into map
.
map | Hashmap to insert into |
key | Key to associate with value |
value | Value to associate with key |
old_value | Location to store the value previously associated with key or NULL |
0 | if value was inserted for an existing key, in which case old_value will contain the previous value |
1 | if a new entry was inserted for the key - value pair |
-ENOMEM | if memory allocation failed |
-ENOSPC | if the size limit has been reached |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Check if map
is empty.
map | Hashmap to query |
true | if map is empty. |
false | if map is not empty. |
|
inlinestatic |
#include <include/zephyr/sys/hash_map_api.h>
Check if a Hashmap iterator has a next entry.
it | Hashmap iterator |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Query the load factor of map
.
sys_hash_load_factor(map) / 100.0f
.map | Hashmap to query |
map
expressed in hundredths.
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Query the number of buckets used in map
.
map | Hashmap to query |
map
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Remove an entry from a sys_hashmap.
Erase the entry associated with key key
, if one exists.
map | Hashmap to remove from |
key | Key to remove from map |
value | Location to store a potential value associated with key or NULL |
true | if map was modified as a result of this operation. |
false | if map does not contain a value associated with key . |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Decide whether the Hashmap should be resized.
This is a simple opportunistic method that implementations can choose to use. It will grow and shrink the Hashmap by a factor of 2 when insertion / removal would exceed / fall into the specified load factor.
map | Hashmap to examine | |
grow | true if an entry is to be added. false if an entry has been removed | |
num_reserved | the number of reserved entries | |
[out] | new_num_buckets | variable Hashmap size |
|
inlinestatic |
#include <include/zephyr/sys/hash_map.h>
Query the number of entries contained within map
.
map | Hashmap to search through |
map
.