-
Notifications
You must be signed in to change notification settings - Fork 69
Add GenBool instance for Map[K, V: GenBool]. #126
Conversation
def zero: Map[K, V] = Map.empty | ||
|
||
def and(a: Map[K, V], b: Map[K, V]): Map[K, V] = ( | ||
(a.keySet intersect b.keySet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for performance you might want:
(a.keySet intersect b.keySet).iterator
.map { k => (k, GBV.and(a(k), b(k))) }
.filter { case (_, v) => EqV.neqv(GBV.zero, v) }
.toMap
putting the iterator early prevents materialization after .map and .filter. Also, note, .map is returning a set here and so if filter, so that is going to be bit slower than the iterator.
I realize we didn't add Also, there are many similar constructions related to |
I will rewrite the expressions to invoke |
Yeah, I realized there could be interesting structures for |
I don't know how immutable m log n < n + m it is more efficient to update the big map. |
Immutable map is a HashTrie, so it is ~ |
@TomasMikula you might want to take a look at: https://github.com/non/algebra/blob/a32f76aba93245b95972b4b4bb80f29b0621c9ba/std/src/main/scala/algebra/std/Util.scala#L154 the addMap/subtractMap methods may be able to be used in these cases. |
Yeah, |
- Optimize chains of map/filter by invoking iterator early. - Use tuple pattern matching on function argument.
i think we need the |
I'm afraid you're right.
Indeed, it would make sense to add |
That sounds like a great plan to me! |
No description provided.