/** * Adds an Object to a PriorityQueue in log(size) time. If one tries to add * more objects than maxSize from initialize an * {@link ArrayIndexOutOfBoundsException} is thrown. * * @return the new 'top' element in the queue. */ public final T add(T element) { size++; heap[size] = element; upHeap(size); return heap[1]; }
/** * Removes an existing element currently stored in the PriorityQueue. Cost is * linear with the size of the queue. (A specialization of PriorityQueue which * tracks element positions would provide a constant remove time but the * trade-off would be extra cost to all additions/insertions) */ public final boolean remove(T element) { for (int i = 1; i <= size; i++) { if (heap[i] == element) { heap[i] = heap[size]; heap[size] = null; // permit GC of objects size--; if (i <= size) { if (!upHeap(i)) { downHeap(i); } } return true; } } return false; }
/** * Adds an Object to a PriorityQueue in log(size) time. * If one tries to add more objects than maxSize from initialize * a RuntimeException (ArrayIndexOutOfBound) is thrown. */ public final void put(Object element) { size++; heap[size] = element; upHeap(); }
/** * Adds an Object to a PriorityQueue in log(size) time. If one tries to add * more objects than maxSize from initialize an * {@link ArrayIndexOutOfBoundsException} is thrown. * * @return the new 'top' element in the queue. */ public final T add(T element) { size++; heap[size] = element; upHeap(size); return heap[1]; }
/** * Adds an Object to a PriorityQueue in log(size) time. * If one tries to add more objects than maxSize from initialize * a RuntimeException (ArrayIndexOutOfBound) is thrown. */ public final void put(Object element) { size++; heap[size] = element; upHeap(); }
/** * Adds an Object to a PriorityQueue in log(size) time. * If one tries to add more objects than maxSize from initialize * a RuntimeException (ArrayIndexOutOfBound) is thrown. */ public final void put(Object element) { size++; heap[size] = element; upHeap(); }
/** * Adds an Object to a PriorityQueue in log(size) time. If one tries to add * more objects than maxSize from initialize an * {@link ArrayIndexOutOfBoundsException} is thrown. * * @return the new 'top' element in the queue. */ public final T add(T element) { size++; heap[size] = element; upHeap(size); return heap[1]; }
/** * Adds an Object to a PriorityQueue in log(size) time. If one tries to add * more objects than maxSize from initialize an * {@link ArrayIndexOutOfBoundsException} is thrown. * * @return the new 'top' element in the queue. */ public final T add(T element) { size++; heap[size] = element; upHeap(); return heap[1]; }
/** * Adds an Object to a PriorityQueue in log(size) time. If one tries to add * more objects than maxSize from initialize an * {@link ArrayIndexOutOfBoundsException} is thrown. * * @return the new 'top' element in the queue. */ public final T add(T element) { size++; heap[size] = element; upHeap(size); return heap[1]; }
/** * Removes an existing element currently stored in the PriorityQueue. Cost is * linear with the size of the queue. (A specialization of PriorityQueue which * tracks element positions would provide a constant remove time but the * trade-off would be extra cost to all additions/insertions) */ public final boolean remove(T element) { for (int i = 1; i <= size; i++) { if (heap[i] == element) { heap[i] = heap[size]; heap[size] = null; // permit GC of objects size--; if (i <= size) { if (!upHeap(i)) { downHeap(i); } } return true; } } return false; }
/** * Removes an existing element currently stored in the PriorityQueue. Cost is * linear with the size of the queue. (A specialization of PriorityQueue which * tracks element positions would provide a constant remove time but the * trade-off would be extra cost to all additions/insertions) */ public final boolean remove(T element) { for (int i = 1; i <= size; i++) { if (heap[i] == element) { heap[i] = heap[size]; heap[size] = null; // permit GC of objects size--; if (i <= size) { if (!upHeap(i)) { downHeap(i); } } return true; } } return false; }
/** * Removes an existing element currently stored in the PriorityQueue. Cost is * linear with the size of the queue. (A specialization of PriorityQueue which * tracks element positions would provide a constant remove time but the * trade-off would be extra cost to all additions/insertions) */ public final boolean remove(T element) { for (int i = 1; i <= size; i++) { if (heap[i] == element) { heap[i] = heap[size]; heap[size] = null; // permit GC of objects size--; if (i <= size) { if (!upHeap(i)) { downHeap(i); } } return true; } } return false; }