I tried to adapt the code to accept variable step but I seem to have trouble at window edges. Works fine until last value 512 (which is always 511+1G instead of 511+step*g) in first set, then skipped completely next (1024 entry is given 1025 value) then plus 1 then skipped etc. Do you know why this is happening?
All the verifications and setup assumes a step size of G, so in order to change the step, it needs to be factored in everywhere where the step is assumed to be equal to 1:
- first constant point: step * (2 * num_const - 1)
- constant points from 1 to N - 1 start from step*G, increase by step*G
- validations for user input need to be updated as well (invalid ranges, etc.) - sounds like this is your error
- maximum range size can no longer be 64-bits (reduces by size)
For 512 constant points with a "size" of 1, the range cannot start at key 512, because a pivot starts at key 1023 (= 512 + (NUM_CONST - 1), and it will fail to compute 1023G + (2*NUM - 1)G.
If the step size is 2, then by the same logic C[0] = 2*1023 = 2046. And the pivot starts at (start + step*(NUM_CONST - 1)). Solving for this equation (pivot == C[0]) means that now we have to ban the range from starting at 2046 - 2*511 = base key 1024. Or more simply, NUM_CONST * size.