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 NextNode attribute of the AVLNode object. The current node is not released. * * @return The NextNode value */ public AVLNode getNextNode() { AVLNode node; if ((node = getRightChildNode()) != null) { return node.getMinNode_R(); } node = this; while (node.childIndex == IDX_RIGHT) { if ((node = node.parentNode) == null) { return null; } } node = node.parentNode; if (node != null) { node.incRefCount(); } 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; }
/** * 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 maximum node to the right of this AVLNode (the largest node * in this subtree). The current node is not released. * * @return The node under this node containing the largest values, or * the current node if this is the largest. */ public AVLNode getMaxNode() { incRefCount(); return getMaxNode_R(); }
if (isLeafNode()) { assert leftChildNode == null; assert rightChildNode == null; } else { AVLNode node = parentNode; node.modify(); parentNode = null; node.rebalanceRemove(childIndex); node.release(); childNode = getLeftChildNode(); adjacentNode = childNode.getMaxNode_R(); ci = IDX_LEFT; } else { childNode = getRightChildNode(); adjacentNode = childNode.getMinNode_R(); ci = IDX_RIGHT; adjacentNode.modify(); adjacentNode.parentNode = parentNode; adjacentNode.leftChildNode = null; phase.setRootId(adjacentNode.getId()); } else { if (childIndex == IDX_LEFT) { parentNode.modify();
node.modify(); node.block.putByte(IDX_BALANCE_B, (byte) balance); node.incRefCount(); node.rotateL(); node.release(); node.incRefCount(); node.rotateR(); node.release();
lowAVLNode = avlFilePhase.getRootNode(objectPool); if (lowAVLNode != null) { lowAVLNode = lowAVLNode.getMinNode_R(); lowAVLNode = lowAVLNode.getNextNode_R(); findResult[0].release(); highAVLNode = highAVLNode.getNextNode(); if (highAVLNode != null) { highAVLNodeId = highAVLNode.getId(); ); highAVLNode.release(); } else { highAVLNodeId = Block.INVALID_BLOCK_ID; highAVLNodeId = highAVLNode.getId(); highAVLNodeId = findResult[1] != null ? findResult[1].getId() : Block.INVALID_BLOCK_ID;
newNode.putPayloadByte(IDX_TYPE_CATEGORY_B, (byte)typeCategory.ID); newNode.putPayloadByte(IDX_TYPE_ID_B, (byte)typeId); newNode.putPayloadByte(IDX_SUBTYPE_ID_B, (byte)subtypeId); int dataSize = data.limit(); newNode.putPayloadInt(IDX_DATA_SIZE_I, dataSize); newNode.putPayloadLong(IDX_GRAPH_NODE, gNode); newNode.write(); findResult[li].insert(newNode, 1 - li); newNode.release();
/** * 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; }
/** * 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; }
assert nodeL.parentNode == this; assert leftChildNode == nodeL; assert nodeL.getId() == getLeftId(); nodeL.modify(); modify(); block.putLong(IDX_LEFT, nodeL.block.getLong(IDX_RIGHT)); nodeL.block.putLong(IDX_RIGHT, getId()); parentNode.modify(); parentNode.block.putLong(childIndex, nodeL.getId()); } else { --refCount; nodeL.incRefCount(); int deltaHeight = calcNewBalances( block.getByte(IDX_BALANCE_B), nodeL.block.getByte(IDX_BALANCE_B), newBalances phase.setRootId(nodeL.getId());
assert nodeR.parentNode == this; assert rightChildNode == nodeR; assert nodeR.getId() == getRightId(); nodeR.modify(); modify(); block.putLong(IDX_RIGHT, nodeR.block.getLong(IDX_LEFT)); nodeR.block.putLong(IDX_LEFT, getId()); parentNode.modify(); parentNode.block.putLong(childIndex, nodeR.getId()); } else { --refCount; nodeR.incRefCount(); int deltaHeight = calcNewBalances( -block.getByte(IDX_BALANCE_B), -nodeR.block.getByte(IDX_BALANCE_B), newBalances phase.setRootId(nodeR.getId());
/** * 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; }
/** * 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; }
modify(); newNode.parentNode = this; newNode.childIndex = ci; incRefCount(); block.putLong(ci, newNode.getId()); rebalanceInsert(ci); phase.incNrNodes();
node = node.getMinNode_R(); int typeCategoryId = node.getPayloadByte(IDX_TYPE_CATEGORY_B); if (typeCategoryId == SPObject.TypeCategory.TCID_FREE) { throw new AssertionError("Found free node"); int typeId = node.getPayloadByte(IDX_TYPE_ID_B); if (typeCategoryId == prevTypeCategoryId && typeId < prevTypeId) { throw new AssertionError( ); int subtypeId = node.getPayloadByte(IDX_SUBTYPE_ID_B); int dataSize = node.getPayloadInt(IDX_DATA_SIZE_I); long blockId = node.getPayloadLong(IDX_BLOCK_ID); long graphNode = node.getPayloadLong(IDX_GRAPH_NODE); } while ((node = node.getNextNode_R()) != null); objectPool.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; }
/** * 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; }