@Test public void testUniqueInsert() throws Exception, IOException, MiniDBException{ BPlusTree bt = createCommonTree(true); bt.insertPair(new ArrayList<>(Arrays.asList(100, 200.0, "12")), 12L); bt.insertPair(new ArrayList<>(Arrays.asList(100, 200.0, "120")), 0L); bt.insertPair(new ArrayList<>(Arrays.asList(100, 200.0, "9")), 254L); try{ bt.insertPair(new ArrayList<>(Arrays.asList(100, 200.0, "12 ")), 13L); throw new Exception("wrong!"); }catch (MiniDBException e) { } assertSearchEqual(bt, new ArrayList<>(Arrays.asList(100, 200.0, "9")), new Long[]{254L}); assertSearchEqual(bt, new ArrayList<>(Arrays.asList(100, 200.0, "120")), new Long[]{0L}); assertSearchEqual(bt, new ArrayList<>(Arrays.asList(100, 200.0, "12")), new Long[]{12L}); assertSearchEqual(bt, new ArrayList<>(Arrays.asList(100, 200.0, "xs")), new Long[]{}); }
@SuppressWarnings("unused") public void insertPair(ArrayList<Object> key, long value) throws IOException, MiniDBException, IllegalStateException { if(root == null) {throw new IllegalStateException("Can't insert to null tree");} conf.padKey(key); if(root.isFull(conf)) { aChild = this.root; TreeInternalNode node_buf = new TreeInternalNode(TreeNode.TreeNodeType.TREE_ROOT_INTERNAL, generateFirstAvailablePageIndex(conf)); node_buf.addPointerAt(0, aChild.getPageIndex()); this.root = node_buf; splitTreeNode(node_buf, 0); writeFileHeader(conf); insertNonFull(node_buf, key, value); } else {insertNonFull(root, key, value);} }
BPlusTree { @SuppressWarnings("unused") public void insertPair(ArrayList<Object> key, long value) throws IOException, MiniDBException, IllegalStateException { if(root == null) {throw new IllegalStateException("Can't insert to null tree");} conf.padKey(key); if(root.isFull(conf)) { aChild = this.root; TreeInternalNode node_buf = new TreeInternalNode(TreeNode.TreeNodeType.TREE_ROOT_INTERNAL, generateFirstAvailablePageIndex(conf)); node_buf.addPointerAt(0, aChild.getPageIndex()); this.root = node_buf; splitTreeNode(node_buf, 0); writeFileHeader(conf); insertNonFull(node_buf, key, value); } else {insertNonFull(root, key, value);} } }
BPlusTree { @SuppressWarnings("unused") public void insertPair(ArrayList<Object> key, long value) throws IOException, MiniDBException, IllegalStateException { if(root == null) {throw new IllegalStateException("Can't insert to null tree");} conf.padKey(key); if(root.isFull(conf)) { aChild = this.root; TreeInternalNode node_buf = new TreeInternalNode(TreeNode.TreeNodeType.TREE_ROOT_INTERNAL, generateFirstAvailablePageIndex(conf)); node_buf.addPointerAt(0, aChild.getPageIndex()); this.root = node_buf; splitTreeNode(node_buf, 0); writeFileHeader(conf); insertNonFull(node_buf, key, value); } else {insertNonFull(root, key, value);} } @SuppressWarnings("unused")  BPlusTree(BPlusConfiguration conf, String mode,
                     String treeFilePath); }
BPlusTree { @SuppressWarnings("unused") public void insertPair(ArrayList<Object> key, long value) throws IOException, MiniDBException, IllegalStateException { if(root == null) {throw new IllegalStateException("Can't insert to null tree");} conf.padKey(key); if(root.isFull(conf)) { aChild = this.root; TreeInternalNode node_buf = new TreeInternalNode(TreeNode.TreeNodeType.TREE_ROOT_INTERNAL, generateFirstAvailablePageIndex(conf)); node_buf.addPointerAt(0, aChild.getPageIndex()); this.root = node_buf; splitTreeNode(node_buf, 0); writeFileHeader(conf); insertNonFull(node_buf, key, value); } else {insertNonFull(root, key, value);} } @SuppressWarnings("unused")  BPlusTree(BPlusConfiguration conf, String mode,
                     String treeFilePath); boolean isUnique(); @SuppressWarnings("unused") void insertPair(ArrayList<Object> key, long value); LinkedList<Long> rangeSearch(ArrayList<Object> minKey, ArrayList<Object> maxKey, boolean includeMin, boolean includeMax); boolean deletePair(ArrayList<Object> key, long value); boolean updatePair(ArrayList<Object> key, long value, long newValue); LinkedList<Long> search(ArrayList<Object> key); TreeNode mergeOrRedistributeTreeNodes(TreeNode mnode, TreeInternalNode parent,
                                             int parentPointerIndex, int parentKeyIndex); boolean isOverflowPage(TreeNode.TreeNodeType nt); boolean isLeaf(TreeNode.TreeNodeType nt); void commitTree(); }
BPlusTree { @SuppressWarnings("unused") public void insertPair(ArrayList<Object> key, long value) throws IOException, MiniDBException, IllegalStateException { if(root == null) {throw new IllegalStateException("Can't insert to null tree");} conf.padKey(key); if(root.isFull(conf)) { aChild = this.root; TreeInternalNode node_buf = new TreeInternalNode(TreeNode.TreeNodeType.TREE_ROOT_INTERNAL, generateFirstAvailablePageIndex(conf)); node_buf.addPointerAt(0, aChild.getPageIndex()); this.root = node_buf; splitTreeNode(node_buf, 0); writeFileHeader(conf); insertNonFull(node_buf, key, value); } else {insertNonFull(root, key, value);} } @SuppressWarnings("unused")  BPlusTree(BPlusConfiguration conf, String mode,
                     String treeFilePath); boolean isUnique(); @SuppressWarnings("unused") void insertPair(ArrayList<Object> key, long value); LinkedList<Long> rangeSearch(ArrayList<Object> minKey, ArrayList<Object> maxKey, boolean includeMin, boolean includeMax); boolean deletePair(ArrayList<Object> key, long value); boolean updatePair(ArrayList<Object> key, long value, long newValue); LinkedList<Long> search(ArrayList<Object> key); TreeNode mergeOrRedistributeTreeNodes(TreeNode mnode, TreeInternalNode parent,
                                             int parentPointerIndex, int parentKeyIndex); boolean isOverflowPage(TreeNode.TreeNodeType nt); boolean isLeaf(TreeNode.TreeNodeType nt); void commitTree(); public BPlusConfiguration conf; }