Lines Matching refs:queue

29  * An unbounded priority {@linkplain Queue queue} based on a priority heap.
30 * The elements of the priority queue are ordered according to their
32 * provided at queue construction time, depending on which constructor is
33 * used. A priority queue does not permit {@code null} elements.
34 * A priority queue relying on natural ordering also does not permit
38 * <p>The <em>head</em> of this queue is the <em>least</em> element
41 * broken arbitrarily. The queue retrieval operations {@code poll},
43 * element at the head of the queue.
45 * <p>A priority queue is unbounded, but has an internal
47 * elements on the queue. It is always at least as large as the queue
48 * size. As elements are added to a priority queue, its capacity
56 * the priority queue in any particular order. If you need ordered
61 * instance concurrently if any of the threads modifies the queue.
88 * Priority queue represented as a balanced binary heap: the two
89 * children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The
90 * priority queue is ordered by comparator, or by the elements'
93 * lowest value is in queue[0], assuming the queue is nonempty.
95 private transient Object[] queue;
98 * The number of elements in the priority queue.
103 * The comparator, or null if priority queue uses elements'
109 * The number of times this priority queue has been
128 * @param initialCapacity the initial capacity for this priority queue
140 * @param initialCapacity the initial capacity for this priority queue
142 * priority queue. If {@code null}, the {@linkplain Comparable
153 this.queue = new Object[initialCapacity];
161 * priority queue will be ordered according to the same ordering.
162 * Otherwise, this priority queue will be ordered according to the
166 * into this priority queue
169 * queue's ordering
193 * specified priority queue. This priority queue will be
195 * queue.
197 * @param c the priority queue whose elements are to be placed
198 * into this priority queue
202 * @throws NullPointerException if the specified priority queue or any
213 * specified sorted set. This priority queue will be ordered
217 * into this priority queue
232 this.queue = c.toArray();
249 this.queue = a;
254 * Initializes queue array with elements from the given Collection.
277 int oldCapacity = queue.length;
285 queue = Arrays.copyOf(queue, newCapacity);
297 * Inserts the specified element into this priority queue.
301 * compared with elements currently in this priority queue
302 * according to the priority queue's ordering
310 * Inserts the specified element into this priority queue.
314 * compared with elements currently in this priority queue
315 * according to the priority queue's ordering
323 if (i >= queue.length)
327 queue[0] = e;
336 return (E) queue[0];
342 if (o.equals(queue[i]))
349 * Removes a single instance of the specified element from this queue,
351 * that {@code o.equals(e)}, if this queue contains one or more such
352 * elements. Returns {@code true} if and only if this queue contained
353 * the specified element (or equivalently, if this queue changed as a
356 * @param o element to be removed from this queue, if present
357 * @return {@code true} if this queue changed as a result of the call
373 * @param o element to be removed from this queue, if present
378 if (o == queue[i]) {
387 * Returns {@code true} if this queue contains the specified element.
388 * More formally, returns {@code true} if and only if this queue contains
391 * @param o object to be checked for containment in this queue
392 * @return {@code true} if this queue contains the specified element
399 * Returns an array containing all of the elements in this queue.
403 * maintained by this queue. (In other words, this method must allocate
409 * @return an array containing all of the elements in this queue
412 return Arrays.copyOf(queue, size);
416 * Returns an array containing all of the elements in this queue; the
419 * If the queue fits in the specified array, it is returned therein.
421 * specified array and the size of this queue.
423 * <p>If the queue fits in the specified array with room to spare
424 * (i.e., the array has more elements than the queue), the element in
433 * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
434 * The following code can be used to dump the queue into a newly
443 * @param a the array into which the elements of the queue are to
446 * @return an array containing all of the elements in this queue
449 * this queue
455 return (T[]) Arrays.copyOf(queue, size, a.getClass());
456 System.arraycopy(queue, 0, a, 0, size);
463 * Returns an iterator over the elements in this queue. The iterator
466 * @return an iterator over the elements in this queue
474 * Index (into queue array) of element to be returned by
487 * A queue of elements that were moved from the unvisited portion of
521 return (E) queue[lastRet = cursor++];
559 * Removes all of the elements from this priority queue.
560 * The queue will be empty after this call returns.
565 queue[i] = null;
574 E result = (E) queue[0];
575 E x = (E) queue[s];
576 queue[s] = null;
583 * Removes the ith element from queue.
599 queue[i] = null;
601 E moved = (E) queue[s];
602 queue[s] = null;
604 if (queue[i] == moved) {
606 if (queue[i] != moved)
636 Object e = queue[parent];
639 queue[k] = e;
642 queue[k] = key;
648 Object e = queue[parent];
651 queue[k] = e;
654 queue[k] = x;
677 Object c = queue[child];
680 ((Comparable<? super E>) c).compareTo((E) queue[right]) > 0)
681 c = queue[child = right];
684 queue[k] = c;
687 queue[k] = key;
694 Object c = queue[child];
697 comparator.compare((E) c, (E) queue[right]) > 0)
698 c = queue[child = right];
701 queue[k] = c;
704 queue[k] = x;
713 siftDown(i, (E) queue[i]);
718 * queue, or {@code null} if this queue is sorted according to
721 * @return the comparator used to order this queue, or
722 * {@code null} if this queue is sorted according to the
748 s.writeObject(queue[i]);
765 queue = new Object[size];
769 queue[i] = s.readObject();