Skip to content
Snippets Groups Projects
Commit 31bc9a28 authored by David Gobbi's avatar David Gobbi Committed by Lucas Givord
Browse files

Simply vtkPriorityQueue array usage

This class was accessing its ItemLocation array beyond MaxId, now
it uses the array in a more standard way.

(cherry picked from commit 432053f7)
parent 38d8678a
No related branches found
No related tags found
No related merge requests found
......@@ -21,11 +21,6 @@ vtkPriorityQueue::vtkPriorityQueue()
void vtkPriorityQueue::Allocate(vtkIdType sz, vtkIdType ext)
{
this->ItemLocation->Allocate(sz, ext);
for (vtkIdType i = 0; i < sz; i++)
{
this->ItemLocation->SetValue(i, -1);
}
this->Size = (sz > 0 ? sz : 1);
delete[] this->Array;
this->Array = new vtkPriorityQueue::Item[sz];
......@@ -59,19 +54,15 @@ void vtkPriorityQueue::Insert(double priority, vtkIdType id)
}
this->Array[this->MaxId].priority = priority;
this->Array[this->MaxId].id = id;
if (id >= this->ItemLocation->GetSize()) // might have to resize and initialize
vtkIdType oldMaxId = this->ItemLocation->GetMaxId();
this->ItemLocation->InsertValue(id, this->MaxId); // this does allocation
for (i = oldMaxId + 1; i < id; i++)
{
vtkIdType oldSize = this->ItemLocation->GetSize();
this->ItemLocation->InsertValue(id, this->MaxId);
for (i = oldSize; i < this->ItemLocation->GetSize(); i++)
{
this->ItemLocation->SetValue(i, -1);
}
this->ItemLocation->SetValue(id, this->MaxId);
// initialize previously unused elements
this->ItemLocation->SetValue(i, -1);
}
this->ItemLocation->InsertValue(id, this->MaxId);
// now begin percolating towards top of tree
for (i = this->MaxId;
i > 0 && this->Array[i].priority < this->Array[(idx = (i - 1) / 2)].priority; i = idx)
......@@ -214,11 +205,6 @@ vtkPriorityQueue::Item* vtkPriorityQueue::Resize(vtkIdType sz)
void vtkPriorityQueue::Reset()
{
this->MaxId = -1;
for (int i = 0; i <= this->ItemLocation->GetMaxId(); i++)
{
this->ItemLocation->SetValue(i, -1);
}
this->ItemLocation->Reset();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment