libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
lru.c File Reference
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <uthash.h>
#include <aaruformat.h>

Go to the source code of this file.

Functions

void * find_in_cache (struct CacheHeader *cache, const char *key)
 Finds a value in the cache by string key.
void add_to_cache (struct CacheHeader *cache, const char *key, void *value)
 Adds a value to the cache with a string key, pruning if necessary.
static __attribute__ ((always_inline))
void * find_in_cache_uint64 (struct CacheHeader *cache, const uint64_t key)
 Finds a value in the cache by uint64_t key, using string conversion.
void add_to_cache_uint64 (struct CacheHeader *cache, const uint64_t key, void *value)
 Adds a value to the cache with a uint64_t key, using string conversion.

Function Documentation

◆ __attribute__()

__attribute__ ( (always_inline) )
inlinestatic

Definition at line 71 of file lru.c.

References FORCE_INLINE.

◆ add_to_cache()

void add_to_cache ( struct CacheHeader * cache,
const char * key,
void * value )

Adds a value to the cache with a string key, pruning if necessary.

Adds a new entry to the cache. If the cache exceeds its maximum size, prunes the least recently used entry.

Parameters
cachePointer to the cache header.
keyString key to add.
valuePointer to the value to store.

Definition at line 47 of file lru.c.

References CacheHeader::cache, CacheEntry::hh, CacheEntry::key, CacheHeader::max_items, and CacheEntry::value.

Referenced by add_to_cache_uint64().

◆ add_to_cache_uint64()

void add_to_cache_uint64 ( struct CacheHeader * cache,
const uint64_t key,
void * value )

Adds a value to the cache with a uint64_t key, using string conversion.

Converts the uint64_t key to a string and adds the entry to the cache.

Parameters
cachePointer to the cache header.
key64-bit integer key to add.
valuePointer to the value to store.

Definition at line 102 of file lru.c.

References add_to_cache(), CacheEntry::key, and CacheEntry::value.

Referenced by aaruf_read_sector().

◆ find_in_cache()

void * find_in_cache ( struct CacheHeader * cache,
const char * key )

Finds a value in the cache by string key.

Searches for a value in the cache using a string key and moves it to the front if found.

Parameters
cachePointer to the cache header.
keyString key to search for.
Returns
Pointer to the value if found, or NULL if not found.

Definition at line 24 of file lru.c.

References CacheHeader::cache, CacheEntry::hh, CacheEntry::key, and CacheEntry::value.

Referenced by find_in_cache_uint64().

◆ find_in_cache_uint64()

void * find_in_cache_uint64 ( struct CacheHeader * cache,
const uint64_t key )

Finds a value in the cache by uint64_t key, using string conversion.

Converts the uint64_t key to a string and searches for the entry in the cache.

Parameters
cachePointer to the cache header.
key64-bit integer key to search for.
Returns
Pointer to the value if found, or NULL if not found.

Definition at line 88 of file lru.c.

References find_in_cache(), and CacheEntry::key.

Referenced by aaruf_read_sector().