Details

      Description

      HashMap does not implement filter directly but defers to the generic builder-based implementation of TraversableLike. That leads to filter always creating a completely new HashMap instead of reusing the old set where possible.

      I am working on an application where it is very important to have fast map operations such as filter, and I would prefer not to have to roll my own collections.

        val m = HashMap(1->1,2->2,3->3,4->4)
        /* this builds a completely new set, which is very inefficient */
        val n = m.filter(_ => true)
        println(m eq n) // false, should be true
        
        val u = m.filterNot(_ => false)
        println(m eq u) // true, because filterNot in MapLike removes non-matching elements. 
      

        Issue Links

          Activity

          Hide
          Adriaan Moors added a comment -

          Unassigning and rescheduling to M6 as previous deadline was missed.

          Show
          Adriaan Moors added a comment - Unassigning and rescheduling to M6 as previous deadline was missed.
          Hide
          Rex Kerr added a comment -

          Patch is broken. Doesn't deliver the requested feature. In fact, it makes it worse.

          Show
          Rex Kerr added a comment - Patch is broken. Doesn't deliver the requested feature. In fact, it makes it worse.
          Hide
          Rex Kerr added a comment -

          Hm, more complicated than that. There's some interaction between + and filter that I don't fully understand yet.

          Show
          Rex Kerr added a comment - Hm, more complicated than that. There's some interaction between + and filter that I don't fully understand yet.
          Hide
          Rex Kerr added a comment -

          Aha. There's some incorrect size reporting going on somewhere along the way.

          Show
          Rex Kerr added a comment - Aha. There's some incorrect size reporting going on somewhere along the way.
          Hide
          Rex Kerr added a comment -

          This general approach works, but there's a big performance penalty for filters that would end up mostly empty (up to about 3x for filtering to nothing).

          Show
          Rex Kerr added a comment - This general approach works, but there's a big performance penalty for filters that would end up mostly empty (up to about 3x for filtering to nothing).
          Show
          Rex Kerr added a comment - https://github.com/scala/scala/pull/3318

            People

            • Assignee:
              Rex Kerr
              Reporter:
              Rüdiger Klaehn
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development