Uploaded image for project: 'Clojure'
  1. CLJ-1362

Reduce broken on some primitive vectors

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: Release 1.6, Release 1.5, Release 1.4, Release 1.3
    • Fix versions: Release 1.7
    • Labels:
    • Approval:
      Ok
    • Patch:
      Code and Test

      Description

      In some cases, reduce over a sequence from a primitive vector created with vector-of will return incorrect answers:

      user=> (into [] (drop 32 (into [] (range 33))))
      [32]
      user=> (into [] (drop 32 (into (vector-of :int) (range 33))))
      [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32]
      

      Second call should return [32] 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.

      Patch: clj-1362-v1.patch

      Screened by:

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: