You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
valm=HashMap(1->1,2->2,3->3,4->4)
/* this builds a completely new set, which is very inefficient */valn= m.filter(_ =>true)
println(m eq n) // false, should be truevalu= m.filterNot(_ =>false)
println(m eq u) // true, because filterNot in MapLike removes non-matching elements.
The text was updated successfully, but these errors were encountered:
@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).
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.
The text was updated successfully, but these errors were encountered: