Пример #1
0
        public extentsOverflowLeafNode.extentsOverflowLeafRecord getExtentRecordWithKey(HFSPlusExtentKey recordKeyID)
        {
            extentsOverflowLeafNode.extentsOverflowLeafRecord result;

            byte[] nodeRawData       = new byte[this.nodeSize];
            uint   currentNodeNumber = this.header.headerInfo.rootNode;

            absNode.nodeType currentNodeType = getNodeType(currentNodeNumber);

            // until a leaf node is found
            while (currentNodeType != absNode.nodeType.leaf)
            {
                fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin);
                fs.Read(nodeRawData, 0, this.nodeSize);

                extentsOverflowIndexNode currentNode = new extentsOverflowIndexNode(ref nodeRawData);
                extentsOverflowIndexNode.extentsOverflowIndexRecord perhapsThisRecord = currentNode.records[0];

                // finds the subtree that contains the desired record and follows it
                foreach (extentsOverflowIndexNode.extentsOverflowIndexRecord record in currentNode.records)
                {
                    bool equalsSearch   = extentsOverflowKeyCompare(record.extentKey, recordKeyID) == dataOperations.keyCompareResult.equalsTrialKey;
                    bool lessThanSearch = extentsOverflowKeyCompare(record.extentKey, recordKeyID) == dataOperations.keyCompareResult.greaterThanTrialKey;
                    bool greaterThanOrEqualToBestKnown = extentsOverflowKeyCompare(record.extentKey, perhapsThisRecord.extentKey) == dataOperations.keyCompareResult.lessThanTrialKey ||
                                                         extentsOverflowKeyCompare(record.extentKey, perhapsThisRecord.extentKey) == dataOperations.keyCompareResult.equalsTrialKey;


                    if (lessThanSearch && greaterThanOrEqualToBestKnown || equalsSearch)
                    {
                        perhapsThisRecord = record;
                    }
                }

                currentNodeNumber = perhapsThisRecord.pointer;
                currentNodeType   = (absNode.nodeType)getNodeType(currentNodeNumber);
            }

            // once the leaf node is found, compile the data from it and return that node
            fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin);
            fs.Read(nodeRawData, 0, this.nodeSize);

            extentsOverflowLeafNode leafNode = new extentsOverflowLeafNode(ref nodeRawData);

            foreach (extentsOverflowLeafNode.extentsOverflowLeafRecord leafRecord in leafNode.records)
            {
                if (dataOperations.keyCompareResult.equalsTrialKey == extentsOverflowKeyCompare(leafRecord.key, recordKeyID))
                {
                    result = leafRecord;
                    return(result);
                }
            }

            throw new Exception("The specified search key was not found.");
        }
        public extentsOverflowLeafNode.extentsOverflowLeafRecord getExtentRecordWithKey(HFSPlusExtentKey recordKeyID)
        {
            extentsOverflowLeafNode.extentsOverflowLeafRecord result;

            byte[] nodeRawData = new byte[this.nodeSize];
            uint currentNodeNumber = this.header.headerInfo.rootNode;

            absNode.nodeType currentNodeType = getNodeType(currentNodeNumber);

            // until a leaf node is found
            while (currentNodeType != absNode.nodeType.leaf)
            {
                fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin);
                fs.Read(nodeRawData, 0, this.nodeSize);

                extentsOverflowIndexNode currentNode = new extentsOverflowIndexNode(ref nodeRawData);
                extentsOverflowIndexNode.extentsOverflowIndexRecord perhapsThisRecord = currentNode.records[0];

                // finds the subtree that contains the desired record and follows it
                foreach (extentsOverflowIndexNode.extentsOverflowIndexRecord record in currentNode.records)
                {
                    bool equalsSearch = extentsOverflowKeyCompare(record.extentKey, recordKeyID) == dataOperations.keyCompareResult.equalsTrialKey;
                    bool lessThanSearch = extentsOverflowKeyCompare(record.extentKey, recordKeyID) == dataOperations.keyCompareResult.greaterThanTrialKey;
                    bool greaterThanOrEqualToBestKnown = extentsOverflowKeyCompare(record.extentKey, perhapsThisRecord.extentKey) == dataOperations.keyCompareResult.lessThanTrialKey
                        || extentsOverflowKeyCompare(record.extentKey, perhapsThisRecord.extentKey) == dataOperations.keyCompareResult.equalsTrialKey;

                    if (lessThanSearch && greaterThanOrEqualToBestKnown || equalsSearch)
                    {
                        perhapsThisRecord = record;
                    }
                }

                currentNodeNumber = perhapsThisRecord.pointer;
                currentNodeType = (absNode.nodeType)getNodeType(currentNodeNumber);
            }

            // once the leaf node is found, compile the data from it and return that node
            fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin);
            fs.Read(nodeRawData, 0, this.nodeSize);

            extentsOverflowLeafNode leafNode = new extentsOverflowLeafNode(ref nodeRawData);

            foreach (extentsOverflowLeafNode.extentsOverflowLeafRecord leafRecord in leafNode.records)
            {
                if (dataOperations.keyCompareResult.equalsTrialKey == extentsOverflowKeyCompare(leafRecord.key, recordKeyID))
                {
                    result = leafRecord;
                    return result;
                }
            }

            throw new Exception("The specified search key was not found.");
        }