コード例 #1
0
ファイル: BTreeDir.java プロジェクト: anushb/simpleDB
 /**
  * Creates a new root block for the B-tree. The new root will have two children: the old root, and
  * the specified block. Since the root must always be in block 0 of the file, the contents of the
  * old root will get transferred to a new block.
  *
  * @param e the directory entry to be added as a child of the new root
  */
 public void makeNewRoot(DirEntry e) {
   Constant firstval = contents.getDataVal(0);
   int level = contents.getFlag();
   Block newblk = contents.split(0, level); // ie, transfer all the records
   DirEntry oldroot = new DirEntry(firstval, newblk.number());
   insertEntry(oldroot);
   insertEntry(e);
   contents.setFlag(level + 1);
 }
コード例 #2
0
ファイル: BTreeDir.java プロジェクト: anushb/simpleDB
 private DirEntry insertEntry(DirEntry e) {
   int newslot = 1 + contents.findSlotBefore(e.dataVal());
   contents.insertDir(newslot, e.dataVal(), e.blockNumber());
   if (!contents.isFull()) return null;
   // else page is full, so split it
   int level = contents.getFlag();
   int splitpos = contents.getNumRecs() / 2;
   Constant splitval = contents.getDataVal(splitpos);
   Block newblk = contents.split(splitpos, level);
   return new DirEntry(splitval, newblk.number());
 }
コード例 #3
0
ファイル: BTreeDir.java プロジェクト: anushb/simpleDB
 private Block findChildBlock(Constant searchkey) {
   int slot = contents.findSlotBefore(searchkey);
   if (contents.getDataVal(slot + 1).equals(searchkey)) slot++;
   int blknum = contents.getChildNum(slot);
   return new Block(filename, blknum);
 }