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
24{
25 uint64_t key;
26 void *value;
27 UT_hash_handle hh;
28};
29
42{
43 uint64_t max_items;
44 struct CacheEntry *cache;
45 void (*free_func)(void *);
46};
47
48void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key);
49void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value);
50void free_cache(struct CacheHeader *cache);
51
52#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, evicting LRU if full.
Definition lru.c:48
void * find_in_cache_uint64(struct CacheHeader *cache, uint64_t key)
Finds a value in the cache by uint64_t key.
Definition lru.c:24
void free_cache(struct CacheHeader *cache)
Frees all entries in the cache and clears it.
Definition lru.c:82
Single hash entry in the in-memory cache.
Definition lru.h:24
void * value
Opaque value pointer associated with key.
Definition lru.h:26
uint64_t key
64-bit integer key (unique within the cache).
Definition lru.h:25
UT_hash_handle hh
uthash handle (must remain per uthash docs).
Definition lru.h:27
Cache top-level descriptor encapsulating the hash table root and capacity limit.
Definition lru.h:42
struct CacheEntry * cache
Hash root (uthash). NULL when empty.
Definition lru.h:44
uint64_t max_items
Hard limit for number of entries.
Definition lru.h:43
void(* free_func)(void *)
Optional callback to free cached values. NULL if not needed.
Definition lru.h:45