private void down ( int element ) { assert this . contains ( element ) ; int epos = this . pos . get ( element ) ; int size = this . heap . size ( ) ; while ( true ) { int cpos = left ( epos ) ; if ( cpos >= size ) break ; int c = this . heap . get ( cpos ) ; int o ; int opos = right ( epos ) ; if ( ! this . less ( element , c ) ) { if ( opos >= size ) break ; o = this . heap . get ( opos ) ; if ( ! this . less ( element , o ) ) break ; cpos = opos ; c = o ; } else if ( opos < size ) { o = this . heap . get ( opos ) ; if ( ! this . less ( o , c ) ) { cpos = opos ; c = o ; } } this . heap . set ( cpos , element ) ; this . heap . set ( epos , c ) ; this . pos . set ( c , epos ) ; epos = cpos ; } this . pos . set ( element , epos ) ; }
Bubbles a given element down .