Deque<int> Questions

I have some code using some deque functions, but I can't interpret what it means:

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
typedef deque<mpz_class> dqz;
	typedef unordered_set<string> HS;
	HS S;
	FILE* f;	

	/* now construct the coefficients of a massive polynomial
	 * based on the words of the file we just read. */
	dqz coeff[2]; // we'll alternate which is input / output...							
	coeff[currentIn].push_back(1);
	mpz_class hashv; // store hash as an integer.
	HS::iterator it;
	for (it=S.begin(); it!= S.end(); it++) {
		SHA1((const unsigned char*)it->c_str(), it->length(), output);
		/* now convert to mpz_t, and multiply into the accumulator. */
		mpz_from_bytes(hashv, output, 20);
		coeff[1-currentIn].resize( coeff[currentIn].size()+1, 0 );		//coeff[currentIn].size() ?					//coeff[1-currentIn]?
		for (size_t i = 0; i < coeff[currentIn].size(); i++) {
			MULMOD(coeff[1-currentIn][i],coeff[currentIn][i],hashv,algPRF::p);
		}
		// shift the coeff's and add to the output register:
		coeff[currentIn].push_front(0);
		for (size_t i = 0; i < coeff[currentIn].size(); i++) {
			coeff[1-currentIn][i] += coeff[currentIn][i];
			MOD(coeff[1-currentIn][i],coeff[1-currentIn][i],algPRF::p);
		}
		currentIn = 1 - currentIn; // swap input and output.
	}


Just focus on parts:
1
2
3
4
dqz coeff[2]; // we'll alternate which is input / output...	
	int currentIn=0;
	coeff[currentIn].push_back(1);
coeff[1-currentIn].resize( coeff[currentIn].size()+1, 0 );


What do they mean?
deque named coeff of size 2?
Then, coeff[currentIn].push_back(1); ?? Is this a multidimensional deque?

Thank you.
dqz coeff[2];

This is an array of two dqz (two deques)
Last edited on
Could it be represented graphically as follows?

front of deques
[ ] [ ]------------------array
[ ] [ ]
[ ] [ ]
[ ] [ ]
back of deques
No, think of it as a ragged array. The deques are not constrained to have the same sizes just because they are part of the same array.

In other words, think of them as two separate deques and you just use a variable to decide which one to access.
Last edited on
You are right. So, a better example could be:

front of deques
[ ] [ ]------------------array
[ ] [ ]
[ ]
[ ]
back of deques

Where the deques are of arbitrary size?
Yes. personally graphical representations don't help me - if they help you, that fine.

What's the next thing you're confused about?
Your clarification answered all of them.

Thank you.
Topic archived. No new replies allowed.