31#include "fastjet/internal/MinHeap.hh"
36FASTJET_BEGIN_NAMESPACE
47void MinHeap::initialise(
const std::vector<double> & values){
51 for (
unsigned i = values.size(); i < _heap.size(); i++) {
52 _heap[i].value = std::numeric_limits<double>::max();
53 _heap[i].minloc = &(_heap[i]);
58 for (
unsigned i = 0; i < values.size(); i++) {
59 _heap[i].value = values[i];
60 _heap[i].minloc = &(_heap[i]);
64 for (
unsigned i = _heap.size()-1; i > 0; i--) {
65 ValueLoc * parent = &(_heap[(i-1)/2]);
66 ValueLoc * here = &(_heap[i]);
67 if (here->minloc->value < parent->minloc->value) {
68 parent->minloc = here->minloc;
79void MinHeap::update(
unsigned int loc,
double new_value) {
82 assert(loc < _heap.size());
83 ValueLoc * start = &(_heap[loc]);
87 if (start->minloc != start && !(new_value < start->minloc->value)) {
88 start->value = new_value;
94 start->value = new_value;
95 start->minloc = start;
97 bool change_made =
true;
99 ValueLoc * heap_end = (&(_heap[0])) + _heap.size();
103 ValueLoc * here = &(_heap[loc]);
107 if (here->minloc == start) {
108 here->minloc = here; change_made =
true;
120 ValueLoc * child = &(_heap[0]) + (2*loc+1);
121 if (child < heap_end && child->minloc->value < here->minloc->value ) {
122 here->minloc = child->minloc;
125 if (child < heap_end && child->minloc->value < here->minloc->value ) {
126 here->minloc = child->minloc;
130 if (loc == 0) {
break;}