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

clojure.data/diff uses set union on key seqs

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Patch:
      Code

      Description

      clojure.data/diff, on line 118, defines:

      java.util.Map
      (diff-similar [a b]
        (diff-associative a b (set/union (keys a) (keys b))))
      

      Since keys returns a key seq, this seems like an error. clojure.set/union has strange and inconsistent behavior with regard to non-sets, and in this case the two key seqs are concatenated. Based on a cursory benchmark, it seems that this bug is a slight performance gain when the maps have no common keys, and a significant performance loss when the maps have the same keys. The results are still correct because of the merging reduce in diff-associative.

      The patch is easy (just call set on each key seq).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              tomoj Tom Jack
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: