I am trying to build a relatively complex data structure (for me). My goal is to read words from text documents and index words and some specific properties into a hash table. The table is built from a vector of structure vectors: (vector <vector> vecName;). I was very lucky. Each unique word is hashed at the location of the index in the vector. The second size of the vector (structure vector) stores information about the file being read and where the word is in the file. For each file that I read, if I find a certain word several times, the score increases in the structure, and the vector of structures with integers stores information for all places where this word is stored in the file.
I have two elements that I would like to help with:
- I am curious if anyone has any suggestions for a better implementation of the data structure than my suggestion. Could a class containing some independent data, instead of a hippo, be more useful?
- It looks like I have a syntax error causing a compilation error, or I'm just trying to create a structure that the vector class does not support.
Here are the cmpilation errors. All three errors relate to the vector of structures within the structure:
'class std :: vector>' does not have a name with the name 'theLoc'
'class std :: vector>' does not have a name with the name 'theStart'
'class std :: vector>' does not have a name with the name 'theEnd'
, EboMike, , :
, , , . : * ' ' push_back '' testProps.wordProps:: theWordLoc: theLoc, non-type 'int' *
( ) , :
http://iamkevinfrye.com/blog/wp-content/uploads/2010/10/MicroSearch-Hash-Table-Data-Structure-Diagram.png
#include <vector>
#include <iterator>
#include <algorithm>
#include <iostream>
using namespace std;
struct wordLoc
{
int theLoc;
int theStart;
int theEnd;
};
struct wordProps // stores word info to be placed in array
{
string theFile;
int theCount;
vector <wordLoc> theWordLoc;
};
int main()
{
int Tsize = 20000;
wordProps testProps;
testProps.theFile = "test1";
testProps.theCount = 1;
testProps.theWordLoc.theLoc.push_back(200);
testProps.theWordLoc.theStart.push_back(1);
testProps.theWordLoc.theEnd.push_back(15);
vector < vector <wordProps> > theWordProps;
theWordProps.resize(Tsize);
theWordProps[0].push_back(testProps);
cout << "index[0] = " << theWordProps[0].front().theFile << endl;
cout << "index[0] = " << theWordProps[0].front().theCount << endl;
cout << "index[0] = " << theWordProps[0].front().theWordLoc[0].theLoc << endl;
cout << "index[0] = " << theWordProps[0].front().theWordLoc[0].theStart << endl;
cout << "index[0] = " << theWordProps[0].front().theWordLoc[0].theEnd << endl;
cout << "size of theWordProps[0] = " << theWordProps[0].size();
cout << endl;
}