Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
kv_store.h File Reference
#include <stdint.h>
#include <stddef.h>
+ Include dependency graph for kv_store.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  kv_store_t
 

Functions

void kv_init (kv_store_t *kv, size_t capacity, size_t esize, uint32_t *keys, void *values, uint8_t *used)
 Initializes a key-value store.
 
int kv_exists (const kv_store_t *kv, uint32_t key)
 Checks if a key exists in the store.
 
int kv_set (kv_store_t *kv, uint32_t key, const void *value)
 Sets a value for a given key.
 
voidkv_get (const kv_store_t *kv, uint32_t key)
 Retrieves the value associated with a given key.
 
int kv_remove (kv_store_t *kv, uint32_t key)
 Removes a key-value pair from the store.
 

Data Structure Documentation

◆ kv_store_t

struct kv_store_t

Definition at line 11 of file kv_store.h.

Data Fields
size_t capacity
size_t esize
uint32_t * keys
uint8_t * used
uint8_t * values

Function Documentation

◆ kv_exists()

int kv_exists ( const kv_store_t kv,
uint32_t  key 
)

Checks if a key exists in the store.

Parameters
kvPointer to the kv_store_t structure.
keyThe key to check for existence.
Returns
1 if the key exists, 0 otherwise.

Definition at line 64 of file kv_store.c.

References foo, kv, and kv_find().

+ Here is the call graph for this function:

◆ kv_get()

void * kv_get ( const kv_store_t kv,
uint32_t  key 
)

Retrieves the value associated with a given key.

Parameters
kvPointer to the kv_store_t structure.
keyThe key to retrieve the value for.
Returns
Pointer to the value if the key exists, NULL otherwise.

Definition at line 111 of file kv_store.c.

References foo, kv, and kv_find().

Referenced by get_transfer_id().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ kv_init()

void kv_init ( kv_store_t kv,
size_t  capacity,
size_t  esize,
uint32_t keys,
void values,
uint8_t used 
)

Initializes a key-value store.

Parameters
kvPointer to the kv_store_t structure to initialize.
capacityThe maximum number of key-value pairs the store can hold.
esizeThe size in bytes of each value element.
keysPointer to an array of uint32_t for storing keys. At least "capacity" long.
valuesPointer to the memory area for storing values. At least "capacity * esize" long.
usedPointer to an array of uint8_t flags indicating if a slot is used. At least "capacity" long.

Definition at line 20 of file kv_store.c.

References kv.

Referenced by uavcanInitIface().

+ Here is the caller graph for this function:

◆ kv_remove()

int kv_remove ( kv_store_t kv,
uint32_t  key 
)

Removes a key-value pair from the store.

Parameters
kvPointer to the kv_store_t structure.
keyThe key to remove.
Returns
0 on success, -1 if the key was not found.

Definition at line 127 of file kv_store.c.

References kv, and kv_find().

+ Here is the call graph for this function:

◆ kv_set()

int kv_set ( kv_store_t kv,
uint32_t  key,
const void value 
)

Sets a value for a given key.

If the key already exists, its value is updated. If not, a new key-value pair is inserted into the first available slot. If the store is full, the operation fails.

Parameters
kvPointer to the kv_store_t structure.
keyThe key to set.
valuePointer to the value to store. Value will be memcpy in the store, so the pointer does not need to be valid afterward.
Returns
0 on success, -1 if the store is full.

Definition at line 79 of file kv_store.c.

References foo, kv, and kv_find().

Referenced by get_transfer_id().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: