-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinodedata.cpp
63 lines (57 loc) · 1.53 KB
/
inodedata.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
#include <algorithm>
#include "inodedata.h"
/*******************************
* CONSTRUCTOR *
*******************************/
INodeData::INodeData()
{
sorted_ = false;
}
INodeData::INodeData(const string &w)
{
word_ = w;
sorted_ = false;
}
/*******************************
* GET THE KEYWORD *
*******************************/
string INodeData::word()
{
return word_;
}
/********************************************
* LIST OF DOCUMENTS CONTAINING THE KEYWORD *
********************************************/
vector<Document> INodeData::docs()
{
return docs_;
}
/*****************************************
* ADD DOCUMENT TO THE LIST *
*****************************************/
void INodeData::docs(Document doc)
{
//Check for existance of the document in the list
for (vector<Document>::reverse_iterator rit = docs_.rbegin(), ritend = docs_.rend(); rit != ritend; rit++)
{
//If yes,
if (rit->name_ == doc.name_)
{
//Increase the word occurrence counter for the document
rit->occurrence_ += doc.occurrence_;
return;
}
}
//If the list doesn't have the document, add it to the list
docs_.insert(docs_.end(), doc);
sorted_ = false;
}
/*******************************************
* SORT THE LIST OF DOCUMENTS *
*******************************************/
void INodeData::sortDocs()
{
if (!sorted_)
sort(docs_.begin(), docs_.end(), Document::docNameComp);
sorted_ = true;
}