Advertisement
Guest User

condensed contents

a guest
Mar 8th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. /**
  2.  * Tries to combine this bucket with its buddy.  Done when
  3.  * we would like to have two buckets with the same contents for
  4.  * <insert reason here>
  5.  *
  6.  * @throws IOException
  7.  */
  8. private void combine() throws IOException {
  9.         if (!this.canCombine()) {
  10.             return; //not an exception?
  11.         }
  12.        
  13.         Bucket buddy = this.index.loadBucket(this.findBuddy());
  14.        
  15.         index.setBucketAddr(this.findBuddy(), this.bucketAddr);
  16.        
  17.         //decrease depth of both buckets for <insert reason here>
  18.         this.depth--;
  19.         buddy.depth--;
  20.        
  21.         int[] combinedKeys = new int[this.maxNumKeys];
  22.        
  23.         for (int i=0; i< this.numKeys; i++){
  24.             combinedKeys[keysSaved] = this.keys[i];
  25.         }
  26.         for (int i=0; i <buddy.numKeys; i++){
  27.             combinedKeys[keysSaved] = buddy.keys[i];
  28.         }
  29.        
  30.         //reset buckets and point both objects to combined contents
  31.         this.numKeys = 0;
  32.         buddy.numKeys = 0;
  33.         this.keys = new int[this.maxNumKeys];
  34.         buddy.keys = new int[this.maxNumKeys];
  35.        
  36.         this.storeData(this.index.getFilePointer());
  37.         buddy.storeData(this.index.getFilePointer());
  38.        
  39.         for (int i = 0; i < combinedKeys.length; i++) {
  40.             this.index.insert(combinedKeys[i]);
  41.         }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement