Mstdlib-1.24.0
|
Data Structures | |
struct | M_cache_callbacks |
Typedefs | |
typedef struct M_cache | M_cache_t |
typedef void *(* | M_cache_duplicate_func) (const void *) |
typedef void(* | M_cache_free_func) (void *) |
Enumerations | |
enum | M_cache_flags_t { M_CACHE_NONE = 0 } |
Functions | |
M_cache_t * | M_cache_create (size_t max_size, M_hashtable_hash_func key_hash, M_sort_compar_t key_equality, M_uint32 flags, const struct M_cache_callbacks *callbacks) M_MALLOC |
void | M_cache_destroy (M_cache_t *c) |
M_bool | M_cache_insert (M_cache_t *c, const void *key, const void *value) |
M_bool | M_cache_remove (M_cache_t *c, const void *key) |
M_bool | M_cache_get (const M_cache_t *c, const void *key, void **value) |
size_t | M_cache_size (const M_cache_t *c) |
size_t | M_cache_max_size (const M_cache_t *c) |
M_bool | M_cache_set_max_size (M_cache_t *c, size_t max_size) |
Hot cache.
struct M_cache_callbacks |
Structure of callbacks that can be registered to override default behavior for implementation.
Data Fields | ||
---|---|---|
M_cache_duplicate_func | key_duplicate |
Callback to duplicate a key. Default if NULL is pass-thru pointer |
M_cache_free_func | key_free |
Callback to free a key. Default if NULL is no-op |
M_cache_duplicate_func | value_duplicate |
Callback to duplicate a value. Default if NULL is pass-thru pointer |
M_cache_free_func | value_free |
Callback to free a value. Default if NULL is a no-op |
typedef struct M_cache M_cache_t |
typedef void *(* M_cache_duplicate_func) (const void *) |
Function definition to duplicate a value.
typedef void(* M_cache_free_func) (void *) |
Function definition to free a value.
enum M_cache_flags_t |
M_cache_t * M_cache_create | ( | size_t | max_size, |
M_hashtable_hash_func | key_hash, | ||
M_sort_compar_t | key_equality, | ||
M_uint32 | flags, | ||
const struct M_cache_callbacks * | callbacks | ||
) |
Create a cache.
[in] | max_size | Maximum number of entries in the cache. |
[in] | key_hash | The function to use for hashing a key. If not specified will use the pointer address as the key. |
[in] | key_equality | The function to use to determine if two keys are equal. If not specified, will compare pointer addresses. |
[in] | flags | M_hash_strvp_flags_t flags for modifying behavior. |
[in] | callbacks | Register callbacks for overriding default behavior. |
void M_cache_destroy | ( | M_cache_t * | c | ) |
Destroy the cache.
[in] | c | Cache to destroy |
M_bool M_cache_insert | ( | M_cache_t * | c, |
const void * | key, | ||
const void * | value | ||
) |
Insert an entry into the cache.
[in] | c | Cache being referenced. |
[in] | key | Key to insert. |
[in] | value | Value to insert into h. The c will take ownership of the value. Maybe NULL. |
M_bool M_cache_remove | ( | M_cache_t * | c, |
const void * | key | ||
) |
Remove an entry from the cache.
[in] | c | Cache being referenced. |
[in] | key | Key to remove from the h. |
M_bool M_cache_get | ( | const M_cache_t * | c, |
const void * | key, | ||
void ** | value | ||
) |
Retrieve the value for a key from the cache.
[in] | c | Cache being referenced. |
[in] | key | Key for value. |
[out] | value | Pointer to value stored in the h. Optional, pass NULL if not needed. |
size_t M_cache_size | ( | const M_cache_t * | c | ) |
Get the number of items in the cache.
[in] | c | Cache being referenced. |
size_t M_cache_max_size | ( | const M_cache_t * | c | ) |
Get the maximum number of items allowed in the cache.
[in] | c | Cache being referenced. |
M_bool M_cache_set_max_size | ( | M_cache_t * | c, |
size_t | max_size | ||
) |
Set the maximum number of items allowed in the cache.
This can be used to increase or decrease the maximum size of the cache. If the max size is smaller than the number of items in the cache, older items will be removed.
[in] | c | Cache being referenced. |
[in] | max_size | Maximum size. |