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