-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvIndex.cpp
58 lines (34 loc) · 1.44 KB
/
InvIndex.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
#include "InvIndex.h"
InvIndex::InvIndex(const size_t arraySize): maxWordId(0) {
wordVec.resize(arraySize); // should we restore arraySize
}
InvIndex::~InvIndex() {
for (vector<WordInfo *>::wordVecIt = wordVec.begin(); wordVecIt != wordVec.end(); ++wordVecIt) {
delete *wordVecIt;
}
}
InvIndex::insertDoc(int docId, const vector <int> &wordIds) {
for (vector <int>::wordIt = wordIds.begin(); wordIt != wordIds.end(); ++wordIt) {
boost::lock_guard<boost::mutex> wordLock (wordVec[*wordIt].mutex);
if (wordVec[*wordIt] == 0) // if null pointer
wordVec[*wordIt] = new WordInfo;
wordVec[*wordIt] -> overflow.push_back(docId);
}
}
InvIndex:: insertDoc(int docId, const vector <string> &words) {
boost::lock_guard<boost::mutex> wordLock (wordVec[*wordIt].mutex);
vector <int> wordIds (words.size());
for (vector <string>::iterator wordIt = words.begin(); wordIt != words.end(); ++wordIt) {
WordMap::iterator mapIt = wordMap.find(*wordIt);
int wordId;
if (mapIt == wordMap.end()) { // word not in map
wordId = maxWordId;
maxWordId++;
mapIt[*wordIt] = wordId;
}
else { // word found
}
}
int wordId = *wordIt; // will this save a few pointer dereferences
boost::lock_guard<boost::mutex> wordLock(utexes[wordMutexes[wordId];
}