Mstdlib-1.24.0
Cache - String/Void Pointer

Typedefs

typedef struct M_cache_strvp M_cache_strvp_t
 

Enumerations

enum  M_cache_strvp_flags_t {
  M_CACHE_STRVP_NONE = 0 ,
  M_CACHE_STRVP_CASECMP = 1 << 0
}
 

Functions

M_cache_strvp_tM_cache_strvp_create (size_t max_size, M_uint32 flags, void(*destroy_func)(void *)) M_MALLOC_ALIASED
 
void M_cache_strvp_destroy (M_cache_strvp_t *c)
 
M_bool M_cache_strvp_insert (M_cache_strvp_t *c, const char *key, const void *value)
 
M_bool M_cache_strvp_remove (M_cache_strvp_t *c, const char *key)
 
M_bool M_cache_strvp_get (const M_cache_strvp_t *c, const char *key, void **value)
 
void * M_cache_strvp_get_direct (const M_cache_strvp_t *c, const char *key)
 
size_t M_cache_strvp_size (const M_cache_strvp_t *c)
 
size_t M_cache_strvp_max_size (const M_cache_strvp_t *c)
 
M_bool M_cache_strvp_set_max_size (M_cache_strvp_t *c, size_t max_size)
 

Detailed Description

Hot cache meant for storing string keys and void pointer values.

Typedef Documentation

◆ M_cache_strvp_t

typedef struct M_cache_strvp M_cache_strvp_t

Enumeration Type Documentation

◆ M_cache_strvp_flags_t

Flags for controlling the behavior of the hash

Enumerator
M_CACHE_STRVP_NONE 

Default.

M_CACHE_STRVP_CASECMP 

Compare keys case insensitive.

Function Documentation

◆ M_cache_strvp_create()

M_cache_strvp_t * M_cache_strvp_create ( size_t  max_size,
M_uint32  flags,
void(*)(void *)  destroy_func 
)

Create a cache.

Parameters
[in]max_sizeMaximum number of entries in the cache.
[in]flagsM_hash_strvp_flags_t flags for modifying behavior.
[in]destroy_funcThe function to be called to destroy value when removed.
Returns
Allocated cache.
See also
M_cache_strvp_destroy

◆ M_cache_strvp_destroy()

void M_cache_strvp_destroy ( M_cache_strvp_t c)

Destroy the cache.

Parameters
[in]cCache to destroy

◆ M_cache_strvp_insert()

M_bool M_cache_strvp_insert ( M_cache_strvp_t c,
const char *  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_strvp_remove()

M_bool M_cache_strvp_remove ( M_cache_strvp_t c,
const char *  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_strvp_get()

M_bool M_cache_strvp_get ( const M_cache_strvp_t c,
const char *  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_strvp_get_direct()

void * M_cache_strvp_get_direct ( const M_cache_strvp_t c,
const char *  key 
)

Retrieve the value for a key from the cache, and return it directly as the return value.

This cannot be used if you need to differentiate between a key that doesn't exist vs a key with a NULL value.

Parameters
[in]cCache being referenced.
[in]keyKey for value to retrieve from the hashtable. A NULL or empty string is explicitly disallowed.
Returns
NULL if key doesn't exist or NULL value on file, otherwise the value.

◆ M_cache_strvp_size()

size_t M_cache_strvp_size ( const M_cache_strvp_t c)

Get the number of items in the cache.

Parameters
[in]cCache being referenced.
Returns
Count.

◆ M_cache_strvp_max_size()

size_t M_cache_strvp_max_size ( const M_cache_strvp_t c)

Get the maximum number of items allowed in the cache.

Parameters
[in]cCache being referenced.
Returns
Max.

◆ M_cache_strvp_set_max_size()

M_bool M_cache_strvp_set_max_size ( M_cache_strvp_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.