-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIndexT.cpp
48 lines (41 loc) · 1.12 KB
/
IndexT.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
#include "IndexT.h"
//Index Record in ROM
IndexRec::IndexRec() :
fatherNum(-1), name(""), type('N'), fBlock(-1) {}
IndexRec::IndexRec(long f, const char* n, char t, long long fbn) :
fatherNum(f), name{ '\0' }, type(t), fBlock(fbn) {
//strcpy_s(name, 23, n);
for (int i = 0; i < 22; i++) {
name[i] = n[i];
if (n[i] < 32) { name[i] = '\0'; break; }
}
name[22] = '\0';
}
//Index treeNode in RAM
IndexNode::IndexNode(
const char* ne,//name
char ty,//type
long long fb,//if type is file, fb is first fileBlockNum
long fa//node father
) :name{ '\0' }, type(ty), fBlock(fb), father(fa)
{ //copy ne to name
for (int i = 0; i < 22; i++) {
name[i] = ne[i];
if (ne[i] < 32) { name[i] = '\0'; break; }
}
//strcpy_s(name, 22, ne);
name[22] = '\0';
}
int addChild(vector<IndexNode>& index, IndexRec& rec) {
IndexNode temp(
rec.name,
rec.type,
rec.fBlock,
rec.fatherNum
);
index.push_back(temp);
if (rec.fatherNum >= 0) {
index.at(rec.fatherNum).children.push_back(index.size() - 1);
}
return 0;
}