def _siftup_max(heap, pos):
 endpos = len(heap)
 startpos = pos
 newitem = heap[pos]
 childpos = ((2 * pos) + 1)
 while (childpos < endpos):
  rightpos = (childpos + 1)
  if ((rightpos < endpos) and (not cmp_lt(heap[rightpos], heap[childpos]))):
   childpos = rightpos
  heap[pos] = heap[childpos]
  pos = childpos
  childpos = ((2 * pos) + 1)
 heap[pos] = newitem
 _siftdown_max(heap, startpos, pos)

def _siftup_max ( heap , pos ) : endpos = len ( heap ) startpos = pos newitem = heap [ pos ] childpos = ( ( 2 * pos ) + 1 ) while ( childpos < endpos ) : rightpos = ( childpos + 1 ) if ( ( rightpos < endpos ) and ( not cmp_lt ( heap [ rightpos ] , heap [ childpos ] ) ) ) : childpos = rightpos heap [ pos ] = heap [ childpos ] pos = childpos childpos = ( ( 2 * pos ) + 1 ) heap [ pos ] = newitem _siftdown_max ( heap , startpos , pos )
maxheap variant of _siftup .