Originally Posted by
R.Stiltskin
Here's what your addWord does:
Suppose word (the one passed as argument 1 of addWord) is "Markov". And suppose you already have 100 indexWords in the vector data, but none of them has value=="Markov".
addWord looks at the first of the 100 elements of data, finds that its value member is not "Markov", so it assigns index.value="Markov", assigns index.locations[0]=pageNumber (this is a "new" indexWord so its locations vector starts out empty), and pushes this index onto the back of the vector data.
Then it looks at the next element of data and does the same thing again, and so on ...
...so it ultimately pushes 100 copies of "Markov" onto the vector, then continues, looking at each of those new copies but since for each of them the value is "Markov", it doesn't add any more copies.
On the other hand, if an indexWord with value=="Markov" is already in data, addWord simply skips over that element and goes on to the next, and never adds a second element to the locations vector of any indexWord.