Can I build a vector of structure vectors with structure vectors? (Yes indeed)

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;                     // the location of the word in theFile
    int theStart;                   // the beginning of the sentence
    int theEnd;                     // the end of the sentence
};

struct wordProps                    // stores word info to be placed in array
{
    string  theFile;                // stores the file where theWord is found
    int theCount;                   // increments with each occurence of theWord
    vector <wordLoc> theWordLoc;    // stores the wordLoc info for each occurence of theWord
};

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;
}
+3
4

, , hasmap, !

:

int main()
{    
    int Tsize = 20000;

    wordProps testProps;
    testProps.theFile = "test1";
    testProps.theCount = 1;

    // create your wordLoc object
    wordLoc wl;
    wl.theLoc = 200;
    wl.theStart = 1;
    wl.theEnd = 15;

    // put it into the vector
    testProps.theWordLoc.push_back(wl);

    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;
}
+1

: , , :

testProps.theWordLoc.theLoc.push_back(200);
testProps.theWordLoc.theStart.push_back(1);
testProps.theWordLoc.theEnd.push_back(15);

theWordLoc - , , :

testProps.theWordLoc[0].theLoc = 200;

, :

wordLoc wordLocData;
worldLocData.theLoc = 200;
worldLocData.theStart = 1;
worldLocData.theEnd = 15;
testProps.theWorldLoc.push_back(worldLocData);

: ? . , ? ? ", ", . worldLoc, wordProps, , .

, . , ( ), , -.

+3

testProps.theWordLoc.theLoc theLoc theWordLoc. . - testProps.theWordLoc[0].theLoc.

+1

Source: https://habr.com/ru/post/1778459/


All Articles