Numerically Controlled Oscillator (NCO) Sample quantity
This technique is generally called Direct Digital Synthesis (DDS). 


  How can the frequency be varied without effecting the number of samples present in the wave?


It doesn't; The sample rate is fixed. I.e. the synthesizer/oscillator outputs some number of samples per second, this does not vary, the sample value varies. 

Lets say you used a sample rate of 8khz, if you looked at the one second of output you will have 8000 samples. The highest frequency that could be output at this rate is 4khz which is the Nyquist_frequency. For this 4khz the sample value would alternate 0,255,0,255... your table index would 0,128,0,128 or (127,255... or whatever). The index would increase by 128 each sample. A 2khz signal would see an index increasing by 64 each sample. Both signals would have 8000 samples for the whole second, the 2khz signal would have half as many cycles as the 4khz signal in the same time, because it is half the frequency!

Now if you meant cycle instead of wave, then the answer would be that you can't have the same number of samples/cycle for another frequency with the same sample rate. If you need more fidelity (i.e. more samples) you will have to increase the sample rate.