forked from sylar-yin/sylar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_lru.cc
41 lines (32 loc) · 854 Bytes
/
test_lru.cc
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
#include "sylar/ds/lru_cache.h"
void test_lru() {
sylar::ds::LruCache<int, int> cache(30, 10);
for(int i = 0; i < 105; ++i) {
cache.set(i, i * 100);
}
for(int i = 0; i < 105; ++i) {
int v;
if(cache.get(i, v)) {
std::cout << "get: " << i << " - " << v << std::endl;
}
}
std::cout << cache.toStatusString() << std::endl;
}
void test_hash_lru() {
sylar::ds::HashLruCache<int, int> cache(2, 30, 10);
for(int i = 0; i < 105; ++i) {
cache.set(i, i * 100);
}
for(int i = 0; i < 105; ++i) {
int v;
if(cache.get(i, v)) {
std::cout << "get: " << i << " - " << v << std::endl;
}
}
std::cout << cache.toStatusString() << std::endl;
}
int main(int argc, char** argv) {
test_lru();
test_hash_lru();
return 0;
}