|
libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
|
#include <stddef.h>#include <stdint.h>#include <uthash.h>Go to the source code of this file.
Data Structures | |
| struct | CacheEntry |
| Single hash entry in the in-memory cache. More... | |
| struct | CacheHeader |
| Cache top-level descriptor encapsulating the hash table root and capacity limit. More... | |
Functions | |
| void * | find_in_cache_uint64 (struct CacheHeader *cache, uint64_t key) |
| Finds a value in the cache by uint64_t key. | |
| void | add_to_cache_uint64 (struct CacheHeader *cache, uint64_t key, void *value, size_t size) |
| Adds a value to the cache with a uint64_t key, evicting LRU entries if over budget. | |
| void | free_cache (struct CacheHeader *cache) |
| Frees all entries in the cache and clears it. | |
| void add_to_cache_uint64 | ( | struct CacheHeader * | cache, |
| const uint64_t | key, | ||
| void * | value, | ||
| const size_t | size ) |
Adds a value to the cache with a uint64_t key, evicting LRU entries if over budget.
Adds a new entry to the cache. If an entry with the same key is already present, its value is freed and replaced. If the cache exceeds its memory budget, the least recently used entries are evicted until it fits again. The entry just inserted is never evicted, so the caller may keep using the pointer it handed over for the remainder of the call.
| cache | Pointer to the cache header. |
| key | 64-bit integer key to add. |
| value | Pointer to the value to store. |
| size | Size in bytes of the memory pointed to by value. |
Definition at line 68 of file lru.c.
References add_to_cache_uint64(), CacheHeader::cache, CacheHeader::cur_bytes, drop_entry(), CacheHeader::free_func, CacheEntry::hh, CacheEntry::key, CacheHeader::max_bytes, CacheEntry::size, and CacheEntry::value.
Referenced by aaruf_read_sector(), add_to_cache_uint64(), and ec_recover_data_block().
| 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.
| cache | Pointer to the cache header. |
| key | 64-bit integer key to search for. |
Definition at line 41 of file lru.c.
References CacheHeader::cache, find_in_cache_uint64(), CacheEntry::hh, CacheEntry::key, and CacheEntry::value.
Referenced by aaruf_read_sector(), and find_in_cache_uint64().
| 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.
| cache | Pointer to the cache header. |
Definition at line 118 of file lru.c.
References CacheHeader::cache, CacheHeader::cur_bytes, drop_entry(), free_cache(), and CacheEntry::hh.
Referenced by aaruf_close(), and free_cache().