Covalent Bond  0.0.1-alpha
'covalent bond' is a data middle office. As a 2022-2023 Fall SWE final project.
Public Member Functions | Private Member Functions | Private Attributes | List of all members
cb::cbLRUCache< V > Class Template Reference

We used LRU alogrithm to implement our cache. More...

#include <cbLRUCache.hpp>

Collaboration diagram for cb::cbLRUCache< V >:
Collaboration graph
[legend]

Public Member Functions

 cbLRUCache (int32_t max_size)
 Construct a new cb Least Recently Use Cache object. More...
 
 ~cbLRUCache ()
 Destroy the cb Least Recently Use Cache object. More...
 
void push (std::string key, V value)
 Push key and value into cache. If key has been existed, the corresponding value will be update. More...
 
V * get (const std::string &key)
 Get the value of corresponding key of input, if key doesn't exist, it will return null pointer. More...
 

Private Member Functions

void eraseTail ()
 delete the last element of list More...
 
void update (const std::string &key)
 move the node has been used recently to the top of cache list More...
 
void insertTop (const std::string &key)
 transit the node choosen to the top of list More...
 
void __loop_map ()
 loop in cachae list and map More...
 

Private Attributes

int32_t m_maxSize
 
int32_t m_sizeCounter
 
nodem_bufNode
 
std::string m_bufKey
 
std::list< nodem_cacheList
 
std::map< std::string, V > m_cacheMap
 

Detailed Description

template<typename V>
class cb::cbLRUCache< V >

We used LRU alogrithm to implement our cache.

Template Parameters
VYou can set any type of value and key only support string

Definition at line 39 of file cbLRUCache.hpp.

Constructor & Destructor Documentation

◆ cbLRUCache()

template<typename V >
cb::cbLRUCache< V >::cbLRUCache ( int32_t  max_size)
inline

Construct a new cb Least Recently Use Cache object.

Parameters
max_sizeMaximum sixe of cache

Definition at line 46 of file cbLRUCache.hpp.

◆ ~cbLRUCache()

template<typename V >
cb::cbLRUCache< V >::~cbLRUCache ( )
inline

Destroy the cb Least Recently Use Cache object.

Definition at line 52 of file cbLRUCache.hpp.

References cb::cbLRUCache< V >::m_bufNode.

Member Function Documentation

◆ __loop_map()

template<typename V >
void cb::cbLRUCache< V >::__loop_map ( )
inlineprivate

loop in cachae list and map

Definition at line 144 of file cbLRUCache.hpp.

References cb::cbLRUCache< V >::m_cacheList, and cb::cbLRUCache< V >::m_cacheMap.

◆ eraseTail()

template<typename V >
void cb::cbLRUCache< V >::eraseTail ( )
inlineprivate

delete the last element of list

Definition at line 103 of file cbLRUCache.hpp.

References cb::listNode::key, cb::cbLRUCache< V >::m_bufKey, cb::cbLRUCache< V >::m_bufNode, cb::cbLRUCache< V >::m_cacheList, and cb::cbLRUCache< V >::m_cacheMap.

Referenced by cb::cbLRUCache< V >::push().

Here is the caller graph for this function:

◆ get()

template<typename V >
V* cb::cbLRUCache< V >::get ( const std::string &  key)
inline

Get the value of corresponding key of input, if key doesn't exist, it will return null pointer.

Parameters
keykey of cache map
Returns
V* the pointer of type V

Definition at line 86 of file cbLRUCache.hpp.

References cb::cbLRUCache< V >::m_cacheMap, and cb::cbLRUCache< V >::update().

Here is the call graph for this function:

◆ insertTop()

template<typename V >
void cb::cbLRUCache< V >::insertTop ( const std::string &  key)
inlineprivate

transit the node choosen to the top of list

Parameters
keykey of cache map

Definition at line 132 of file cbLRUCache.hpp.

References cb::listNode::key, cb::cbLRUCache< V >::m_bufNode, and cb::cbLRUCache< V >::m_cacheList.

Referenced by cb::cbLRUCache< V >::push(), and cb::cbLRUCache< V >::update().

Here is the caller graph for this function:

◆ push()

template<typename V >
void cb::cbLRUCache< V >::push ( std::string  key,
value 
)
inline

Push key and value into cache. If key has been existed, the corresponding value will be update.

Parameters
keykey of cache map
valuevalue of cache map

Definition at line 61 of file cbLRUCache.hpp.

References cb::cbLRUCache< V >::eraseTail(), find_list, cb::cbLRUCache< V >::insertTop(), cb::cbLRUCache< V >::m_cacheMap, cb::cbLRUCache< V >::m_maxSize, cb::cbLRUCache< V >::m_sizeCounter, and cb::cbLRUCache< V >::update().

Here is the call graph for this function:

◆ update()

template<typename V >
void cb::cbLRUCache< V >::update ( const std::string &  key)
inlineprivate

move the node has been used recently to the top of cache list

Parameters
keykey of cache map

Definition at line 117 of file cbLRUCache.hpp.

References find_list, cb::cbLRUCache< V >::insertTop(), and cb::cbLRUCache< V >::m_cacheList.

Referenced by cb::cbLRUCache< V >::get(), and cb::cbLRUCache< V >::push().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bufKey

template<typename V >
std::string cb::cbLRUCache< V >::m_bufKey
private

Definition at line 158 of file cbLRUCache.hpp.

Referenced by cb::cbLRUCache< V >::eraseTail().

◆ m_bufNode

template<typename V >
node* cb::cbLRUCache< V >::m_bufNode
private

◆ m_cacheList

template<typename V >
std::list<node> cb::cbLRUCache< V >::m_cacheList
private

◆ m_cacheMap

template<typename V >
std::map<std::string, V> cb::cbLRUCache< V >::m_cacheMap
private

◆ m_maxSize

template<typename V >
int32_t cb::cbLRUCache< V >::m_maxSize
private

Definition at line 155 of file cbLRUCache.hpp.

Referenced by cb::cbLRUCache< V >::push().

◆ m_sizeCounter

template<typename V >
int32_t cb::cbLRUCache< V >::m_sizeCounter
private

Definition at line 156 of file cbLRUCache.hpp.

Referenced by cb::cbLRUCache< V >::push().


The documentation for this class was generated from the following file: