Flash Translation Layer  1.0
Data Structures | Typedefs | Functions
lru.h File Reference

data structures and interfaces for the lru cache More...

#include <stdint.h>
#include <stdlib.h>
#include "log.h"
Include dependency graph for lru.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lru_node
 doubly-linked list data structure More...
 
struct  lru_cache
 main LRU cache data structure More...
 

Typedefs

typedef int(* lru_dealloc_fn) (const uint64_t, uintptr_t)
 deallocate the value for eviction function type. 0 means successfully evicted More...
 

Functions

struct lru_cachelru_init (const size_t capacity, lru_dealloc_fn deallocate)
 initialize the LRU cache data strcture More...
 
int lru_put (struct lru_cache *cache, const uint64_t key, uintptr_t value)
 inser the key, value to the LRU cache More...
 
uintptr_t lru_get (struct lru_cache *cache, const uint64_t key)
 get data from the LRU cache More...
 
int lru_free (struct lru_cache *cache)
 deallocate the LRU cache structure More...
 
static size_t lru_get_evict_size (struct lru_cache *cache)
 get evict size of the LRU cache More...
 

Detailed Description

data structures and interfaces for the lru cache

Author
Gijun Oh
Version
0.1
Date
2021-09-30
Note
This is not thread-safe.

Typedef Documentation

◆ lru_dealloc_fn

typedef int(* lru_dealloc_fn) (const uint64_t, uintptr_t)

deallocate the value for eviction function type. 0 means successfully evicted

Function Documentation

◆ lru_free()

int lru_free ( struct lru_cache cache)

deallocate the LRU cache structure

Parameters
cacheLRU cache data structure pointer
Returns
0 to success

◆ lru_get()

uintptr_t lru_get ( struct lru_cache cache,
const uint64_t  key 
)

get data from the LRU cache

Parameters
cacheLRU cache data structrue pointer
keykey which identifies the node
Returns
data in the node's value
Here is the call graph for this function:

◆ lru_get_evict_size()

static size_t lru_get_evict_size ( struct lru_cache cache)
static

get evict size of the LRU cache

Parameters
cacheLRU cache structrue pointer
Returns
number of the eviction entries
Note
Default LRU cache's eviction size is 30% of its capacity

◆ lru_init()

struct lru_cache* lru_init ( const size_t  capacity,
lru_dealloc_fn  deallocate 
)

initialize the LRU cache data strcture

Parameters
capacitynumber of the entries to insert the LRU
deallocatedeallcation function for LRU's value
Returns
initialized LRU cache data structure pointer
Here is the call graph for this function:

◆ lru_put()

int lru_put ( struct lru_cache cache,
const uint64_t  key,
uintptr_t  value 
)

inser the key, value to the LRU cache

Parameters
cacheLRU cache data structure pointer
keykey which identifies the node
valuevalue which contains the data
Returns
0 to success
Here is the call graph for this function: