RFR: 6356745: (coll) Add PriorityQueue(Collection, Comparator) [v2]
Valeh Hajiyev
duke at openjdk.org
Tue Dec 19 21:17:17 UTC 2023
On Sun, 17 Dec 2023 15:20:50 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Valeh Hajiyev has updated the pull request incrementally with one additional commit since the last revision:
>>
>> updated the javadoc
>
> You should update the GitHub PR title to `6356745: (coll) Add PriorityQueue(Collection, Comparator)` to match the JBS issue title.
>
> In addition, you will need a [CSR](https://wiki.openjdk.org/display/csr) as the bot tells you. Its prompt is like:
>
> Summary
> A concise description of the proposed change. The description should be one to two sentences long and written to be reusable in documents aggregating changes for a release.
>
> Problem
> A brief description of the problem, optionally including the motivation for developing a solution.
>
> Solution
> An overview of the solution. Alternative solutions may be discussed; links to rationale documents or review threads welcome to provide additional background to reviewers.
>
> Specification
> The detailed changes. Acceptable normative formats include inline patches, attached webrevs, and attached specdiffs. The names of attached files are recommended to include a bug id. References to external webservers, such as http://cr.openjdk.java.net/, can be provided as informative supplements for the convenience of reviewers, but must be accompanied by a normative form of the specification directly associated with the CSR issue to satisfy archival purposes.
>
>
> I can create one for you, and here's my proposed CSR content:
>
> Summary
> Add a new constructor to PriorityQueue that takes a Collection and a Comparator.
>
> Problem
> Creating a PriorityQueue with an existing Collection and a custom Comparator is inefficient; it can use heapify which is `O(N)` in time complexity, but it currently has to be done via `addAll`, which has `O(N log N)` time complexity.
>
> Solution
> Add a new constructor `PriorityQueue(Collection, Comparator)` to explicitly allow the heapify process when a custom comparator is given. This constructor would be in pair with `PriorityQueue(Collection)`, as all other PriorityQueue constructors come in natural-order and comparator pairs (`()` and `(Comparator)`, `(int)` and `(int, Comparator)` ones)
>
> An alternative solution would be to override `addAll(Collection)` to call `initFromCollection` when the PriorityQueue is empty. This would have the same effect as the new constructor and is applicable to all empty PriorityQueues, but doesn't solve the parity issue mentioned above.
>
> Specification
> --- a/src/java.base/share/classes/java/util/PriorityQueue.java
> +++ b/src/java.base/share/classes/java/util/PriorityQueue.java
> @@ -209,6 +209,25 @@ else if (c instanceof PriorityQueue<?>) {
> }
> }
>
> + /**...
@liach thanks for the help. I updated the PR title, also your proposed CSR content looks good to me. would you mind creating it with your proposed content?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/17045#issuecomment-1863481650
More information about the core-libs-dev
mailing list