forked from ChunelFeng/CGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTU02-Lru.cpp
More file actions
43 lines (35 loc) · 1.01 KB
/
Copy pathTU02-Lru.cpp
File metadata and controls
43 lines (35 loc) · 1.01 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
/***************************
@Author: Chunel
@Contact: chunel@foxmail.com
@File: TU02-Lru.cpp
@Time: 2021/9/19 12:43 上午
@Desc: 本例主要演示,Lru工具的使用方法
***************************/
#include "../src/CGraph.h"
using namespace CGraph;
void tutorial_lru() {
ULru<int, std::string, 3> lru;
lru.put(1, "one");
lru.put(2, "two");
lru.put(3, "three");
lru.put(4, "four"); // 此时,key=1的节点,已经被在缓存中删除了
lru.put(5, "five");
std::string val;
int key = 5;
// 返回值的 true的情况下,表示获取成功。否则表示未获取到 value 的值
if (lru.get(key, val)) {
CGRAPH_ECHO("key = %d, value is : [%s]", key, val.c_str());
} else {
CGRAPH_ECHO("[%d] no get value", key);
}
key = 6;
if (lru.get(key, val)) {
CGRAPH_ECHO("key = %d, value is : [%s]", key, val.c_str());
} else {
CGRAPH_ECHO("[%d] no get value", key);
}
}
int main() {
tutorial_lru();
return 0;
}