@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean containsTyped(T node) { return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean containsTyped(T node) { return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean containsTyped(T node) { return contains(node, node.priorityQueueIndex(this)); }
@Override public void priorityChanged(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return; } // Preserve the min-heap property by comparing the new priority with parents/children in the heap. if (i == 0) { bubbleDown(i, node); } else { // Get the parent to see if min-heap properties are violated. int iParent = (i - 1) >>> 1; T parent = queue[iParent]; if (comparator.compare(node, parent) < 0) { bubbleUp(i, node); } else { bubbleDown(i, node); } } }
@Override public boolean removeTyped(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return false; } node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); if (--size == 0 || size == i) { // If there are no node left, or this is the last node in the array just remove and return. queue[i] = null; return true; } // Move the last element where node currently lives in the array. T moved = queue[i] = queue[size]; queue[size] = null; // priorityQueueIndex will be updated below in bubbleUp or bubbleDown // Make sure the moved node still preserves the min-heap properties. if (comparator.compare(node, moved) < 0) { bubbleDown(i, moved); } else { bubbleUp(i, moved); } return true; }
@Override public void priorityChanged(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return; } // Preserve the min-heap property by comparing the new priority with parents/children in the heap. if (i == 0) { bubbleDown(i, node); } else { // Get the parent to see if min-heap properties are violated. int iParent = (i - 1) >>> 1; T parent = queue[iParent]; if (comparator.compare(node, parent) < 0) { bubbleUp(i, node); } else { bubbleDown(i, node); } } }
@Override public boolean removeTyped(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return false; } node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); if (--size == 0 || size == i) { // If there are no node left, or this is the last node in the array just remove and return. queue[i] = null; return true; } // Move the last element where node currently lives in the array. T moved = queue[i] = queue[size]; queue[size] = null; // priorityQueueIndex will be updated below in bubbleUp or bubbleDown // Make sure the moved node still preserves the min-heap properties. if (comparator.compare(node, moved) < 0) { bubbleDown(i, moved); } else { bubbleUp(i, moved); } return true; }
@Override public void priorityChanged(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return; } // Preserve the min-heap property by comparing the new priority with parents/children in the heap. if (i == 0) { bubbleDown(i, node); } else { // Get the parent to see if min-heap properties are violated. int iParent = (i - 1) >>> 1; T parent = queue[iParent]; if (comparator.compare(node, parent) < 0) { bubbleUp(i, node); } else { bubbleDown(i, node); } } }
@Override public boolean removeTyped(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return false; } node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); if (--size == 0 || size == i) { // If there are no node left, or this is the last node in the array just remove and return. queue[i] = null; return true; } // Move the last element where node currently lives in the array. T moved = queue[i] = queue[size]; queue[size] = null; // priorityQueueIndex will be updated below in bubbleUp or bubbleDown // Make sure the moved node still preserves the min-heap properties. if (comparator.compare(node, moved) < 0) { bubbleDown(i, moved); } else { bubbleUp(i, moved); } return true; }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean containsTyped(T node) { return contains(node, node.priorityQueueIndex(this)); }
@Override public void priorityChanged(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return; } // Preserve the min-heap property by comparing the new priority with parents/children in the heap. if (i == 0) { bubbleDown(i, node); } else { // Get the parent to see if min-heap properties are violated. int iParent = (i - 1) >>> 1; T parent = queue[iParent]; if (comparator.compare(node, parent) < 0) { bubbleUp(i, node); } else { bubbleDown(i, node); } } }
@Override public boolean removeTyped(T node) { int i = node.priorityQueueIndex(this); if (!contains(node, i)) { return false; } node.priorityQueueIndex(this, INDEX_NOT_IN_QUEUE); if (--size == 0 || size == i) { // If there are no node left, or this is the last node in the array just remove and return. queue[i] = null; return true; } // Move the last element where node currently lives in the array. T moved = queue[i] = queue[size]; queue[size] = null; // priorityQueueIndex will be updated below in bubbleUp or bubbleDown // Make sure the moved node still preserves the min-heap properties. if (comparator.compare(node, moved) < 0) { bubbleDown(i, moved); } else { bubbleUp(i, moved); } return true; }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean containsTyped(T node) { return contains(node, node.priorityQueueIndex(this)); }
@Override public boolean contains(Object o) { if (!(o instanceof PriorityQueueNode)) { return false; } PriorityQueueNode node = (PriorityQueueNode) o; return contains(node, node.priorityQueueIndex(this)); }