AVLNode node = avlFilePhase.getRootNode(objectPool); if (node == null) { objectPool.release();
block = phase.getAVLBlockFilePhase().readBlock(objectPool, nodeId); } catch (IOException ex) { throw new Error("IOException", ex);
lowAVLNode = avlFilePhase.getRootNode(objectPool); if (lowAVLNode != null) { lowAVLNode = lowAVLNode.getMinNode_R(); AVLNode[] findResult = avlFilePhase.find( objectPool, lowComparator, null ); findResult = avlFilePhase.find(objectPool, highComparator, null); if (findResult.length == 1) {
findResult = avlFilePhase.find(objectPool, avlComparator, null); if (findResult != null && findResult.length == 1) { gNode = findResult[0].getPayloadLong(IDX_GRAPH_NODE);
phase.setRootId(NULL_NODE); } else { AVLNode node = parentNode; phase.setRootId(adjacentNode.getId()); } else { if (childIndex == IDX_LEFT) { phase.decNrNodes(); free();
AVLNode[] findResult = avlFilePhase.find( objectPool, lowComparator, null ); findResult = avlFilePhase.find(objectPool, highComparator, null); assert findResult.length == 2; highAVLNodeId = findResult[1] != null ? findResult[1].getId() : lowAVLNode = avlFilePhase.getRootNode(objectPool); if (lowAVLNode != null) { lowAVLNode = lowAVLNode.getMinNode_R();
findResult = avlFilePhase.find(objectPool, avlComparator, null); if (findResult != null && findResult.length == 1) { throw new StringPoolException(
AVLNode newNode = avlFilePhase.newAVLNodeInstance(objectPool); newNode.putPayloadByte(IDX_TYPE_CATEGORY_B, (byte)typeCategory.ID); newNode.putPayloadByte(IDX_TYPE_ID_B, (byte)typeId); avlFilePhase.insertFirst(newNode); } else {
/** * Initialises a node on the given information. * * @param phase The phase that the node exists in. * @param objectPool The pool that the node will return to. * @throws IOException If an I/O error occurs. */ private void init( AVLFile.Phase phase, ObjectPool objectPool ) throws IOException { assert this.objectPool == null; this.phase = phase; parentNode = null; childIndex = 0; this.leftChildNode = null; this.rightChildNode = null; this.objectPool = objectPool; //X trace = new Throwable(); refCount = 1; writable = true; dirty = true; block = phase.getAVLBlockFilePhase().allocateBlock(objectPool); block.putLong(IDX_LEFT, NULL_NODE); block.putLong(IDX_RIGHT, NULL_NODE); block.putByte(IDX_BALANCE_B, (byte) 0); }
/** * Factory method for an AVLNode. * * @param phase The phase form the AVLFile. * @param objectPool The object pool to return this node to when it's finished with. * @return The new node, backed by a new block in the file. * @throws IOException If there was an I/O exception. */ public static AVLNode newInstance( AVLFile.Phase phase, ObjectPool objectPool ) throws IOException { if (!phase.isCurrent()) { throw new IllegalStateException( "Attempt to allocate a new AVL node on a read-only phase." ); } AVLNode avlNode = (AVLNode) objectPool.get(ObjectPool.TYPE_AVLNODE); if (avlNode != null) { avlNode.init(phase, objectPool); } else { avlNode = new AVLNode(phase, objectPool); } return avlNode; }
/** * 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(); } }
/** * Creates a new phase for this AVL tree. * * @throws IOException If and I/O error occurs. */ public Phase() throws IOException { if (currentPhase == null) { rootId = AVLNode.NULL_NODE; nrNodes = 0; } else { rootId = currentPhase.rootId; nrNodes = currentPhase.nrNodes; } avlBlockFilePhase = avlBlockFile.new Phase(); check(); currentPhase = this; }
/** * CONSTRUCTOR Phase TO DO * * @param b PARAMETER TO DO * @param offset PARAMETER TO DO * @throws IOException EXCEPTION TO DO */ Phase(Block b, int offset) throws IOException { avlFilePhase = avlFile.new Phase(b, offset); offset += AVLFile.Phase.RECORD_SIZE; for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFilePhases[i] = blockFiles[i].new Phase(b, offset); offset += ManagedBlockFile.Phase.RECORD_SIZE; } currentPhase = this; dirty = false; }
/** * CONSTRUCTOR Phase TO DO * * @throws IOException EXCEPTION TO DO */ Phase(Phase p) throws IOException { assert p != null; avlFilePhase = avlFile.new Phase(p.avlFilePhase); for (int i = 0; i < NR_BLOCK_FILES; ++i) { blockFilePhases[i] = blockFiles[i].new Phase( p.blockFilePhases[i] ); } currentPhase = this; dirty = true; }
/** * 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(); }
/** * Constructs a phase, copying another phase. * * @param p The phase to copy. * @throws IOException If an I/O error occurs. */ public Phase(Phase p) throws IOException { assert p != null; rootId = p.rootId; nrNodes = p.nrNodes; avlBlockFilePhase = avlBlockFile.new Phase(p.avlBlockFilePhase); check(); currentPhase = this; }
/** * Construct a phase, copy the phase data found in an existing block. * * @param b The block containing the phase data. * @param offset The offset of the phase data within the block. * @throws IOException If an I/O error occurs. */ public Phase(Block b, int offset) throws IOException { rootId = b.getLong(offset + IDX_ROOT_ID); nrNodes = b.getLong(offset + IDX_NR_NODES); avlBlockFilePhase = avlBlockFile.new Phase(b, offset + HEADER_SIZE); check(); currentPhase = this; }