/** * {@inheritDoc} */ public DeleteResult<K, V> delete( K key, V value, long revision ) throws IOException { return delete( key, value, revision, null, -1 ); }
/** * {@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(); }
/** * Create a new holder storing an offset and a SoftReference containing the element. * * @param page The element to store into a SoftReference */ public PersistedPageHolder( BTree<K, V> btree, Page<K, V> page ) { // DO NOT keep the reference to Page, it will be fetched from cache when needed super( btree, null ); cache = ( ( PersistedBTree<K, V> ) btree ).getCache(); recordManager = ( ( PersistedBTree<K, V> ) btree ).getRecordManager(); offset = ( ( AbstractPage<K, V> ) page ).getOffset(); lastOffset = ( ( AbstractPage<K, V> ) page ).getLastOffset(); ( ( AbstractPage<K, V> ) page ).setOffset( offset ); ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset ); cache.put( offset, page ); }
child = ( ( AbstractPage<K, V> ) parentPos.page ).getPage( parentPos.pos ); parentPos.pos = 0; parentPos.page = child; child = ( ( AbstractPage<K, V> ) child ).getPage( 0 ); parentPos.page = child; parentPos.pos = 0; parentPos.valueCursor = ( ( AbstractPage<K, V> ) child ).getValue( 0 ).getCursor();
/** * Serialize a Node's Value. We store the two offsets of the child page. */ private <K, V> int serializeNodeValue( PersistedNode<K, V> node, int pos, List<byte[]> serializedData ) throws IOException { // For a node, we just store the children's offsets Page<K, V> child = node.getReference( pos ); // The first offset byte[] buffer = LongSerializer.serialize( ( ( AbstractPage<K, V> ) child ).getOffset() ); serializedData.add( buffer ); int dataSize = buffer.length; // The last offset buffer = LongSerializer.serialize( ( ( AbstractPage<K, V> ) child ).getLastOffset() ); serializedData.add( buffer ); dataSize += buffer.length; return dataSize; }
for ( int j = 0; j < lastNode.getNbElems(); j++ ) if ( lastNode.getKey( j ) == null ) lastNode.setNbElems( n ); KeyHolder<K>[] keys = lastNode.getKeys(); lastNode.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, n ) ); System.arraycopy( keys, 0, lastNode.getKeys(), 0, n );
/** * Change the position in the current cursor before the first key */ public void beforeFirst() throws IOException { // First check that we have elements in the BTree if ( ( stack == null ) || ( stack.length == 0 ) ) { return; } Page<K, K> child = null; for ( int i = 0; i < depth; i++ ) { ParentPos<K, K> parentPos = stack[i]; parentPos.pos = 0; if ( child != null ) { parentPos.page = child; } child = ( ( AbstractPage<K, K> ) parentPos.page ).getPage( 0 ); } // and leaf ParentPos<K, K> parentPos = stack[depth]; parentPos.pos = BEFORE_FIRST; if ( child != null ) { parentPos.page = child; } }
/** * Set the root page * @param rootPage the rootPage to set */ /* no qualifier */void setRootPage( Page<K, V> rootPage ) { this.rootPage = rootPage; this.rootPageOffset = ( ( AbstractPage<K, V> ) rootPage ).getOffset(); }
/** * {@inheritDoc} */ public TupleCursor<K, V> browse( K key, ReadTransaction<K, V> transaction, ParentPos<K, V>[] stack, int depth ) throws IOException { int pos = findPos( key ); if ( pos < 0 ) { pos = -pos; } // We first stack the current page stack[depth++] = new ParentPos<K, V>( this, pos ); Page<K, V> page = children[pos].getValue(); return page.browse( key, transaction, stack, depth ); }
for ( int j = 0; j < lastNode.getNbElems(); j++ ) if ( lastNode.getKey( j ) == null ) lastNode.setNbElems( n ); KeyHolder<K>[] keys = lastNode.getKeys(); lastNode.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, n ) ); System.arraycopy( keys, 0, lastNode.getKeys(), 0, n );
public String toString() { StringBuilder sb = new StringBuilder(); sb.append( "\n copiedPage = <" ); boolean isFirst = true; for ( Page<K, V> copiedPage : getCopiedPages() ) { if ( isFirst ) { isFirst = false; } else { sb.append( ", " ); } sb.append( ( ( AbstractPage<K, V> ) copiedPage ).getOffset() ); } sb.append( ">" ); return sb.toString(); } }
/** * {@inheritDoc} */ public V get( K key ) throws IOException, KeyNotFoundException { int pos = findPos( key ); if ( pos < 0 ) { // Here, if we have found the key in the node, then we must go down into // the right child, not the left one return children[-pos].getValue().get( key ); } else { return children[pos].getValue().get( key ); } }
child = ( ( AbstractPage<K, V> ) parentPos.page ).getPage( parentPos.pos ); parentPos.pos = child.getNbElems(); parentPos.page = child; child = ( ( AbstractPage<K, V> ) parentPos.page ).getPage( parentPos.page.getNbElems() ); parentPos.pos = child.getNbElems() - 1; parentPos.page = child; ValueHolder<V> valueHolder = ( ( AbstractPage<K, V> ) parentPos.page ).getValue( parentPos.pos ); parentPos.valueCursor = valueHolder.getCursor(); parentPos.valueCursor.afterLast();
ValueHolder<V> valueHolder = leaf.getValue( parentPos.pos ); parentPos.pos = AFTER_LAST; parentPos.valueCursor = valueHolder.getCursor(); tuple.setKey( leaf.getKey( parentPos.pos ) ); ValueHolder<V> valueHolder = leaf.getValue( parentPos.pos ); parentPos.valueCursor = valueHolder.getCursor(); V value = parentPos.valueCursor.next();