private void moveSlotBefore ( ) { /* * int slot = 0; while (slot < currentPage.getNumRecords() && * searchRange.largerThan(getKey(currentPage, slot))) slot++; * * currentSlot = slot - 1; */ // Optimization: Use binary search rather than sequential search int startSlot = 0 , endSlot = currentPage . getNumRecords ( ) - 1 ; int middleSlot = ( startSlot + endSlot ) / 2 ; SearchKey searchMin = searchRange . getMin ( ) ; if ( endSlot >= 0 ) { while ( middleSlot != startSlot ) { if ( searchMin . compareTo ( getKey ( currentPage , middleSlot , keyType . length ( ) ) ) > 0 ) startSlot = middleSlot ; else endSlot = middleSlot ; middleSlot = ( startSlot + endSlot ) / 2 ; } if ( searchMin . compareTo ( getKey ( currentPage , endSlot , keyType . length ( ) ) ) > 0 ) currentSlot = endSlot ; else if ( searchMin . compareTo ( getKey ( currentPage , startSlot , keyType . length ( ) ) ) > 0 ) currentSlot = startSlot ; else currentSlot = startSlot - 1 ; } else currentSlot = - 1 ; }
Positions the current slot right before the first index record that matches the specified search range .