Re: New methods in PriorityQueue

2022-03-06 Thread Julian Waters
was also (1.) that I was curious about the reasons why they are missing and (2.) about the JDK PR process in general. And this curiosity has been satisfied. 1. I was not really aware about the requirements of the API user to maintain the "invariants of the PriorityQueue" while usin

Re: New methods in PriorityQueue

2022-03-04 Thread Roger Riggs
this. The general rule for collections that use hashes and comparison methods (such as HashMap and TreeMap, as well as PriorityQueue) is that one mustn't mutate any element that resides in such a collection in any way that changes the results of hashCode, equals, or the comparison method. It's a bad

Re: New methods in PriorityQueue

2022-03-03 Thread Julian Waters
Stuart Marks wrote: > I agree with Roger. Let me amplify this. > > The general rule for collections that use hashes and comparison methods > (such as > HashMap and TreeMap, as well as PriorityQueue) is that one mustn't mutate > any > element that resides in such a

Re: New methods in PriorityQueue

2022-03-03 Thread Stuart Marks
I agree with Roger. Let me amplify this. The general rule for collections that use hashes and comparison methods (such as HashMap and TreeMap, as well as PriorityQueue) is that one mustn't mutate any element that resides in such a collection in any way that changes the results of hashCode

Re: PriorityQueue PR requiring review

2022-03-03 Thread David Holmes
oracle.com> > <mailto:david.hol...@oracle.com <mailto:david.hol...@oracle.com>>> wrote: > >     Hi Julian, > >     On 3/03/2022 10:33 pm, Jules W. wrote: >      > Hi all, >      > >      > A new PR that adds m

Re: New methods in PriorityQueue

2022-03-03 Thread Roger Riggs
Hi Julian, Modifying the priorities of elements in the PriorityQueue violates the invariants of the PriorityQueue established at insertion and maintained at removal by the Comparator. To maintain the invariant the element should be removed, its priority modified, and re-inserted. An API

New methods in PriorityQueue

2022-03-03 Thread Jules W.
Hi all, A new PR that adds methods to PriorityQueue was created some time ago at https://github.com/openjdk/jdk/pull/6938 but has no corresponding issue. As I'm not too familiar with this part of the JDK I'm querying this mailing list for anyone to properly review the PR before I create an issue

Re: PriorityQueue PR requiring review

2022-03-03 Thread Julian Waters
t 8:45 PM David Holmes > <mailto:david.hol...@oracle.com>> wrote: > > > > Hi Julian, > > > > On 3/03/2022 10:33 pm, Jules W. wrote: > > > Hi all, > > > > > > A new PR that adds methods to PriorityQueue was

Re: PriorityQueue PR requiring review

2022-03-03 Thread David Holmes
10:33 pm, Jules W. wrote: > Hi all, > > A new PR that adds methods to PriorityQueue was created some time ago at > https://github.com/openjdk/jdk/pull/6938 <https://github.com/openjdk/jdk/pull/6938> but has no corresponding issue. As > I'm n

Re: PriorityQueue PR requiring review

2022-03-03 Thread Julian Waters
022 10:33 pm, Jules W. wrote: > > Hi all, > > > > A new PR that adds methods to PriorityQueue was created some time ago at > > https://github.com/openjdk/jdk/pull/6938 but has no corresponding > issue. As > > I'm not too familiar with this part of the JDK I'm

Re: PriorityQueue PR requiring review

2022-03-03 Thread Julian Waters
> On 3/03/2022 10:33 pm, Jules W. wrote: > >> Hi all, > >> > >> A new PR that adds methods to PriorityQueue was created some time ago at > >> https://github.com/openjdk/jdk/pull/6938 but has no corresponding > >> issue. As > >> I'm not too fam

Re: PriorityQueue PR requiring review

2022-03-03 Thread David Holmes
Sorry Julian, I see now you were the person aiding the person who created the PR. David On 3/03/2022 10:45 pm, David Holmes wrote: Hi Julian, On 3/03/2022 10:33 pm, Jules W. wrote: Hi all, A new PR that adds methods to PriorityQueue was created some time ago at https://github.com/openjdk

Re: PriorityQueue PR requiring review

2022-03-03 Thread David Holmes
Hi Julian, On 3/03/2022 10:33 pm, Jules W. wrote: Hi all, A new PR that adds methods to PriorityQueue was created some time ago at https://github.com/openjdk/jdk/pull/6938 but has no corresponding issue. As I'm not too familiar with this part of the JDK I'm querying this mailing list

PriorityQueue PR requiring review

2022-03-03 Thread Jules W.
Hi all, A new PR that adds methods to PriorityQueue was created some time ago at https://github.com/openjdk/jdk/pull/6938 but has no corresponding issue. As I'm not too familiar with this part of the JDK I'm querying this mailing list for anyone to properly review the PR before I create an issue

Re: PriorityQueue

2015-05-18 Thread Brett Bernstein
I believe the linked sequence of messages refer to the addition of a PriorityQueue constructor only taking a Comparator which was does appear in Java 1.8. Did you have a link to something regarding the a constructor taking a Collection and a Comparator (2 arguments)? On Thu, May 14, 2015 at 2

Re: PriorityQueue

2015-05-16 Thread Paul Sandoz
On May 15, 2015, at 4:04 PM, Chris Hegarty chris.hega...@oracle.com wrote: And/Or should PriorityQueue override addAll and provide a more performant implementation for common Collection types ( just like the constructor )? It should be possible to improve this case too: create a new array

Re: PriorityQueue

2015-05-15 Thread Paul Sandoz
On May 15, 2015, at 3:20 PM, Vitaly Davidovich vita...@gmail.com wrote: Paul, I don't think you're missing anything obvious (unless I am as well :)). What you wrote is basically what I meant by creating static helper method in Brett's own code that does exactly what you wrote. The

Re: PriorityQueue

2015-05-15 Thread Paul Sandoz
On May 14, 2015, at 8:17 AM, Brett Bernstein brett.bernst...@gmail.com wrote: I believe the linked sequence of messages refer to the addition of a PriorityQueue constructor only taking a Comparator which was does appear in Java 1.8. Did you have a link to something regarding

Re: PriorityQueue

2015-05-15 Thread Stuart Marks
Yes, this is very subtle, and Brett mentioned it (albeit somewhat obliquely) in an email on jdk9-dev: [1] If someone needs to make a heap and their data is Comparable, the corresponding constructor gives a O(n) runtime. If their data uses a Comparator, the corresponding runtime (using addAll)

Re: PriorityQueue

2015-05-15 Thread Vitaly Davidovich
Whoops, I believe you're right -- I completely overlooked that as well :( On Fri, May 15, 2015 at 12:40 PM, Paul Sandoz paul.san...@oracle.com wrote: On May 15, 2015, at 6:15 PM, Louis Wasserman lowas...@google.com wrote: http://lcm.csa.iisc.ernet.in/dsa/node139.html suggests an algorithm

Re: PriorityQueue

2015-05-15 Thread Paul Sandoz
On May 15, 2015, at 6:15 PM, Louis Wasserman lowas...@google.com wrote: http://lcm.csa.iisc.ernet.in/dsa/node139.html suggests an algorithm for heapifying an unsorted array in O(n), corroborated elsewhere at http://courses.csail.mit.edu/6.006/fall10/handouts/recitation10-8.pdf . Any

Re: PriorityQueue

2015-05-15 Thread Vitaly Davidovich
I was initially confused by this because it seems to attribute the algorithmic difference to Comparable vs Comparator, which doesn't make any sense That's exactly what threw me off as well, but I didn't bother checking (doh!). Anyway, I think the upside is we're all in agreement now that

Re: PriorityQueue

2015-05-14 Thread Martin Buchholz
Software is hard. We tried and got stuck, although the former effort can be revived. RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator) http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-July/019124.html On Wed, May 13, 2015 at 10:17 PM, Brett Bernstein brett.bernst

Re: PriorityQueue

2015-05-14 Thread Martin Buchholz
On Wed, May 13, 2015 at 11:17 PM, Brett Bernstein brett.bernst...@gmail.com wrote: I believe the linked sequence of messages refer to the addition of a PriorityQueue constructor only taking a Comparator which was does appear in Java 1.8. Did you have a link to something regarding

Re: PriorityQueue

2015-05-14 Thread Dawid Weiss
On Thu, May 14, 2015 at 8:21 AM, Martin Buchholz marti...@google.com wrote: On Wed, May 13, 2015 at 11:17 PM, Brett Bernstein brett.bernst...@gmail.com wrote: I believe the linked sequence of messages refer to the addition of a PriorityQueue constructor only taking a Comparator which was does

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-08-07 Thread Doug Lea
On 07/25/13 10:15, Doug Lea wrote: On 07/24/13 19:30, Martin Buchholz wrote: PriorityQueue is unusual in that Doug maintains a copy in jsr166 CVS even though it is a non-thread-safe collection. I think it makes sense, because PriorityQueue and PriorityBlockingQueue have parallel APIs

RFR: 8021601 : (xxs) Add unit test for PriorityQueue(Comparator) constructor

2013-07-26 Thread Mike Duigou
Hello all; JDK-6799426 (http://hg.openjdk.java.net/jdk8/tl/jdk/rev/a6cbb9808e4b) was pushed without a unit test. (Always recheck for unit tests when breathing life back into a stale old patch). A unit test is needed. This change adds an additional case to an existing test to exercise the new

Re: RFR: 8021601 : (xxs) Add unit test for PriorityQueue(Comparator) constructor

2013-07-26 Thread Joseph Darcy
Looks good Mike; cheers, -Joe On 7/26/2013 5:06 PM, Mike Duigou wrote: Hello all; JDK-6799426 (http://hg.openjdk.java.net/jdk8/tl/jdk/rev/a6cbb9808e4b) was pushed without a unit test. (Always recheck for unit tests when breathing life back into a stale old patch). A unit test is needed.

Re: RFR: 8021601 : (xxs) Add unit test for PriorityQueue(Comparator) constructor

2013-07-26 Thread Alan Bateman
On 26/07/2013 17:06, Mike Duigou wrote: Hello all; JDK-6799426 (http://hg.openjdk.java.net/jdk8/tl/jdk/rev/a6cbb9808e4b) was pushed without a unit test. (Always recheck for unit tests when breathing life back into a stale old patch). A unit test is needed. This change adds an additional case

hg: jdk8/tl/jdk: 8021601: Add unit test for PriorityQueue(Comparator) constructor

2013-07-26 Thread mike . duigou
Changeset: f056728871f8 Author:mduigou Date: 2013-07-26 17:23 -0700 URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/f056728871f8 8021601: Add unit test for PriorityQueue(Comparator) constructor Reviewed-by: darcy, alanb ! src/share/classes/java/util/PriorityQueue.java ! test/java

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-25 Thread Doug Lea
On 07/24/13 19:30, Martin Buchholz wrote: PriorityQueue is unusual in that Doug maintains a copy in jsr166 CVS even though it is a non-thread-safe collection. I think it makes sense, because PriorityQueue and PriorityBlockingQueue have parallel APIs and parallel implementations. Many changes

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-24 Thread Mike Duigou
Yes, and there should be. I will open an issue. Mike On Jul 23 2013, at 17:26 , Alan Bateman wrote: On 22/07/2013 12:24, Mike Duigou wrote: Hello all; A simple rewiew for the addition of another constructor to PriorityQueue. Currently if you wish to specify a Comparator you must also

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-23 Thread Alan Bateman
On 22/07/2013 12:24, Mike Duigou wrote: Hello all; A simple rewiew for the addition of another constructor to PriorityQueue. Currently if you wish to specify a Comparator you must also supply a size. This addition allows use of the default size which is good for two reason; you don't have

RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-22 Thread Mike Duigou
Hello all; A simple rewiew for the addition of another constructor to PriorityQueue. Currently if you wish to specify a Comparator you must also supply a size. This addition allows use of the default size which is good for two reason; you don't have to specify a fixed value

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-22 Thread Lance Andersen - Oracle
looks fine Mike Best Lance On Jul 22, 2013, at 3:24 PM, Mike Duigou wrote: Hello all; A simple rewiew for the addition of another constructor to PriorityQueue. Currently if you wish to specify a Comparator you must also supply a size. This addition allows use of the default size which

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-22 Thread Remi Forax
On 07/22/2013 09:42 PM, Lance Andersen - Oracle wrote: looks fine Mike Best Lance Yes, fine for me too. Rémi On Jul 22, 2013, at 3:24 PM, Mike Duigou wrote: Hello all; A simple rewiew for the addition of another constructor to PriorityQueue. Currently if you wish to specify a Comparator

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-22 Thread Chris Hegarty
On 22/07/2013 20:24, Mike Duigou wrote: Hello all; A simple rewiew for the addition of another constructor to PriorityQueue. Currently if you wish to specify a Comparator you must also supply a size. This addition allows use of the default size which is good for two reason; you don't have

RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-22 Thread Paul Benedict
Mike, I know the description is pulled from the previous constructor, but both sound a bit awkward. Both can probably benefit from an improvement. Currently: Creates a {@code PriorityQueue} with the default initial capacity that orders its elements according to the specified comparator

Re: RFR : 6799426 : (xs) Add constructor PriorityQueue(Comparator)

2013-07-22 Thread Mike Duigou
, but both sound a bit awkward. Both can probably benefit from an improvement. Currently: Creates a {@code PriorityQueue} with the default initial capacity that orders its elements according to the specified comparator. Depending on one's spoken emphasis, it can sound as if the capacity

Re: PriorityQueue(collection) should throw NPE

2010-05-07 Thread Chris Hegarty
a PriorityQueue subclass), or can it simply call initElementsFromCollection? -Chris. On 07/05/2010 03:37, David Holmes wrote: Hi Martin, CR 6950540 filed. (Chris might want to tidy it up :) ) Changes look okay to me. Thanks, David Martin Buchholz said the following on 05/07/10 12:19: David

Re: PriorityQueue(collection) should throw NPE

2010-05-07 Thread David Holmes
to call initFromCollection ( in the case where you're given a PriorityQueue subclass), or can it simply call initElementsFromCollection? It's possible that the subclass overrides toArray to return an array that doesn't preserve the internal order. Hence we need to re-sort, hence

Re: PriorityQueue(collection) should throw NPE

2010-05-07 Thread Chris Hegarty
. Is it necessary for initFromPriorityQueue to call initFromCollection ( in the case where you're given a PriorityQueue subclass), or can it simply call initElementsFromCollection? It's possible that the subclass overrides toArray to return an array that doesn't preserve the internal order. Hence we

Re: PriorityQueue(collection) should throw NPE

2010-05-07 Thread Martin Buchholz
observation while reviewing the changes. Is it necessary for initFromPriorityQueue to call initFromCollection ( in the case where you're given a PriorityQueue subclass), or can it simply call initElementsFromCollection? It's possible that the subclass overrides toArray to return an array

PriorityQueue(collection) should throw NPE

2010-05-06 Thread Martin Buchholz
This is a bug report with fix. (Chris, please file a bug) Summary: PriorityQueue(collection) should throw NPE if collection contains a null Description: PriorityQueue spec says: A priority queue does not permit {...@code null} elements. but the constructor taking a collection does not enforce

Re: PriorityQueue(collection) should throw NPE

2010-05-06 Thread David Holmes
Martin, Martin Buchholz said the following on 05/07/10 08:24: This is a bug report with fix. (Chris, please file a bug) Summary: PriorityQueue(collection) should throw NPE if collection contains a null Description: PriorityQueue spec says: A priority queue does not permit {...@code null

Re: PriorityQueue(collection) should throw NPE

2010-05-06 Thread Martin Buchholz
an existing PriorityQueue. Strictly speaking, the source PriorityQueue might be a subclass that has been modified to accept nulls. But yes, we could have a version of the fix that only checks for nulls if the source is not a PQ. So is it only the case for filling from a SortedSet that needs the explicit

Re: PriorityQueue(collection) should throw NPE

2010-05-06 Thread David Holmes
that incidental nulls will be caught in many/most cases by the sorting code for collections assumed to contain Comparable's. The comparator might accept nulls. True but a Comparator is only used if the Collection is a SortedSet or a PriorityQueue. For any other Collection the elements must implement

Re: PriorityQueue(collection) should throw NPE

2010-05-06 Thread Martin Buchholz
the right fix. It seems to me that incidental nulls will be caught in many/most cases by the sorting code for collections assumed to contain Comparable's. The comparator might accept nulls. True but a Comparator is only used if the Collection is a SortedSet or a PriorityQueue. For any other

Re: PriorityQueue(collection) should throw NPE

2010-05-06 Thread David Holmes
Comparable's. The comparator might accept nulls. True but a Comparator is only used if the Collection is a SortedSet or a PriorityQueue. For any other Collection the elements must implement Comparable and the code in: private void siftDownComparable(int k, E x) { Comparable? super E key