/** * Set the value at a give position * * @param pos The position in the values array * @param value the value to inject */ /* no qualifier */void setValue( int pos, Page<K, V> value ) { children[pos] = new PageHolder<K, V>( btree, value ); }
/** * {@inheritDoc} */ /* no qualifier */Page<K, V> getPage( int pos ) { if ( ( pos >= 0 ) && ( pos < children.length ) ) { if ( children[pos] != null ) { return children[pos].getValue(); } else { return null; } } else { return null; } }
Page<K, V> siblingChild = sibling.children[sibling.nbElems].getValue(); newNode.children[0] = new PageHolder<K, V>( btree, siblingChild ); //1 newNode.children[1] = new PageHolder<K, V>( btree, modifiedPage ); System.arraycopy( children, 2, newNode.children, 2, nbElems - 1 ); newNode.setKey( 0, new KeyHolder<K>( children[0].getValue().getLeftMostKey() ) ); //2 newNode.children[index] = new PageHolder<K, V>( btree, modifiedPage ); // 7
K siblingKey = sibling.children[0].getValue().getLeftMostKey(); newNode.children[0] = new PageHolder<K, V>( btree, modifiedPage ); newNode.children[index - 1] = new PageHolder<K, V>( btree, modifiedPage ); // 6
/** * {@inheritDoc} */ /* no qualifier */Page<K, V> getReference( int pos ) throws IOException { if ( pos < nbElems + 1 ) { if ( children[pos] != null ) { return children[pos].getValue(); } else { return null; } } else { return null; } }
/** * Creates a new Node which will contain only one key, with references to * a left and right page. This is a specific constructor used by the btree * when the root was full when we added a new value. * * @param btree the parent BTree * @param revision the Node revision * @param key The new key * @param leftPage The left page * @param rightPage The right page */ @SuppressWarnings("unchecked") InMemoryNode( BTree<K, V> btree, long revision, K key, Page<K, V> leftPage, Page<K, V> rightPage ) { super( btree, revision, 1 ); // Create the children array, and store the left and right children children = ( PageHolder[] ) Array.newInstance( PageHolder.class, btree.getPageSize() + 1 ); children[0] = new PageHolder<K, V>( btree, leftPage ); children[1] = new PageHolder<K, V>( btree, rightPage ); // Create the keys array and store the pivot into it // We get the type of array to create from the btree // Yes, this is an hack... setKeys( ( KeyHolder<K>[] ) Array.newInstance( KeyHolder.class, btree.getPageSize() ) ); setKey( 0, new KeyHolder<K>( key ) ); }
newNode.children[half + 1] = new PageHolder<K, V>( btree, modifiedPage ); System.arraycopy( children, 2, newNode.children, half + 2, half - 1 ); newNode.setKey( half, new KeyHolder<K>( children[0].getValue().getLeftMostKey() ) ); // 3 newNode.children[half + index] = new PageHolder<K, V>( btree, modifiedPage ); //8 newNode.children[0] = new PageHolder<K, V>( btree, modifiedPage ); newNode.children[index - 1] = new PageHolder<K, V>( btree, modifiedPage ); // 7
/** * {@inheritDoc} */ public Tuple<K, V> findRightMost() throws EndOfFileExceededException, IOException { return children[nbElems].getValue().findRightMost(); }
/** * Set the page at a give position * * @param btree The B-tree to update * @param page The page to update * @param pos The position in the values array * @param child the child page to inject */ /* no qualifier*/static <K, V> void setPage( BTree<K, V> btree, Page<K, V> page, int pos, Page<K, V> child ) { if ( btree.getType() != BTreeTypeEnum.IN_MEMORY ) { ( ( PersistedNode<K, V> ) page ).setValue( pos, new PersistedPageHolder<K, V>( btree, child ) ); } else { ( ( InMemoryNode<K, V> ) page ).setPageHolder( pos, new PageHolder<K, V>( btree, child ) ); } }
/** * {@inheritDoc} */ public K getLeftMostKey() { return children[0].getValue().getLeftMostKey(); }
newNode.children[pos] = new PageHolder<K, V>( btree, leftPage ); newNode.children[pos + 1] = new PageHolder<K, V>( btree, rightPage );
/** * {@inheritDoc} */ public K getLeftMostKey() { return children[0].getValue().getLeftMostKey(); }
/** * This method is used when we have to replace a child in a page when we have * found the key in the tree (the value will be changed, so we have made * copies of the existing pages). * * @param revision The current revision * @param result The modified page * @param pos The position of the found key * @return A modified page * @throws IOException If we have an error while trying to access the page */ private InsertResult<K, V> replaceChild( long revision, ModifyResult<K, V> result, int pos ) throws IOException { // Just copy the current page and update its revision Page<K, V> newPage = copy( revision ); // Last, we update the children table of the newly created page // to point on the modified child Page<K, V> modifiedPage = result.getModifiedPage(); ( ( InMemoryNode<K, V> ) newPage ).children[pos] = new PageHolder<K, V>( btree, modifiedPage ); // We can return the result, where we update the modifiedPage, // to avoid the creation of a new object result.setModifiedPage( newPage ); result.addCopiedPage( this ); return result; }
/** * {@inheritDoc} */ public Tuple<K, V> findLeftMost() throws EndOfFileExceededException, IOException { return children[0].getValue().findLeftMost(); }
newPage.children[index + 1] = new PageHolder<K, V>( btree, modifiedPage ); newPage.children[index] = new PageHolder<K, V>( btree, modifiedPage );
newLeftPage.children[pos] = new PageHolder<K, V>( btree, leftPage ); newLeftPage.children[pos + 1] = new PageHolder<K, V>( btree, rightPage ); newLeftPage.children[middle] = new PageHolder<K, V>( btree, leftPage ); newRightPage.children[0] = new PageHolder<K, V>( btree, rightPage ); newRightPage.children[pos - middle - 1] = new PageHolder<K, V>( btree, leftPage ); newRightPage.children[pos - middle] = new PageHolder<K, V>( btree, rightPage );
node.setPageHolder( i, new PageHolder<K, V>( btree, p ) );
/** * {@inheritDoc} */ public String dumpPage( String tabs ) { StringBuilder sb = new StringBuilder(); if ( nbElems > 0 ) { // Start with the first child sb.append( children[0].getValue().dumpPage( tabs + " " ) ); for ( int i = 0; i < nbElems; i++ ) { sb.append( tabs ); sb.append( "<" ); sb.append( getKey( i ) ).append( ">\n" ); sb.append( children[i + 1].getValue().dumpPage( tabs + " " ) ); } } return sb.toString(); }