MCPcopy Create free account
hub / github.com/Kitware/VTK / Insert

Method Insert

Common/Core/vtkPriorityQueue.cxx:39–78  ·  view source on GitHub ↗

Insert id with priority specified.

Source from the content-addressed store, hash-verified

37
38// Insert id with priority specified.
39void 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.
81vtkIdType vtkPriorityQueue::Pop(vtkIdType location)

Callers 3

PartitionMethod · 0.45
operator()Method · 0.45
operator()Method · 0.45

Calls 4

ResizeMethod · 0.95
GetValueMethod · 0.45
InsertValueMethod · 0.45
SetValueMethod · 0.45

Tested by

no test coverage detected