⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btreefileheaderuos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* BtreeFileHeaderUos.java
 * ---------------------------------------------
 * Copyright (c) 2001 University of Saskatchewan
 * All Rights Reserved
 * --------------------------------------------- */

package dslib.file;

import java.io.Serializable;

/** This class holds data about a Btree that is necessary
    to restore a Btree that was saved to disk. */
public class BtreeFileHeaderUos implements Serializable
{ 
    /** The name of the node file. */
    protected String nodeFileName;
    
    /** The first free address associated with the node file. */
    protected long firstFreeNodeAddress;

    /** The next address for the node file. */
    protected long nextNodeAddress;

    /** The size of nodes in the node file. */
    protected int nodeSize;

    /** The first free address associated with the data file. */
    protected long firstFreeDataAddress;

    /** The size of the blocks. */   
    protected int blockSize;
    
    /** The next address for the data file. */
    protected long nextAddress;

    /** The order of the Btree. */
    protected int BtreeOrder;

    /** Is the btree empty?. */
    protected boolean treeEmpty;
    
    /** The address of the root. */
    protected long rootAddress;
    
    /** Is the root a leaf?. */
    protected boolean rootIsALeaf;

    /** Make a file header based upon the argument. <br> 
        Analysis : Time = O(1) 
        @param tree The tree from which this header will extract information */
    public BtreeFileHeaderUos(BtreeFileUos tree) 
    {
        /* Obtain info about the node file */
        if (tree.nodeFile() != null)
        {
            nodeFileName = tree.nodeFile().name;
            firstFreeNodeAddress = tree.nodeFile().lastReturnedAddress; 
            nodeSize = tree.nodeFile().nodeSize;
            nextNodeAddress = tree.nodeFile().nextAddress;
        }

        /* Obtain info about the data file */
        if (tree.dataFile() != null) 
        { 
            firstFreeDataAddress = tree.dataFile().lastReturnedAddress;
            blockSize = tree.dataFile().blockSize;
            nextAddress = tree.dataFile().nextAddress;
        }

        /* Obtain info from the tree  */
        BtreeOrder = tree.order();
        treeEmpty = tree.isEmpty();       
        if (!treeEmpty) 
        {
            rootAddress = tree.rootNode.fileAddress;
            rootIsALeaf = (tree.rootNode instanceof BtreeLeafUos);
        }
    }

    /** Access function for nodeFileName. 
        Analysis: Time = O(1) */
    public String nodeFileName()
    {
        return nodeFileName;
    }
       
    /** Return a string representation of the header. 
        Analysis : Time = O(1) */
    public String toString()
    {
        String result = "\nNode file name : " + nodeFileName 
                        + "\nRoot's address : " + rootAddress 
                        + "\nOrder : "+ BtreeOrder;

        if (treeEmpty)
            result += "\nThe tree is empty";
        else if (rootIsALeaf)
            result += "\nThe root is a leaf";

        result += "\nNext Block Address : " + nextAddress 
                + "\nBlock size : " + blockSize
                + "\nNode size : " + nodeSize
                + "\nFirst free data address : " + firstFreeDataAddress
                + "\nFirst free node address : " + firstFreeNodeAddress;
        return result;
    }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -