Skip to content

Commit 01438a6

Browse files
committed
docs: document namespace and classes
1 parent e959379 commit 01438a6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

others/lfu_cache.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @brief Implementation for [LFU Cache]
44
* (https://en.wikipedia.org/wiki/Least_frequently_used)
55
*
6+
* @details
67
* LFU discards the least frequently used value. if there are multiple items
78
* with the same minimum frequency then, the least recently used among them is
89
* discarded. Data structures used - doubly linked list and unordered_map(hash
@@ -28,8 +29,17 @@
2829
* @brief Other algorithms
2930
*/
3031
namespace others {
32+
33+
/**
34+
* @namespace
35+
* @brief Cache algorithm
36+
*/
3137
namespace Cache {
3238

39+
/**
40+
* @class
41+
* @brief Node for a doubly linked list with data, prev and next pointers
42+
*/
3343
template <typename T>
3444
class D_Node {
3545
public:
@@ -43,15 +53,19 @@ class D_Node {
4353
template <typename K, typename V>
4454
using CacheNode = D_Node<std::pair<K, V>>;
4555

56+
/**
57+
* @class
58+
* @brief LFUCache
59+
*/
4660
template <typename K, typename V>
4761
class LFUCache {
4862
std::unordered_map<K, std::pair<CacheNode<K, V> *, int>>
49-
node_map; // maps the key to the node address and frequency
63+
node_map; ///< maps the key to the node address and frequency
5064
std::unordered_map<int, std::pair<CacheNode<K, V> *, CacheNode<K, V> *>>
51-
freq_map; // maps the frequency to doubly linked list
65+
freq_map; ///< maps the frequency to doubly linked list
5266

53-
int minFreq; // minimum frequency in the cache
54-
int _capacity; // maximum capacity of the cache
67+
int minFreq; ///< minimum frequency in the cache
68+
int _capacity; ///< maximum capacity of the cache
5569

5670
public:
5771
/**
@@ -281,7 +295,6 @@ void test2() {
281295
* @brief test method with 2 tests
282296
* @return void
283297
*/
284-
285298
void test() {
286299
test1();
287300
test2();
@@ -291,8 +304,7 @@ void test() {
291304
* @brief main function
292305
* @return 0 on exit
293306
*/
294-
295307
int main() {
296308
test();
297309
return 0;
298-
}
310+
}

0 commit comments

Comments
 (0)