ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/PriorityQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/PriorityQueue.java (file contents):
Revision 1.113 by jsr166, Wed Nov 30 03:31:47 2016 UTC vs.
Revision 1.117 by jsr166, Tue Dec 20 22:37:31 2016 UTC

# Line 522 | Line 522 | public class PriorityQueue<E> extends Ab
522           */
523          private int expectedModCount = modCount;
524  
525 +        Itr() {}                        // prevent access constructor creation
526 +
527          public boolean hasNext() {
528              return cursor < size ||
529                  (forgetMeNot != null && !forgetMeNot.isEmpty());
# Line 631 | Line 633 | public class PriorityQueue<E> extends Ab
633       * promoting x up the tree until it is greater than or equal to
634       * its parent, or is the root.
635       *
636 <     * To simplify and speed up coercions and comparisons. the
636 >     * To simplify and speed up coercions and comparisons, the
637       * Comparable and Comparator versions are separated into different
638       * methods that are otherwise identical. (Similarly for siftDown.)
639       *
# Line 731 | Line 733 | public class PriorityQueue<E> extends Ab
733       */
734      @SuppressWarnings("unchecked")
735      private void heapify() {
736 <        for (int i = (size >>> 1) - 1; i >= 0; i--)
737 <            siftDown(i, (E) queue[i]);
736 >        final Object[] es = queue;
737 >        final int half = (size >>> 1) - 1;
738 >        if (comparator == null)
739 >            for (int i = half; i >= 0; i--)
740 >                siftDownComparable(i, (E) es[i]);
741 >        else
742 >            for (int i = half; i >= 0; i--)
743 >                siftDownUsingComparator(i, (E) es[i]);
744      }
745  
746      /**
# Line 817 | Line 825 | public class PriorityQueue<E> extends Ab
825      }
826  
827      final class PriorityQueueSpliterator implements Spliterator<E> {
820        /*
821         * This is very similar to ArrayList Spliterator, except for
822         * extra null checks.
823         */
828          private int index;            // current index, modified on advance/split
829          private int fence;            // -1 until first use
830          private int expectedModCount; // initialized when fence set
# Line 849 | Line 853 | public class PriorityQueue<E> extends Ab
853  
854          @SuppressWarnings("unchecked")
855          public void forEachRemaining(Consumer<? super E> action) {
852            int i, hi, mc; // hoist accesses and checks from loop
853            final Object[] a;
856              if (action == null)
857                  throw new NullPointerException();
858 <            if ((a = queue) != null) {
859 <                if ((hi = fence) < 0) {
860 <                    mc = modCount;
861 <                    hi = size;
862 <                }
863 <                else
864 <                    mc = expectedModCount;
863 <                if ((i = index) >= 0 && (index = hi) <= a.length) {
864 <                    for (E e;; ++i) {
865 <                        if (i < hi) {
866 <                            if ((e = (E) a[i]) == null) // must be CME
867 <                                break;
868 <                            action.accept(e);
869 <                        }
870 <                        else if (modCount != mc)
871 <                            break;
872 <                        else
873 <                            return;
874 <                    }
875 <                }
858 >            if (fence < 0) { fence = size; expectedModCount = modCount; }
859 >            final Object[] a = queue;
860 >            int i, hi; E e;
861 >            for (i = index, index = hi = fence; i < hi; i++) {
862 >                if ((e = (E) a[i]) == null)
863 >                    break;      // must be CME
864 >                action.accept(e);
865              }
866 <            throw new ConcurrentModificationException();
866 >            if (modCount != expectedModCount)
867 >                throw new ConcurrentModificationException();
868          }
869  
870 +        @SuppressWarnings("unchecked")
871          public boolean tryAdvance(Consumer<? super E> action) {
872              if (action == null)
873                  throw new NullPointerException();
874 <            int hi = getFence(), lo = index;
875 <            if (lo >= 0 && lo < hi) {
876 <                index = lo + 1;
877 <                @SuppressWarnings("unchecked") E e = (E)queue[lo];
878 <                if (e == null)
874 >            if (fence < 0) { fence = size; expectedModCount = modCount; }
875 >            int i;
876 >            if ((i = index) < fence) {
877 >                index = i + 1;
878 >                E e;
879 >                if ((e = (E) queue[i]) == null
880 >                    || modCount != expectedModCount)
881                      throw new ConcurrentModificationException();
882                  action.accept(e);
890                if (modCount != expectedModCount)
891                    throw new ConcurrentModificationException();
883                  return true;
884              }
885              return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines