libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
lru.h
Go to the documentation of this file.
1//
2// Created by claunia on 2/10/22.
3//
4
5#ifndef LIBAARUFORMAT_LRU_H
6#define LIBAARUFORMAT_LRU_H
7
8#include <stdint.h>
9#include <uthash.h>
10
26 struct CacheEntry
27{
28 char *key;
29 void *value;
30 UT_hash_handle hh;
31};
32
45 struct CacheHeader
46{
47 uint64_t max_items;
48 struct CacheEntry *cache;
49};
50
51 void *find_in_cache(struct CacheHeader *cache, const char *key);
52 void add_to_cache(struct CacheHeader *cache, const char *key, void *value);
53 void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key);
54 void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value);
55
56#endif // LIBAARUFORMAT_LRU_H
add_to_cache_uint64
void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value)
Adds a value to the cache with a uint64_t key, using string conversion.
Definition lru.c:102
find_in_cache_uint64
void * find_in_cache_uint64(struct CacheHeader *cache, uint64_t key)
Finds a value in the cache by uint64_t key, using string conversion.
Definition lru.c:88
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.
Definition lru.c:47
find_in_cache
void * find_in_cache(struct CacheHeader *cache, const char *key)
Finds a value in the cache by string key.
Definition lru.c:24
CacheEntry
Single hash entry in the in-memory cache.
Definition lru.h:27
CacheEntry::value
void * value
Opaque value pointer associated with key (not freed automatically on eviction/clear).
Definition lru.h:29
CacheEntry::hh
UT_hash_handle hh
uthash handle linking this entry into the hash table (must remain last or per uthash docs).
Definition lru.h:30
CacheEntry::key
char * key
Null-terminated key string (unique within the cache). May encode numeric keys.
Definition lru.h:28
CacheHeader
Cache top-level descriptor encapsulating the hash table root and capacity limit.
Definition lru.h:46
CacheHeader::cache
struct CacheEntry * cache
Hash root (uthash). NULL when empty.
Definition lru.h:48
CacheHeader::max_items
uint64_t max_items
Hard limit for number of entries (policy: enforce/ignore depends on implementation).
Definition lru.h:47