-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlru_cache.h
More file actions
60 lines (50 loc) · 1.59 KB
/
lru_cache.h
File metadata and controls
60 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (c) 2024, Manolache Maria-Catalina 313CA
*/
#ifndef LRU_CACHE_H
#define LRU_CACHE_H
#include <stdbool.h>
#include "structs.h"
/* lru cache este implementat printr-un hashtable unde cheia este numele
* documentului si valoarea este un pointer la un nod din lista dublu inlantuita
* care contine informatiile despre document
*/
typedef struct lru_cache {
hashtable_t *lru_ht;
dll_t *lru_dll;
} lru_cache;
lru_cache *init_lru_cache(unsigned int cache_capacity);
bool lru_cache_is_full(lru_cache *cache);
void free_lru_cache(lru_cache **cache);
/**
* lru_cache_put() - Adds a new pair in our cache.
*
* @param cache: Cache where the key-value pair will be stored.
* @param key: Key of the pair.
* @param value: Value of the pair.
* @param evicted_key: The function will RETURN via this parameter the
* key removed from cache if the cache was full.
*
* @return - true if the key was added to the cache,
* false if the key already existed.
*/
bool lru_cache_put(lru_cache *cache, void *key, void *value,
void **evicted_key);
/**
* lru_cache_get() - Retrieves the value associated with a key.
*
* @param cache: Cache where the key-value pair is stored.
* @param key: Key of the pair.
*
* @return - The value associated with the key,
* or NULL if the key is not found.
*/
void *lru_cache_get(lru_cache *cache, void *key);
/**
* lru_cache_remove() - Removes a key-value pair from the cache.
*
* @param cache: Cache where the key-value pair is stored.
* @param key: Key of the pair.
*/
void lru_cache_remove(lru_cache *cache, void *key);
#endif /* LRU_CACHE_H */