[CLJ-1362] Reduce broken on some primitive vectors Created: 18/Feb/14 Updated: 25/Apr/14
|Affects Version/s:||Release 1.3, Release 1.4, Release 1.5, Release 1.6|
|Fix Version/s:||Release 1.7|
|Patch:||Code and Test|
In some cases, reduce over a sequence from a primitive vector created with vector-of will return incorrect answers:
Second call should return  just like the first one.
Cause: VecSeq (seq on primitive Vec obtained with vector-of) maintains two flags: i is the total number of elements prior to the current node in this seq. offset is the offset in the current anode. When using internal-reduce on a VecSeq, the starting index for the reduce was using offset and ignoring i.
Solution: Use (+ i offset) as the starting index.
|Comment by Alex Miller [ 18/Feb/14 10:18 PM ]|
We did some debugging on this at the St. Louis Clojure Meetup tonight and suspect the problem is happening when drop walks through the chunked seq over the vector. Specifically, in the VecSeq's implementation of IChunkedSeq.chunkedNext() at https://github.com/clojure/clojure/blob/master/src/clj/clojure/gvec.clj#L116 particularly the offset 0 at the end.
|Comment by Alex Miller [ 19/Feb/14 2:41 PM ]|
Upon further review, the VecSeq seems to be created properly during chunking. The real issue is in internal-reduce where the starting index is improperly computed.
|Comment by Stuart Sierra [ 25/Apr/14 1:05 PM ]|