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.PriorityQueue: newBuilder type and efficiency improvement #9776

Closed
scabug opened this issue May 15, 2016 · 3 comments
Closed

mutable.PriorityQueue: newBuilder type and efficiency improvement #9776

scabug opened this issue May 15, 2016 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 15, 2016

First, the newBuilder function in object PriorityQueue is defined as

   def newBuilder[A](implicit ord: Ordering[A]) = new PriorityQueue[A]

The lack of a return type means that the type in the API comes out as

   def newBuilder[A](implicit ord: Ordering[A]): PriorityQueue[A]

rather than the expected

   def newBuilder[A](implicit ord: Ordering[A]): Builder[A, PriorityQueue[A]]

The fix is to explicitly add the appropriate return type to the method declaration.

Second, the current algorithm for creating a priority queue from initial elements inserts the elements one at a time. This takes O(N log N) time. Substituting the well-known "heapify" algorithm would improve this to O(N) time. Similar improvements can be made to enqueue, ++=, and reverse.

I am currently working on implementing these changes.

@scabug
Copy link
Author

scabug commented May 15, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9776?orig=1
Reporter: @chrisokasaki
Affected Versions: 2.12.0-M1, 2.12.0-M2, 2.12.0-M3

@scabug
Copy link
Author

scabug commented May 17, 2016

@szeiger said:
The sequential, single-append nature of Builders is also a limitation in https://github.com/scala/scala-java8-compat. It would be great if we could create a more powerful abstraction for Scala 2.13 collections.

@scabug
Copy link
Author

scabug commented May 23, 2016

@adriaanm said:
scala/scala#5181

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

2 participants