DAS  3.0
Das Analysis System
MinHeap
+ Collaboration diagram for MinHeap:

Classes

struct  ValueLoc
 

Public Member Functions

 MinHeap (const std::vector< double > &values, unsigned int max_size)
 
 MinHeap (unsigned int max_size)
 
 MinHeap (const std::vector< double > &values)
 
void initialise (const std::vector< double > &values)
 
unsigned int minloc () const
 
double minval () const
 
double operator[] (int i) const
 
void remove (unsigned int loc)
 
void update (unsigned int, double)
 

Private Attributes

std::vector< ValueLoc_heap
 

Constructor & Destructor Documentation

◆ MinHeap() [1/3]

MinHeap ( const std::vector< double > &  values,
unsigned int  max_size 
)
inline
649  :
650  _heap(max_size) {initialise(values);}

◆ MinHeap() [2/3]

MinHeap ( unsigned int  max_size)
inline
651 : _heap(max_size) {}

◆ MinHeap() [3/3]

MinHeap ( const std::vector< double > &  values)
inline
652  :
653  _heap(values.size()) {initialise(values);}

Member Function Documentation

◆ initialise()

void initialise ( const std::vector< double > &  values)
3691  {
3692  for (unsigned i = values.size(); i < _heap.size(); i++) {
3693  _heap[i].value = std::numeric_limits<double>::max();
3694  _heap[i].minloc = &(_heap[i]);
3695  }
3696  for (unsigned i = 0; i < values.size(); i++) {
3697  _heap[i].value = values[i];
3698  _heap[i].minloc = &(_heap[i]);
3699  }
3700  for (unsigned i = _heap.size()-1; i > 0; i--) {
3701  ValueLoc * parent = &(_heap[(i-1)/2]);
3702  ValueLoc * here = &(_heap[i]);
3703  if (here->minloc->value < parent->minloc->value) {
3704  parent->minloc = here->minloc;
3705  }
3706  }
3707 }

◆ minloc()

unsigned int minloc ( ) const
inline
655  {
656  return (_heap[0].minloc) - &(_heap[0]);}

◆ minval()

double minval ( ) const
inline
657 {return _heap[0].minloc->value;}

◆ operator[]()

double operator[] ( int  i) const
inline
658 {return _heap[i].value;}

◆ remove()

void remove ( unsigned int  loc)
inline
659  {
660  update(loc,std::numeric_limits<double>::max());};

◆ update()

void update ( unsigned int  loc,
double  new_value 
)
3708  {
3709  assert(loc < _heap.size());
3710  ValueLoc * start = &(_heap[loc]);
3711  if (start->minloc != start && !(new_value < start->minloc->value)) {
3712  start->value = new_value;
3713  return;
3714  }
3715  start->value = new_value;
3716  start->minloc = start;
3717  bool change_made = true;
3718  ValueLoc * heap_end = (&(_heap[0])) + _heap.size();
3719  while(change_made) {
3720  ValueLoc * here = &(_heap[loc]);
3721  change_made = false;
3722  if (here->minloc == start) {
3723  here->minloc = here; change_made = true;
3724  }
3725  ValueLoc * child = &(_heap[2*loc+1]);
3726  if (child < heap_end && child->minloc->value < here->minloc->value ) {
3727  here->minloc = child->minloc;
3728  change_made = true;}
3729  child++;
3730  if (child < heap_end && child->minloc->value < here->minloc->value ) {
3731  here->minloc = child->minloc;
3732  change_made = true;}
3733  if (loc == 0) {break;}
3734  loc = (loc-1)/2;
3735  }
3736 }

Member Data Documentation

◆ _heap

std::vector<ValueLoc> _heap
private

The documentation for this class was generated from the following file:
MinHeap::update
void update(unsigned int, double)
Definition: fjcore.cc:3708
MinHeap::_heap
std::vector< ValueLoc > _heap
Definition: fjcore.cc:667
MinHeap::minloc
unsigned int minloc() const
Definition: fjcore.cc:655
MinHeap::initialise
void initialise(const std::vector< double > &values)
Definition: fjcore.cc:3691