API related to the bj_htable object.
More...
bj_htable is an associative container that maps a key to a value. The elements are stored in an array of linked lists called buckets.
|
typedef uint32_t(* | bj_hash_fn) (const void *p_data, size_t size) |
| Function type for hashing keys.
|
|
typedef struct bj_htable_t | bj_htable |
| Typedef for the bj_htable_t struct.
|
|
◆ bj_htable_new_t
#define bj_htable_new_t |
( |
| K, |
|
|
| V ) |
Value:
bj_htable * bj_htable_new(size_t bytes_key, size_t bytes_value)
Creates a new bj_htable with the specified sizes for keys and values.
- Parameters
-
K | Type of keys. |
V | Type of values. |
- Returns
- A pointer to the newly created bj_htable object.
- Examples
- htable.c.
◆ bj_htable_del()
◆ bj_htable_get()
void * bj_htable_get |
( |
const bj_htable * | table, |
|
|
const void * | p_key, |
|
|
void * | p_default ) |
- Parameters
-
table | The table object. |
p_key | The search key. |
p_default | The value returned if the key is not found. |
- Returns
- A pointer to the found value or
p_default
.
If table
does not contain a value for p_key
, the function returns p_default
.
- Examples
- htable.c.
◆ bj_htable_len()
size_t bj_htable_len |
( |
const bj_htable * | table | ) |
|
- Parameters
-
- Returns
- The number of elements in the table.
◆ bj_htable_new()
bj_htable * bj_htable_new |
( |
size_t | bytes_key, |
|
|
size_t | bytes_value ) |
- Parameters
-
bytes_key | Size of each key in bytes. |
bytes_value | Size of each value in bytes. |
- Returns
- A pointer to the newly created bj_htable object.
◆ bj_htable_set()
void * bj_htable_set |
( |
bj_htable * | table, |
|
|
void * | p_key, |
|
|
void * | p_value ) |
- Parameters
-
table | The table object. |
p_key | The key used to identify the value. |
p_value | A pointer to the value to insert. |
- Returns
- A pointer to the inserted value.
If the key already exists, the associated value is modified to store p_value
instead. Otherwise, a new entry is created and the (key, value) pair is stored.
- Weak / Strong ownership
When p_info->weak_owning
is set to BJ_TRUE, the container does not allocate any new memory for storing the actual data. Memory allocation is still needed for the container structure itself. In this case, the caller is responsible for the lifetime of the inserted objects (key and value).
When set to BJ_FALSE, the inserted data is copied into the container's internal memory using bj_memcpy.
- Examples
- htable.c.