Files
libaaruformat/include/aaruformat/lru.h

57 lines
1.2 KiB
C
Raw Normal View History

2022-10-02 16:05:25 +01:00
//
// Created by claunia on 2/10/22.
//
#ifndef LIBAARUFORMAT_LRU_H
#define LIBAARUFORMAT_LRU_H
#include <stdint.h>
#include <uthash.h>
struct CacheEntry
{
2024-04-30 15:51:32 +01:00
char *key;
void *value;
2022-10-02 16:05:25 +01:00
UT_hash_handle hh;
};
struct CacheHeader
{
uint64_t max_items;
2024-04-30 15:51:32 +01:00
struct CacheEntry *cache;
2022-10-02 16:05:25 +01:00
};
/**
* Finds an item in the specified cache
* @param cache Pointer to the cache header
* @param key Key
* @return Value if found, NULL if not
*/
2024-04-30 15:51:32 +01:00
void *find_in_cache(struct CacheHeader *cache, char *key);
2022-10-02 16:05:25 +01:00
/**
* Adds an item to the specified cache
* @param cache Pointer to the cache header
* @param key Key
* @param value Value
*/
2024-04-30 15:51:32 +01:00
void add_to_cache(struct CacheHeader *cache, char *key, void *value);
2022-10-02 16:05:25 +01:00
/**
* Finds an item in the specified cache using a 64-bit integer key
* @param cache Pointer to the cache header
* @param key Key
* @return Value if found, NULL if not
*/
2024-04-30 15:51:32 +01:00
void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key);
2022-10-02 16:05:25 +01:00
/**
* Adds an item to the specified cache using a 64-bit integer key
* @param cache Pointer to the cache header
* @param key Key
* @param value Value
*/
2024-04-30 15:51:32 +01:00
void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value);
2022-10-02 16:05:25 +01:00
2024-04-30 15:51:32 +01:00
#endif // LIBAARUFORMAT_LRU_H