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

Go to the source code of this file.

Functions

void * find_in_cache_uint64 (struct CacheHeader *cache, const uint64_t key)
 Finds a value in the cache by uint64_t key.
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, evicting LRU if full.
void free_cache (struct CacheHeader *cache)
 Frees all entries in the cache and clears it.

Function Documentation

◆ 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, evicting LRU if full.

Adds a new entry to the cache. If the cache exceeds its maximum size, evicts the least recently used (oldest insertion-order) entry.

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

Definition at line 48 of file lru.c.

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

Referenced by aaruf_read_sector(), and ec_recover_data_block().

◆ 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.

Searches for a value using a native 64-bit integer key and promotes it to the front of the insertion-order list (LRU refresh) if found.

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 24 of file lru.c.

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

Referenced by aaruf_read_sector().

◆ free_cache()

void free_cache ( struct CacheHeader * cache)

Frees all entries in the cache and clears it.

Iterates through all cache entries, frees them, then clears the hash table. Uses the cache's free_func if set to free cached values.

Parameters
cachePointer to the cache header.

Definition at line 82 of file lru.c.

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

Referenced by aaruf_close().