Skip to content

Commit d32d382

Browse files
committed
delete Chunk + File
1 parent 8ed7752 commit d32d382

8 files changed

+94
-35
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@
3333
*.exe
3434
*.out
3535
*.app
36+
37+
AIFBS-CS-VS/*
38+
AIFBS-CS-VS

AIFBS_BTree.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ namespace AIFBS {
3737

3838
// The main function that removes a new key in thie B-Tree
3939
void remove(T k);
40+
41+
bool isEmpty() {
42+
return root == NULL;
43+
}
44+
void deleteAll() {
45+
for (int i = 0; i < root->n; i++) {
46+
root->remove(root->keys[i]);
47+
}
48+
}
4049
};
4150
}
4251
#endif

AIFBS_BTreeNode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ namespace AIFBS {
247247
void AIFBS_BTreeNode<T>::removeFromNonLeaf(int idx)
248248
{
249249

250-
int k = keys[idx];
250+
T k = keys[idx];
251251

252252
// If the child that precedes k (C[idx]) has atleast t keys,
253253
// find the predecessor 'pred' of k in the subtree rooted at
254254
// C[idx]. Replace k by pred. Recursively delete pred
255255
// in C[idx]
256256
if (C[idx]->n >= t)
257257
{
258-
int pred = getPred(idx);
258+
T pred = getPred(idx);
259259
keys[idx] = pred;
260260
C[idx]->remove(pred);
261261
}
@@ -267,7 +267,7 @@ namespace AIFBS {
267267
// Recursively delete succ in C[idx+1]
268268
else if (C[idx+1]->n >= t)
269269
{
270-
int succ = getSucc(idx);
270+
T succ = getSucc(idx);
271271
keys[idx] = succ;
272272
C[idx+1]->remove(succ);
273273
}
@@ -286,7 +286,7 @@ namespace AIFBS {
286286

287287
// A function to get predecessor of keys[idx]
288288
template <class T>
289-
int AIFBS_BTreeNode<T>::getPred(int idx)
289+
T AIFBS_BTreeNode<T>::getPred(int idx)
290290
{
291291
// Keep moving to the right most node until we reach a leaf
292292
AIFBS_BTreeNode<T> *cur=C[idx];
@@ -298,7 +298,7 @@ namespace AIFBS {
298298
}
299299

300300
template <class T>
301-
int AIFBS_BTreeNode<T>::getSucc(int idx)
301+
T AIFBS_BTreeNode<T>::getSucc(int idx)
302302
{
303303

304304
// Keep moving the left most node starting from C[idx+1] until we reach a leaf

AIFBS_BTreeNode.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ namespace AIFBS {
4646

4747
// A function to get the predecessor of the key- where the key
4848
// is present in the idx-th position in the node
49-
int getPred(int idx);
49+
T getPred(int idx);
5050

5151
// A function to get the successor of the key- where the key
5252
// is present in the idx-th position in the node
53-
int getSucc(int idx);
53+
T getSucc(int idx);
5454

5555
// A function to fill up the child node present in the idx-th
5656
// position in the C[] array if that child has less than t-1 keys

AIFBS_CS.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,46 @@ namespace AIFBS
6161

6262
return SN;
6363
}
64+
65+
bool AIFBS_CS::remove(std::string chunkDetails) {
66+
SplittedNames sn = this->split(chunkDetails);
67+
68+
AIFBS_FileNodeKey tempFileKey;
69+
tempFileKey.setKey(sn.m_fileName);
70+
AIFBS_FileNodeKey *fileNodeKey = fileTree->searchKeyRef(tempFileKey);
71+
72+
if (fileNodeKey == NULL) {
73+
return false;
74+
}
75+
else {
76+
AIFBS_ChunkNodeKey tempChunkKey;
77+
tempChunkKey.setKey(sn.m_chunkName);
78+
AIFBS_ChunkNodeKey* requiredChunk = fileNodeKey->m_chunkTree->searchKeyRef(tempChunkKey);
79+
80+
if (requiredChunk == NULL) {
81+
return false;
82+
}
83+
else {
84+
fileNodeKey->m_chunkTree->remove(*requiredChunk);
85+
if (fileNodeKey->m_chunkTree->isEmpty()) {
86+
fileTree->remove(*fileNodeKey);
87+
}
88+
}
89+
}
90+
}
91+
92+
bool AIFBS_CS::removeFile(std::string fileName) {
93+
AIFBS_FileNodeKey tempFileKey;
94+
tempFileKey.setKey(fileName);
95+
AIFBS_FileNodeKey *fileNodeKey = fileTree->searchKeyRef(tempFileKey);
96+
97+
if (fileNodeKey == NULL) {
98+
return false;
99+
}
100+
else {
101+
fileNodeKey->m_chunkTree->deleteAll();
102+
}
103+
fileTree->remove(*fileNodeKey);
104+
}
64105
}
65106
#endif

AIFBS_CS.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ namespace AIFBS
5656

5757
}
5858

59-
bool removeChunk() {
60-
61-
}
59+
bool remove(std::string chunkDetails);
60+
61+
bool removeFile(std::string fileName);
6262
};
6363
}

AIFBS_FileNodeKey.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace AIFBS {
2121
m_chunkTree = t_chunkTree;
2222
};
2323
~AIFBS_FileNodeKey() {
24-
// m_key = NULL;
24+
//delete(m_chunkTree);
2525
};
2626

2727
//Must to overload

AIFBS_Test.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ int main() {
1414
// t.insert("chunk6");
1515
// t.insert("chunk7");
1616
// t.insert("chunk8");
17-
1817
// cout << "Traversal of the constucted tree is ";
1918
// t.traverse();
20-
2119
// string k = "chunk2";
2220
// (t.search(k) != NULL)? cout << "\nPresent\n" : cout << "\nNot Present\n";
23-
2421
// k = "15";
2522
// (t.search(k) != NULL)? cout << "\nPresent\n" : cout << "\nNot Present\n";
2623
//endregion
@@ -40,37 +37,33 @@ int main() {
4037
// t2.insert(c3);
4138
// t2.insert(c4);
4239
// t.insert(c5);
43-
4440
// // t.traverse();
45-
4641
// AIFBS_BTree<AIFBS_FileNodeKey> filetree(3);
4742
// AIFBS_FileNodeKey filetreeNode1("file1", &t);
4843
// AIFBS_FileNodeKey filetreeNode2("file2", &t2);
4944
// filetree.insert(filetreeNode1);
5045
// filetree.insert(filetreeNode2);
51-
5246
// filetree.traverse();
5347
//endregion
5448

5549
//region Inserting files with chunk names
5650
//Building a Scenario
57-
// AIFBS_CS cs(3);
58-
//
59-
// cs.insert("cd/cfd/file1/chunk1", 1);
60-
// cs.insert("cd/cfd/file1/chunk3", 1);
61-
// cs.insert("cd/cfd/file1/chunk2", 1);
62-
// cs.insert("cd/cfd/file1/chunk4", 1);
63-
//
64-
// cs.insert("cd/cfd/file2/chunk3", 1);
65-
// cs.insert("cd/cfd/file2/chunk1", 1);
66-
// cs.insert("cd/cfd/file2/chunk2", 1);
67-
//
68-
// cs.insert("cd/cfd/file3/chunk4", 1);
69-
// cs.insert("cd/cfd/file3/chunk1", 1);
70-
// cs.insert("cd/cfd/file3/chunk9", 1);
71-
//
72-
// cs.traverse();
73-
51+
//AIFBS_CS cs(3);
52+
//cs.insert("cd/cfd/file1/chunk1", 1);
53+
//cs.insert("cd/cfd/file1/chunk3", 1);
54+
//cs.insert("cd/cfd/file1/chunk2", 1);
55+
//cs.insert("cd/cfd/file1/chunk4", 1);
56+
//
57+
//cs.insert("cd/cfd/file2/chunk3", 1);
58+
//cs.insert("cd/cfd/file2/chunk1", 1);
59+
//cs.insert("cd/cfd/file2/chunk2", 1);
60+
//
61+
//cs.insert("cd/cfd/file3/chunk4", 1);
62+
//cs.insert("cd/cfd/file3/chunk1", 1);
63+
//cs.insert("cd/cfd/file3/chunk9", 1);
64+
//
65+
//cs.traverse();
66+
//
7467
//endregion
7568

7669
//region Inserting files and searching chunks
@@ -97,6 +90,18 @@ int main() {
9790
cout<<"\n\nChunk found: "<<requiredChunk->getKey()<<endl;
9891
else
9992
cout<<"\n\nChunk not found."<<endl;
93+
94+
cs.removeFile("cd/cfd/file2");
95+
/*cs.remove("cd/cfd/file3/chunk4");
96+
cs.remove("cd/cfd/file3/chunk1");
97+
cs.remove("cd/cfd/file3/chunk9");
98+
cout << "\n After removing chunk4 in file 3: \n";*/
99+
//cs.insert("cd/cfd/file3/chunk9", 4);
100+
101+
102+
103+
cs.traverse();
104+
100105
//endregion
101106

102107
//region Splitting names test
@@ -105,7 +110,8 @@ int main() {
105110

106111
//endregion
107112

108-
113+
cout << "\n\n";
114+
std::system("pause");
109115
return 0;
110116
}
111117

0 commit comments

Comments
 (0)