forked from yangxu02/LFUCache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFreqNode.h
56 lines (41 loc) · 1.01 KB
/
FreqNode.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef __LFU_CACHE_FREQ_NODE_H__
#define __LFU_CACHE_FREQ_NODE_H__
#include <iostream>
#include <sstream>
#include "ItemNode.h"
#include "DoubleLinkedList.h"
struct FreqNode : Node {
DoubleLinkedList itemList;
int freq;
FreqNode(int freq): freq(freq) {}
~FreqNode() {
itemList.setHead(NULL);
itemList.setTail(NULL);
}
void addItem(ItemNode* node) {
node->parent = this;
this->itemList.addNode(node);
}
void removeItem(ItemNode* node) {
this->itemList.removeNode(node);
}
Node* removeHeader() {
Node* node = this->itemList.getHead();
this->itemList.removeNode(node);
return node;
}
Node* removeTail() {
Node* node = this->itemList.getTail();
this->itemList.removeNode(node);
return node;
}
int count() {
return this->itemList.count();
}
std::string repr() {
std::stringstream ss;
ss << "freq=" << freq;
return ss.str();
}
};
#endif