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 <stddef.h>
9#include <stdint.h>
10#include <uthash.h>
11
25{
26 uint64_t key;
27 void *value;
28 size_t size;
29 UT_hash_handle hh;
30};
31
51{
52 uint64_t max_bytes;
53 uint64_t cur_bytes;
54 struct CacheEntry *cache;
55 void (*free_func)(void *);
56};
57
58void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key);
59void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value, size_t size);
60void free_cache(struct CacheHeader *cache);
61
62#endif // LIBAARUFORMAT_LRU_H
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.
Definition lru.c:68
void * find_in_cache_uint64(struct CacheHeader *cache, uint64_t key)
Finds a value in the cache by uint64_t key.
Definition lru.c:41
void free_cache(struct CacheHeader *cache)
Frees all entries in the cache and clears it.
Definition lru.c:118
Single hash entry in the in-memory cache.
Definition lru.h:25
void * value
Opaque value pointer associated with key.
Definition lru.h:27
size_t size
Size in bytes of the memory pointed to by value.
Definition lru.h:28
uint64_t key
64-bit integer key (unique within the cache).
Definition lru.h:26
UT_hash_handle hh
uthash handle (must remain per uthash docs).
Definition lru.h:29
Cache top-level descriptor encapsulating the hash table root and capacity limit.
Definition lru.h:51
struct CacheEntry * cache
Hash root (uthash). NULL when empty.
Definition lru.h:54
void(*) free_func(void *)
Optional callback to free cached values. NULL if not needed.
Definition lru.h:55
uint64_t cur_bytes
Bytes currently held by the cached values.
Definition lru.h:53
uint64_t max_bytes
Memory budget in bytes for the cached values. 0 means unlimited.
Definition lru.h:52