Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Tries to combine this bucket with its buddy. Done when
- * we would like to have two buckets with the same contents for
- * <insert reason here>
- *
- * @throws IOException
- */
- private void combine() throws IOException {
- if (!this.canCombine()) {
- return; //not an exception?
- }
- Bucket buddy = this.index.loadBucket(this.findBuddy());
- index.setBucketAddr(this.findBuddy(), this.bucketAddr);
- //decrease depth of both buckets for <insert reason here>
- this.depth--;
- buddy.depth--;
- int[] combinedKeys = new int[this.maxNumKeys];
- for (int i=0; i< this.numKeys; i++){
- combinedKeys[keysSaved] = this.keys[i];
- }
- for (int i=0; i <buddy.numKeys; i++){
- combinedKeys[keysSaved] = buddy.keys[i];
- }
- //reset buckets and point both objects to combined contents
- this.numKeys = 0;
- buddy.numKeys = 0;
- this.keys = new int[this.maxNumKeys];
- buddy.keys = new int[this.maxNumKeys];
- this.storeData(this.index.getFilePointer());
- buddy.storeData(this.index.getFilePointer());
- for (int i = 0; i < combinedKeys.length; i++) {
- this.index.insert(combinedKeys[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement