-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.cpp
More file actions
43 lines (42 loc) · 1.16 KB
/
Copy pathFile.cpp
File metadata and controls
43 lines (42 loc) · 1.16 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
#include "File.h"
bool File :: ReadFreeList(){
fstream file("../data/record/"+this->filename+"_FreeList.db", ios :: in );
if( !file.is_open() ) return false;
int n;
file >> n;
for(int i = 0 ; i < n ; i++ ){
RecordFreeList tmp = new FreeListNode;
tmp->next = NULL;
file >> tmp->BlockNum >> tmp->offset;
if( freelist == NULL ){
freelist = tmp;
}else{
tmp->next = freelist;
freelist = tmp;
}
}
return true;
}
void File :: WriteFreeList(){
fstream file("../data/record/"+this->filename+"_FreeList.db", ios :: out );
RecordFreeList now = freelist;
int cnt = 0;
while( now ){
now = now->next;
cnt++;
}
file << cnt << endl;
RecordFreeList next;
for( RecordFreeList now = freelist; now ; now = next){
next = now->next;
file << now->BlockNum << " " << now->offset << endl;
delete now;
}
}
void File :: ShowFreeList(){
RecordFreeList now = freelist;
while( now ){
cout << now->BlockNum << " " << now->offset << endl;
now = now->next;
}
}