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

Mutable Queue only has expensive batch enqueue (elems: A*) #9175

Closed
scabug opened this issue Feb 23, 2015 · 8 comments
Closed

Mutable Queue only has expensive batch enqueue (elems: A*) #9175

scabug opened this issue Feb 23, 2015 · 8 comments

Comments

@scabug
Copy link

scabug commented Feb 23, 2015

Seems mutable.Queue only has batch enqueuing:

http://www.scala-lang.org/api/current/index.html#scala.collection.mutable.Queue@enqueue%28elems:A*%29:Unit

which tends to be slower than a combination of two enqueues, one for a single element and one for batches:

http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Queue@enqueue%5BB%3E:A%5D%28iter:scala.collection.immutable.Iterable%5BB%5D%29:scala.collection.immutable.Queue%5BB%5D

http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Queue@enqueue%5BB%3E:A%5D%28elem:B%29:scala.collection.immutable.Queue%5BB%5D

How do you feel about adding an enqueue to the mutable Queue?

@scabug
Copy link
Author

scabug commented Feb 23, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9175?orig=1
Reporter: @VladUreche
Affected Versions: 2.11.5

@scabug
Copy link
Author

scabug commented Feb 23, 2015

@VladUreche said:
Rex, how do you feel about adding a single element enqueue to mutable.Queue? I can do a PR against 2.12 if that's okay with you.

@scabug
Copy link
Author

scabug commented Feb 23, 2015

@Ichoran said:
I think it's really a shame that mutable.Queue doesn't have this, so if you can do it in a source-compatible way, that sounds good to me! However, something like .enqueue(xs: _*) would still need to work to maintain source compatibility. Adriaan is the one to ask if we want a performance vs. backwards compatibility tradeoff. (I think an implicit will do the trick, but it's a bit ugly to have in the API...maybe better to just wait until 2.13 and fix it properly.)

@scabug
Copy link
Author

scabug commented Jun 12, 2015

@ruippeixotog said:
@Ichoran, what about adding signatures like:

def enqueue[B >: A](elem: B): Unit
@deprecated(...) def enqueue[B >: A](elem: B, elem2: B, elems: B*): Unit
def enqueue[B >: A](iter: Iterable[B]): Unit

Unless I'm not missing some corner case, that would keep source compatibility and pave the path to an unified API for enqueuing in 2.13 - a single-element enqueue and an iterator enqueue.

@scabug
Copy link
Author

scabug commented Jun 13, 2015

@Ichoran said:
@ruippeixotog Well, there's the empty case, enqueue(), though I can't imagine why that would have been used. And if anyone extended mutable.Queue this definitely requires a good bit of work to retain compatibility. But it's not a bad idea. Maybe worth moving it up to 2.12 and seeing who complains? Maybe after we survey projects out there and see how often if ever we see mutable.Queue extended.

@scabug
Copy link
Author

scabug commented Jun 13, 2015

@ruippeixotog said:
On a second look, my suggestion breaks also code that calls enqueue as enqueue(elemSeq: _*). Maybe there is no way to do that without breaking source compatibility... how about defining += for single-element enqueues?

@SethTisue
Copy link
Member

@scala/collections what's the status on this one — should this stay open?

@NthPortal
Copy link

fixed in 2.13

@SethTisue SethTisue modified the milestones: Backlog, 2.13.0 Oct 26, 2023
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

4 participants