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
27{
28 char *key;
29 void *value;
30 UT_hash_handle hh;
31};
32
46{
47 uint64_t max_items;
48 struct CacheEntry *cache;
49};
50
51void *find_in_cache(struct CacheHeader *cache, const char *key);
52void add_to_cache(struct CacheHeader *cache, const char *key, void *value);
53void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key);
54void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value);
55
56#endif // LIBAARUFORMAT_LRU_H
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
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
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
void * find_in_cache(struct CacheHeader *cache, const char *key)
Finds a value in the cache by string key.
Definition lru.c:24
Single hash entry in the in-memory cache.
Definition lru.h:27
void * value
Opaque value pointer associated with key (not freed automatically on eviction/clear).
Definition lru.h:29
UT_hash_handle hh
uthash handle linking this entry into the hash table (must remain last or per uthash docs).
Definition lru.h:30
char * key
Null-terminated key string (unique within the cache). May encode numeric keys.
Definition lru.h:28
Cache top-level descriptor encapsulating the hash table root and capacity limit.
Definition lru.h:46
struct CacheEntry * cache
Hash root (uthash). NULL when empty.
Definition lru.h:48
uint64_t max_items
Hard limit for number of entries (policy: enforce/ignore depends on implementation).
Definition lru.h:47