-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.cpp
114 lines (85 loc) · 2.77 KB
/
buffer.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<iostream>
#include<string.h>
enum status_code { locked =1, unlocked, valid, invalid, delay_write};
class Buff_node{
public:
int blk_no;
int device_no;
int data;
status_code status;
Buff_node *fowd_free_list;
Buff_node *prev_free_list;
Buff_node *fowd_hash_list;
Buff_node *prev_hash_list;
int buff_no;
Buff_node(int i){
blk_no = 0;
device_no = 1;
fowd_free_list = nullptr;
prev_free_list = nullptr;
fowd_hash_list = nullptr;
prev_hash_list = nullptr;
buff_no = i;
data = 0;
}
};
class List{
private:
Buff_node *hashques[4];
Buff_node *fhead;
// Buff_node *hash1head,*hash1tail;
// Buff_node *hash2head,*hash2tail;
// Buff_node *hash3head,*hash3tail;
// Buff_node *hash4head,*hash4tail;
public:
List(){
fhead = nullptr;
for (int i = 0; i<4;++i){
hashques[i] = nullptr;
}
// hash1head = hash1tail = nullptr;
// hash2head = hash2tail = nullptr;
// hash3head = hash3tail = nullptr;
// hash4head = hash4tail = nullptr;
}
void CreatePool(int n);
void hashDisplay(const Buff_node *head) const;
void freeDisplay();
};
void List::CreatePool(int n){
Buff_node *temp = nullptr;
for(int i =0;i<n;++i){
Buff_node *newBuff = new Buff_node(i);
if (fhead == nullptr){
fhead = newBuff;
newBuff->fowd_free_list = fhead;
newBuff->prev_free_list = newBuff;
temp = newBuff;
}else{
temp->fowd_free_list = newBuff;
newBuff->prev_free_list = temp;
newBuff->fowd_free_list = fhead;
fhead->prev_free_list = newBuff;
temp = temp->fowd_free_list;
}
}
}
void List::freeDisplay(){
Buff_node *head = fhead;
if (head == nullptr){
std::cout<<"free list is empty"<<std::endl;
return;
}else{
Buff_node *temp = head;
do
{
std::cout<<"["<<temp->data<<":"<<temp->buff_no<<"], ";
temp = temp->fowd_free_list;
}while(temp != head );
}
}
int main(){
List l1;
l1.CreatePool(10);
l1.freeDisplay();
}