A Keyed Collection Implementation. More...
#include "common.h"
Go to the source code of this file.
Data Structures | |
struct | qsc_collection_state |
Collection state structure. More... | |
Macros | |
#define | QSC_COLLECTION_KEY_WIDTH 16ULL |
The length (in bytes) of the key used to index collection items. | |
Functions | |
QSC_EXPORT_API void | qsc_collection_add (qsc_collection_state *ctx, const uint8_t *item, const uint8_t *key) |
Add an item to the collection. | |
QSC_EXPORT_API void | qsc_collection_deserialize (qsc_collection_state *ctx, const uint8_t *input) |
Deserialize a collection. | |
QSC_EXPORT_API void | qsc_collection_dispose (qsc_collection_state *ctx) |
Dispose of the collection. | |
QSC_EXPORT_API void | qsc_collection_erase (qsc_collection_state *ctx) |
Erase the collection. | |
QSC_EXPORT_API bool | qsc_collection_item_exists (const qsc_collection_state *ctx, const uint8_t *key) |
Check if an item exists in the collection. | |
QSC_EXPORT_API bool | qsc_collection_find (const qsc_collection_state *ctx, uint8_t *item, const uint8_t *key) |
Find an item in the collection. | |
QSC_EXPORT_API void | qsc_collection_initialize (qsc_collection_state *ctx, size_t width) |
Initialize the collection. | |
QSC_EXPORT_API void | qsc_collection_item (qsc_collection_state *ctx, uint8_t *item, size_t index) |
Retrieve a collection item by index. | |
QSC_EXPORT_API void | qsc_collection_remove (qsc_collection_state *ctx, const uint8_t *key) |
Remove an item from the collection. | |
QSC_EXPORT_API size_t | qsc_collection_serialize (uint8_t *output, const qsc_collection_state *ctx) |
Serialize the collection. | |
QSC_EXPORT_API size_t | qsc_collection_size (const qsc_collection_state *ctx) |
Get the serialized collection size. | |
A Keyed Collection Implementation.
This header defines the public API for a keyed collection that facilitates the storage, retrieval, and management of items associated with unique keys. Items are stored in a contiguous memory block with a fixed width (in bytes) specified at initialization. The API supports operations such as adding, removing, finding, serializing, and disposing of items.
QSC_EXPORT_API void qsc_collection_add | ( | qsc_collection_state * | ctx, |
const uint8_t * | item, | ||
const uint8_t * | key ) |
Add an item to the collection.
Adds a new item to the collection and associates it with the specified key.
ctx | [qsc_collection_state*] Pointer to the collection state. |
item | [const uint8_t*] Pointer to the item data to be added. |
key | [const uint8_t*] Pointer to the key that uniquely identifies the item. |
QSC_EXPORT_API void qsc_collection_deserialize | ( | qsc_collection_state * | ctx, |
const uint8_t * | input ) |
Deserialize a collection.
Converts a serialized byte array into a collection state.
ctx | [qsc_collection_state*] Pointer to the collection state that will be populated. |
input | [const uint8_t*] Pointer to the serialized collection data. |
QSC_EXPORT_API void qsc_collection_dispose | ( | qsc_collection_state * | ctx | ) |
Dispose of the collection.
Frees any allocated memory and clears the collection state.
ctx | [qsc_collection_state*] Pointer to the collection state to dispose. |
QSC_EXPORT_API void qsc_collection_erase | ( | qsc_collection_state * | ctx | ) |
Erase the collection.
Removes all items from the collection without deallocating the underlying storage.
ctx | [qsc_collection_state*] Pointer to the collection state to erase. |
QSC_EXPORT_API bool qsc_collection_find | ( | const qsc_collection_state * | ctx, |
uint8_t * | item, | ||
const uint8_t * | key ) |
Find an item in the collection.
Searches for an item by its key and copies it into the provided output buffer.
ctx | [const qsc_collection_state*] Pointer to the collection state. |
item | [uint8_t*] Pointer to the destination array that will receive the item data. |
key | [const uint8_t*] Pointer to the key of the item to find. |
QSC_EXPORT_API void qsc_collection_initialize | ( | qsc_collection_state * | ctx, |
size_t | width ) |
Initialize the collection.
Sets up the collection state for use by specifying the byte size of each item.
ctx | [qsc_collection_state*] Pointer to the collection state to initialize. |
width | [size_t] The fixed byte size of each item in the collection. |
QSC_EXPORT_API void qsc_collection_item | ( | qsc_collection_state * | ctx, |
uint8_t * | item, | ||
size_t | index ) |
Retrieve a collection item by index.
Copies the item at the specified index into the provided output buffer.
ctx | [qsc_collection_state*] Pointer to the collection state. |
item | [uint8_t*] Pointer to the array that will receive the item data. |
index | [size_t] The zero-based index of the item to retrieve. |
QSC_EXPORT_API bool qsc_collection_item_exists | ( | const qsc_collection_state * | ctx, |
const uint8_t * | key ) |
Check if an item exists in the collection.
Determines whether an item with the specified key exists in the collection.
ctx | [const qsc_collection_state*] Pointer to the collection state. |
key | [const uint8_t*] Pointer to the key of the item to check. |
QSC_EXPORT_API void qsc_collection_remove | ( | qsc_collection_state * | ctx, |
const uint8_t * | key ) |
Remove an item from the collection.
Removes the item associated with the specified key from the collection.
ctx | [qsc_collection_state*] Pointer to the collection state. |
key | [const uint8_t*] Pointer to the key of the item to remove. |
QSC_EXPORT_API size_t qsc_collection_serialize | ( | uint8_t * | output, |
const qsc_collection_state * | ctx ) |
Serialize the collection.
Converts the entire collection into a contiguous byte array for storage or transmission.
output | [uint8_t*] Pointer to the output buffer that will receive the serialized data. |
ctx | [const qsc_collection_state*] Pointer to the collection state. |
QSC_EXPORT_API size_t qsc_collection_size | ( | const qsc_collection_state * | ctx | ) |
Get the serialized collection size.
Calculates the total size in bytes that the serialized collection will occupy.
ctx | [const qsc_collection_state*] Pointer to the collection state. |