public long deleteAndCheckRangeEmpty ( long key , long min , long max ) { LLIndexPage pageKey = locatePageForKeyUnique ( key , false ) ; int posKey = pageKey . binarySearchUnique ( 0 , pageKey . nEntries , key ) ; //We assume that the key exists. Otherwise we get an exception anyway in the remove-method. //-> no such calculation: posKey = -(posKey+1); //First we cover the most frequent cases, which are also fastest to check. long [ ] keys = pageKey . getKeys ( ) ; if ( posKey > 0 ) { if ( keys [ posKey - 1 ] >= min ) { return pageKey . remove ( key ) ; } if ( posKey < pageKey . nEntries - 1 ) { if ( keys [ posKey + 1 ] <= max ) { return pageKey . remove ( key ) ; } //we are in the middle of the page surrounded by values outside the range ind . file . reportFreePage ( BitTools . getPage ( key ) ) ; return pageKey . remove ( key ) ; } } else if ( posKey == 0 && pageKey . nEntries > 1 ) { if ( keys [ posKey + 1 ] <= max ) { return pageKey . remove ( key ) ; } } //brute force: long pos = pageKey . remove ( key ) ; LLEntryIterator iter = ind . iterator ( min , max ) ; if ( ! iter . hasNextULL ( ) ) { ind . file . reportFreePage ( BitTools . getPage ( key ) ) ; } iter . close ( ) ; return pos ; // //If we get here, the key is on the border of the page and we need to search more. // //If we get here, we also know that there are no values from the range on the page. // // LLIndexPage pageMin = locatePageForKeyUnique(min, false); // if (pageKey != pageMin) { //// System.out.println("X6"); // return pageKey.remove(key); // } // LLIndexPage pageMax = locatePageForKeyUnique(max, false); // if (pageKey != pageMax) { //// System.out.println("X7"); // return pageKey.remove(key); // } // // //Now we know that there are no range-keys on other pages either. We can remove the page. // // System.out.println("X8"); // fsm.reportFreePage(BitTools.getPage(key)); // return pageKey.remove(key); }
Special method to remove entries . When removing the entry it checks whether other entries in the given range exist . If none exist the value is returned as free page to FSM .