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()); }
/** * Inserts a new directory entry into the B-tree block. If the block is at level 0, then the entry * is inserted there. Otherwise, the entry is inserted into the appropriate child node, and the * return value is examined. A non-null return value indicates that the child node split, and so * the returned entry is inserted into this block. If this block splits, then the method similarly * returns the entry information of the new block to its caller; otherwise, the method returns * null. * * @param e the directory entry to be inserted * @return the directory entry of the newly-split block, if one exists; otherwise, null */ public DirEntry insert(DirEntry e) { if (contents.getFlag() == 0) return insertEntry(e); Block childblk = findChildBlock(e.dataVal()); BTreeDir child = new BTreeDir(childblk, ti, tx); DirEntry myentry = child.insert(e); child.close(); return (myentry != null) ? insertEntry(myentry) : null; }