-
Notifications
You must be signed in to change notification settings - Fork 7
immutable.Bag doesn't extend GenericTraversableTemplate[Bag[T]]
#5
Comments
I'm not sure if the semantic of flatten would be correct for any custom equivalence. I'll have to analyse it depth. Could you tell me which is your specific use case. |
I'm using a standard equality ( Your comment about semantics seems interesting, but since I currently uglily reimplemented
|
You are probably right, extending it will work correctly. |
I'm not sure I'm suggesting that. However, for standard equalities it'll work fine, and that's the usecase I'd like. For the rest, I'm not sure what correctly means. Also, when I hacked together quickly a bag implementation, I actually had a potentially faster version, which multiplies multiplicities instead of readding elements:
Could such an implementation be supported in your library? |
That may work for the compact representation but will fail on the others. But the implementation of flatten might be just a |
Thanks, I was indeed just supporting a compact representation. I've tried out your suggestion. However, as currently implemented, that appears to take quadratic time, because The complexity is thus equivalent to the one of the code below, which has more visibly quadratic cost: var acc = Array.empty
for (bag <- bags) {
val newAcc = Array.empty
newAcc += acc //cost: O( | acc | ), which keeps increasing
newAcc += bag //cost: O( | bag | )
acc = newAcc
} |
I forgot to write the implementation of def flattenB: Bag[T] =
b.fold[Bag[T]](Bag.empty)(_ union _) Apparently, that |
This means that the return type of e.g.
flatten
is justIterable[T]
. This should be hopefully easy to fix.I haven't checked the other Bag variants yet, though I conjecture they need updating as well.
The text was updated successfully, but these errors were encountered: