Insert id with priority specified.
| 37 | |
| 38 | // Insert id with priority specified. |
| 39 | void vtkPriorityQueue::Insert(double priority, vtkIdType id) |
| 40 | { |
| 41 | vtkIdType i, idx; |
| 42 | vtkPriorityQueue::Item temp; |
| 43 | |
| 44 | // check and make sure item hasn't been inserted before |
| 45 | if (id <= this->ItemLocation->GetMaxId() && this->ItemLocation->GetValue(id) != -1) |
| 46 | { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | // start by placing new entry at bottom of tree |
| 51 | if (++this->MaxId >= this->Size) |
| 52 | { |
| 53 | this->Resize(this->MaxId + 1); |
| 54 | } |
| 55 | this->Array[this->MaxId].priority = priority; |
| 56 | this->Array[this->MaxId].id = id; |
| 57 | |
| 58 | vtkIdType oldMaxId = this->ItemLocation->GetMaxId(); |
| 59 | this->ItemLocation->InsertValue(id, this->MaxId); // this does allocation |
| 60 | for (i = oldMaxId + 1; i < id; i++) |
| 61 | { |
| 62 | // initialize previously unused elements |
| 63 | this->ItemLocation->SetValue(i, -1); |
| 64 | } |
| 65 | |
| 66 | // now begin percolating towards top of tree |
| 67 | for (i = this->MaxId; |
| 68 | i > 0 && this->Array[i].priority < this->Array[(idx = (i - 1) / 2)].priority; i = idx) |
| 69 | { |
| 70 | temp = this->Array[i]; |
| 71 | |
| 72 | this->ItemLocation->SetValue(temp.id, idx); |
| 73 | this->Array[i] = this->Array[idx]; |
| 74 | |
| 75 | this->ItemLocation->SetValue(this->Array[idx].id, i); |
| 76 | this->Array[idx] = temp; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // Simplified call for easier wrapping for Tcl. |
| 81 | vtkIdType vtkPriorityQueue::Pop(vtkIdType location) |
no test coverage detected