scala-rrb-vector
scala-rrb-vector copied to clipboard
issues with reverse iterator
I admit the code for RRBVectorReverseIterator makes no sense to me, but I'm pretty sure it is incorrect. Consider the initialization:
val idx = endIndex - 1
focusOn(idx)
lastIndexOfBlock = idx
lo = (idx - focusStart) & 31
endLo = java.lang.Math.max(startIndex - focusStart - lastIndexOfBlock, 0)
If the requested range is 5 through 30, then idx will be initialized to 29 (that makes sense as the index of the next value to return). lastIndexOfBlock will be initialized to 29, which is suspicious given that it is decremented by 32 later on; it probably should be 31. lo will be initialized to 29, which makes sense as the offset in the current leaf node of the next value to return. but endLo will be initialized to 0, which is clearly wrong. It should be the offset of the last element in the current leaf node to be returned, in this case 5.
I doubt that is the only problem.