Hello, i have a question to the people who already have read chapter 7-4 in this book.

This example is driving me crazy! :x

typedef vector<string> Rule;
typedef vector<Rule> Rule_collection;
typedef map<string, Rule_collection> Grammar;

So, this would without typedef be like this:

map<string, vector< <vector<string> > > >;

But, why do i need that extra vector?

One moment i think i understand it, but then the next when i think further it stops making any sense!

Andreas

Its a two-dimensional array of strings. Simething like string Rule_Collection[100][2]; except that using vectors is much more efficient because the dimensions are not hard coded.

I've often used the same or similar technique for reading rows and columns (result set) from a database. Where the inner-most vector represents the columns and the outer vector the rows.

>>to the people who already have read chapter 7-4 in this book
Nope, I have not read it.

Edited 6 Years Ago by Ancient Dragon: n/a

I looked at the book and it looks like since there are multiple keys that are the same the author decided to have each rule be in a vector. That way you have one key "adjective" and then a vector that has 3 different rules in it. This way one key can have multiple sets of rules associated with it.

>>Citation please?

By "efficient" I meant memory wise. And for access speed they can be just as efficient as C style arrays. And where do you find the dimensions hard-coded in a vector?

example

int main()
{
    vector< vector<string> > theList;
    vector<string> row;
    row.push_back("one");
    row.push_back("two");
    theList.push_back(row);
    row.erase(row.begin(),row.end());
    row.push_back("three");
    row.push_back("four");
    theList.push_back(row);

    string s = theList[1][1];
    cout << s << '\n';


}

Edited 6 Years Ago by Ancient Dragon: n/a

>>By "efficient" I meant memory wise. And for access speed they can be just as efficient as C style arrays. And where do you find the dimensions hard-coded in a vector

I sure std::vector(5,0) takes up more memory than int array[5]; Just look :

#include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> v(5,0);
	int a[5] = {0};
	//for me, its 24 and 20, respectively;
	cout << sizeof(v) << " " << sizeof(a) << endl;
	return 0;
}

But I heard from someone very knowledgeable and trustworthy, that when full
optimization is on, std::vector is almost exactly like an raw array.

I'm not questioning that one should use std::vector instead of raw arrays, i'm just
curious where you get the information from. Thanks

But vector<int> a is a lot smaller than int a[100]; and more efficient if the program only needs something < or > 100.

>>i'm just curious where you get the information from.

I try to use my head for something other than a hat rack. The reason stated above is pretty obvious.

Edited 6 Years Ago by Ancient Dragon: n/a

But vector<int> a is a lot smaller than int a[100]; and more efficient if the program only needs something < or > 100.

>>i'm just curious where you get the information from.

I try to use my head for something other than a hat rack. The reason stated above is pretty obvious.

Well yea, thats very obvious. Thanks

I have this feeling that not having english as my main language makes me miss important points when reading these books.

I look up the new words ofcourse, but still.

Annoying! >:(


The world’s tallest skyscraper took 7 years to build. Each year the workmen were able to double its height. How many years did it take for the skyscraper to reach half of its maximum height?

6 years! :P

Edited 6 Years Ago by Andreas5: n/a

>>6 years! :P

Lol nice. Its really easy, but also a good question as well. Next time message me the answer, so others can try it to.

I have this feeling that not having english as my main language makes me miss important points when reading these books.

I look up the new words ofcourse, but still.

Annoying! >:(

English IS my first language and I still look up some words too :) For example, do you know the longest word in the English language? (hint: it has 189,819 letters)

This article has been dead for over six months. Start a new discussion instead.