include/indexedHeap.h
void insert(double P, uint32_t R) {
    if (_rev.size()<=R) _rev.resize(R+1,0);    // make sure we have enough space for ID
    size_t i;
    if (_rev[R] != 0) {              				// if index "R" already exists
      i=_rev[R]; _p[i-1]=P;									//   just change its priority
      maxHeapify(i);												//   and push down heap (so, heapified below)
    } else {																// otherwise, add it at the end
      _p.push_back(P); _id.push_back(R); _rev[R]=size();   // _rev index is 1...N
      i=size();
    }
    for (;;) {															// now walk upward from inserted point
      size_t parent=i/2;										//  and make sure heap property is preserved
      if (parent>0 && _p[parent-1] < _p[i-1]) { 
        heapSwap(parent,i);
        i=parent;
      } else return;												// quit whenever we're in heap order
    }
  }
// Insert or change the priority of an element with (unique) ID "R" and priority "P"
Insert or change the priority of an element with (unique) ID "R" and priority "P"
Insert or change the priority of an element with ( unique ) ID " R " and priority " P "
void insert(double P, uint32_t R) {
    if (_rev.size()<=R) _rev.resize(R+1,0);    
    size_t i;
    if (_rev[R] != 0) {              				
      i=_rev[R]; _p[i-1]=P;									
      maxHeapify(i);												
    } else {																
      _p.push_back(P); _id.push_back(R); _rev[R]=size();   
      i=size();
    }
    for (;;) {															
      size_t parent=i/2;										
      if (parent>0 && _p[parent-1] < _p[i-1]) { 
        heapSwap(parent,i);
        i=parent;
      } else return;												
    }
  }
void insert ( double P , uint32_t R ) { if ( _rev . size ( ) <= R ) _rev . resize ( R + 1 , 0 ) ; size_t i ; if ( _rev [ R ] != 0 ) { i = _rev [ R ] ; _p [ i - 1 ] = P ; maxHeapify ( i ) ; } else { _p . push_back ( P ) ; _id . push_back ( R ) ; _rev [ R ] = size ( ) ; i = size ( ) ; } for ( ; ; ) { size_t parent = i / 2 ; if ( parent > 0 && _p [ parent - 1 ] < _p [ i - 1 ] ) { heapSwap ( parent , i ) ; i = parent ; } else return ; } }
Insert or change the priority of an element with (unique) ID "R" and priority "P"
Insert or change the priority of an element with ( unique ) ID " R " and priority " P "
// make sure we have enough space for ID // if index "R" already exists //   just change its priority //   and push down heap (so, heapified below) // otherwise, add it at the end // _rev index is 1...N // now walk upward from inserted point //  and make sure heap property is preserved // quit whenever we're in heap order