/** * Releases the nodes returned from a find when a result was not found. * * @param avlNodes A two element array of AVLNodes. One or the other may be null. */ public static void release(AVLNode[] avlNodes) { if (avlNodes[0] != null) { avlNodes[0].release(); avlNodes[0] = null; } if ( (avlNodes.length == 2) && (avlNodes[1] != null)) { avlNodes[1].release(); avlNodes[1] = null; } }
/** * Gets the ParentNode attribute of the AVLNode object and releases the current node. * @deprecated * * @return The ParentNode value */ public AVLNode getParentNode_R() { AVLNode node = getParentNode(); release(); return node; }
/** * Gets the NextNode attribute of the AVLNode object. The current node is released. * * @return The NextNode_R value */ public AVLNode getNextNode_R() { AVLNode node = getNextNode(); release(); return node; }
/** * Returns the left child node or null if there is no left child node. The * current node is released. * * @return the left child node or null if there is no left child node. */ public AVLNode getLeftChildNode_R() { AVLNode node = getLeftChildNode_N(); if (node == null) { release(); } return node; }
/** * Gets the PrevNode attribute of the AVLNode object. The current node is released. * * @return The PrevNode_R value */ public AVLNode getPrevNode_R() { AVLNode node = getPrevNode(); release(); return node; }
/** * Returns the right child node or null if there is no right child node. The * current node is released. * * @return the right child node or null if there is no right child node. */ public AVLNode getRightChildNode_R() { AVLNode node = getRightChildNode_N(); if (node == null) { release(); } return node; }
/** * Frees all resources from this node, and releases its reference. * This should be the last reference to the node. * * @throws IOException If an I/O error occurs. */ private void free() throws IOException { writable = false; dirty = false; block.free(); block = null; release(); }
public void beforeFirst( long[] prefix, int suffixTruncation ) throws TuplesException { assert prefix != null; if (prefix.length > 1) { throw new TuplesException( "prefix.length (" + prefix.length + ") > nrColumns (1)" ); } if (suffixTruncation != 0) { throw new TuplesException("suffixTruncation not supported"); } beforeFirst = true; onPrefixNode = false; this.prefix = prefix; if (avlNode != null) { avlNode.release(); avlNode = null; } }
/** * Finds an AVLNode containing the requested data. * * @param objectPool The pool to get the AVLNodes from. * @param comparator The means of comparing the key to the payload in the AVLNodes. * @param key The data to search for. * @return An array of nodes. If the tree is empty, then <code>null</code>. * If the data exists, then a single element array containing the required node. * If the data does not exist then return the pair of nodes that the data exists between. */ public AVLNode[] find( ObjectPool objectPool, AVLComparator comparator, long[] key ) { AVLNode rootNode = getRootNode(objectPool); if (rootNode == null) return null; try { return AVLNode.findDown(rootNode, comparator, key); } finally { rootNode.release(); } }
/** * The rotate which is performed when the node is heavy on the left * sub-branch. * * @return the change in height of the node. * @throws IOException If an I/O error occurs. */ private int rotateL() throws IOException { AVLNode nodeL = getLeftChildNode(); int deltaHeight = (nodeL.block.getByte(IDX_BALANCE_B) >= 0) ? rotateLL(nodeL) : rotateLR(nodeL); nodeL.release(); return deltaHeight; }
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; }
/** * 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; }
/** * The rotate which is performed when the node is heavy on the right * sub-branch. * * @return the change in height of the node. * @throws IOException If an I/O error occurs. */ private int rotateR() throws IOException { AVLNode nodeR = getRightChildNode(); int deltaHeight = (nodeR.block.getByte(IDX_BALANCE_B) <= 0) ? rotateRR(nodeR) : rotateRL(nodeR); nodeR.release(); return deltaHeight; }
/** * The rotate which is performed when the node is heavy on the left child's * right sub-branch. * * @param nodeL a reference to the left child. * @return the change in height of the node. * @throws IOException If an I/O error occurs. */ private int rotateLR(AVLNode nodeL) throws IOException { // First perform rotateRR on nodeL. AVLNode nodeLR = nodeL.getRightChildNode(); int deltaHeightL = nodeL.rotateRR(nodeLR); // Adjust the balance of this node. if (deltaHeightL != 0) { modify(); block.putByte( IDX_BALANCE_B, (byte)(block.getByte(IDX_BALANCE_B) + deltaHeightL) ); } // Finally do a rotateLL on this node. int deltaHeight = deltaHeightL + rotateLL(nodeLR); nodeLR.release(); return deltaHeight; }
/** * The rotate which is performed when the node is heavy on the right child's * left sub-branch. * * @param nodeR a reference to the right child. * @return the change in height of the node. * @throws IOException If an I/O error occurs. */ private int rotateRL(AVLNode nodeR) throws IOException { // First perform rotateLL on nodeR. AVLNode nodeRL = nodeR.getLeftChildNode(); int deltaHeightR = nodeR.rotateLL(nodeRL); // Adjust the balance of this node. if (deltaHeightR != 0) { modify(); block.putByte( IDX_BALANCE_B, (byte)(block.getByte(IDX_BALANCE_B) - deltaHeightR) ); } // Finally do a rotateRR on this node. int deltaHeight = deltaHeightR + rotateRR(nodeRL); nodeRL.release(); return deltaHeight; }
avlNode.getId() == highAVLNodeId ) { avlNode.release(); avlNode = null;