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_tM_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)
 

Detailed Description

Hot cache.


Data Structure Documentation

◆ M_cache_callbacks

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 Documentation

◆ M_cache_t

typedef struct M_cache M_cache_t

◆ M_cache_duplicate_func

typedef void *(* M_cache_duplicate_func) (const void *)

Function definition to duplicate a value.

◆ M_cache_free_func

typedef void(* M_cache_free_func) (void *)

Function definition to free a value.

Enumeration Type Documentation

◆ M_cache_flags_t

Flags for controlling the behavior of the hash

Enumerator
M_CACHE_NONE 

Default.

Function Documentation

◆ M_cache_create()

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.

Parameters
[in]max_sizeMaximum number of entries in the cache.
[in]key_hashThe function to use for hashing a key. If not specified will use the pointer address as the key.
[in]key_equalityThe function to use to determine if two keys are equal. If not specified, will compare pointer addresses.
[in]flagsM_hash_strvp_flags_t flags for modifying behavior.
[in]callbacksRegister callbacks for overriding default behavior.
Returns
Allocated cache.
See also
M_cache_destroy

◆ M_cache_destroy()

void M_cache_destroy ( M_cache_t c)

Destroy the cache.

Parameters
[in]cCache to destroy

◆ M_cache_insert()

M_bool M_cache_insert ( M_cache_t c,
const void *  key,
const void *  value 
)

Insert an entry into the cache.

Parameters
[in]cCache being referenced.
[in]keyKey to insert.
[in]valueValue to insert into h. The c will take ownership of the value. Maybe NULL.
Returns
M_TRUE on success, or M_FALSE on failure.

◆ M_cache_remove()

M_bool M_cache_remove ( M_cache_t c,
const void *  key 
)

Remove an entry from the cache.

Parameters
[in]cCache being referenced.
[in]keyKey to remove from the h.
Returns
M_TRUE on success, or M_FALSE if key does not exist.

◆ M_cache_get()

M_bool M_cache_get ( const M_cache_t c,
const void *  key,
void **  value 
)

Retrieve the value for a key from the cache.

Parameters
[in]cCache being referenced.
[in]keyKey for value.
[out]valuePointer to value stored in the h. Optional, pass NULL if not needed.
Returns
M_TRUE if value retrieved, M_FALSE if key does not exist.

◆ M_cache_size()

size_t M_cache_size ( const M_cache_t c)

Get the number of items in the cache.

Parameters
[in]cCache being referenced.
Returns
Count.

◆ M_cache_max_size()

size_t M_cache_max_size ( const M_cache_t c)

Get the maximum number of items allowed in the cache.

Parameters
[in]cCache being referenced.
Returns
Max.

◆ M_cache_set_max_size()

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.

Parameters
[in]cCache being referenced.
[in]max_sizeMaximum size.
Returns
M_TRUE if the max size was changed, otherwise M_FALSE on error.