private SplitNode leftMost( SplitNode node ){ while( true ){ if( node.getMaxChildrenCount() > 0 ){ node = node.getChild( 0 ); } else{ return node; } } }
private SplitNode rightMost( SplitNode node ){ while( true ){ int max = node.getMaxChildrenCount(); if( max > 0 ){ node = node.getChild( max-1 ); } else{ return node; } } }
/** * Counts the total number of children of this node, the total number of children is the total * number of nodes and leafs in the tree below this node, excluding this node. * @return the total number of children, can be 0 */ public int getTotalChildrenCount(){ int max = getMaxChildrenCount(); int sum = 0; for( int i = 0; i < max; i++ ){ SplitNode node = getChild( i ); if( node != null ){ sum += 1 + node.getTotalChildrenCount(); } } return sum; }
/** * Searches and returns the first {@link SplitNode} which contains <code>placeholder</code>. * @param placeholder the placeholder to search * @return the node containing <code>placeholder</code> or <code>null</code> */ public SplitNode getPlaceholderNode( Path placeholder ){ if( hasPlaceholder( placeholder )){ return this; } for( int i = 0, n = getMaxChildrenCount(); i<n; i++ ){ SplitNode child = getChild( i ); if( child != null ){ SplitNode result = child.getPlaceholderNode( placeholder ); if( result != null ){ return result; } } } return null; }
private int ensureIdUnique( long[] ids, int offset ){ idChecked = true; int delta = 0; ids[offset] = getId(); offset++; for( int i = 0, n = getMaxChildrenCount(); i<n; i++ ){ SplitNode child = getChild( i ); if( child != null ){ delta += child.ensureIdUnique( ids, offset + delta ); } } boolean issue = true; while( issue ){ issue = false; long id = getId(); for( int i = 0; i < delta; i++ ){ if( ids[offset+i] == id ){ this.id = access.uniqueID(); issue = true; break; } } } return delta + 1; }