/** * Writes a string representation of this tree structure into a * {@link java.lang.StringBuffer}. * * @param sb The string buffer to write to. */ private void toString(StringBuffer sb) { sb.append(getId()); sb.append(" ["); AVLNode tmp; if ((tmp = getLeftChildNode()) == null) { sb.append("-"); } else { tmp.toString(sb); } sb.append(", "); if ((tmp = getRightChildNode()) == null) { sb.append("-"); } else { tmp.toString(sb); } sb.append("]"); }
/** * Insert the first AVLNode in the tree. * * @param newNode The node to become the only node in the tree. * @throws IOException If an I/O error occurred. */ public void insertFirst(AVLNode newNode) throws IOException { if (!isEmpty()) { throw new IllegalStateException( "insertFirst() called on AVL tree that is not empty"); } // Tree is empty. Set the root. setRootId(newNode.getId()); incNrNodes(); }
if (lowAVLNode != null && lowAVLNode.getId() == highAVLNodeId) {
/** * Returns the left child node or null if there is no left child node. The * current node is released if and only if there is a left child node. * * @return the left child node or null if there is no left child node. */ private AVLNode getLeftChildNode_N() { AVLNode node = leftChildNode; if (node != null) { assert refCount > 1; assert node.parentNode == this; assert node.getId() == getLeftId(); node.incRefCount(); --refCount; return node; } assert refCount > 0; node = getChildNode_N(IDX_LEFT); leftChildNode = node; return node; }
/** * Returns the right child node or null if there is no right child node. The * current node is released if and only if there is a right child node. * * @return the right child node or null if there is no right child node. */ private AVLNode getRightChildNode_N() { AVLNode node = rightChildNode; if (node != null) { assert refCount > 1; assert node.parentNode == this; assert node.getId() == getRightId(); node.incRefCount(); --refCount; return node; } assert refCount > 0; node = getChildNode_N(IDX_RIGHT); rightChildNode = node; return node; }
public long getRowCount() throws TuplesException { if (!nrGNodesValid) { assert lowAVLNode != null; AVLNode n = lowAVLNode; n.incRefCount(); long count = 0; while ( n != null && ( highAVLNodeId == Block.INVALID_BLOCK_ID || n.getId() != highAVLNodeId ) ) { ++count; n = n.getNextNode_R(); } if (n != null) { n.release(); } nrGNodes = count; nrGNodesValid = true; } return nrGNodes; }
block.putLong(ci, newNode.getId()); rebalanceInsert(ci); phase.incNrNodes();
count < 2 && n != null && ( highAVLNodeId == Block.INVALID_BLOCK_ID || n.getId() != highAVLNodeId
/** * Returns the right child node or null if there is no right child node. The * current node is not released. * * @return the right child node or null if there is no right child node. */ public AVLNode getRightChildNode() { assert refCount > 0; AVLNode node = rightChildNode; if (node != null) { assert node.parentNode == this; assert node.getId() == getRightId(); node.incRefCount(); return node; } node = getChildNode_N(IDX_RIGHT); rightChildNode = node; if (node != null) { incRefCount(); } return node; }
/** * Returns the left child node or null if there is no left child node. The * current node is not released. * * @return the left child node or null if there is no left child node. */ public AVLNode getLeftChildNode() { assert refCount > 0; AVLNode node = leftChildNode; if (node != null) { assert node.parentNode == this; assert node.getId() == getLeftId(); node.incRefCount(); return node; } node = getChildNode_N(IDX_LEFT); leftChildNode = node; if (node != null) { incRefCount(); } return node; }
/** * Gets the Height attribute of the AVLNode object * * @return The Height value */ public int getHeight() { AVLNode lChildNode = getLeftChildNode(); int leftHeight = (lChildNode != null) ? lChildNode.getHeight() : 0; if (lChildNode != null) { lChildNode.release(); } AVLNode rChildNode = getRightChildNode(); int rightHeight = (rChildNode != null) ? rChildNode.getHeight() : 0; if (rChildNode != null) { rChildNode.release(); } // Check the balance value. int balance = leftHeight - rightHeight; if (balance != block.getByte(IDX_BALANCE_B)) { throw new RuntimeException( "Incorrect balance for node " + getId() + ". Expected: " + balance + " but was: " + block.getByte(IDX_BALANCE_B) ); } return Math.max(leftHeight, rightHeight) + 1; }
avlNode.getId() == highAVLNodeId ) { avlNode.release();
highAVLNodeId = findResult[1] != null ? findResult[1].getId() : Block.INVALID_BLOCK_ID; AVLFile.release(findResult);