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
but elms.updatedWith could easily return the same MultiDict if the value is already in the Set[V].
It would help if the signature made sure that the same object would be returned if nothing changed as that would allow one
to reduce unnecessary object creation (both in the call, and also in the creation of objects in the calling object.
Otherwise one ends up creating a lot of garbage.
Something like this seems better:
defadd(key: K, value: V):MultiDict[K, V] =valnewElems= elems.updatedWith(key) {
caseNone=>Some(Set(value))
caseSome(vs) =>Some(vs + value) // if vs + value == vs then this will return the original MD I believe
}
if newElems eq this.elems thenthiselsenewMultiDict(newElems)
That is how incl in the standard scala library for HashSet works.
The text was updated successfully, but these errors were encountered:
I have a mini implementation of MultiDict for my needs in org/w3/banana/quiver/util/MultiDict.scala with tests that pass and two implementations of Graph that use it whose tests also pass.
Uh oh!
There was an error while loading. Please reload this page.
The add method is defined as follows
but
elms.updatedWith
could easily return the same MultiDict if the value is already in the Set[V].It would help if the signature made sure that the same object would be returned if nothing changed as that would allow one
to reduce unnecessary object creation (both in the call, and also in the creation of objects in the calling object.
Otherwise one ends up creating a lot of garbage.
Something like this seems better:
That is how
incl
in the standard scala library for HashSet works.The text was updated successfully, but these errors were encountered: