Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HashMap should implement filter #6200

Closed
scabug opened this issue Aug 6, 2012 · 7 comments
Closed

HashMap should implement filter #6200

scabug opened this issue Aug 6, 2012 · 7 comments

Comments

@scabug
Copy link

scabug commented Aug 6, 2012

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. 
@scabug
Copy link
Author

scabug commented Aug 6, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6200?orig=1
Reporter: @rklaehn
Affected Versions: 2.10.0-M6
See #6196
Attachments:

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Dec 3, 2013

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

@scabug
Copy link
Author

scabug commented Dec 3, 2013

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

@scabug
Copy link
Author

scabug commented Dec 3, 2013

@Ichoran said:
Aha. There's some incorrect size reporting going on somewhere along the way.

@scabug
Copy link
Author

scabug commented Dec 3, 2013

@Ichoran said:
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).

@scabug
Copy link
Author

scabug commented Jan 15, 2014

@Ichoran said:
scala/scala#3318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants