public override void VisitRange(BTreeVisitor <TKey> visitor)
        {
            int nextResult = visitor(_records[0].Key, null);

            int idx = 0;

            while (idx < _records.Length)
            {
                int thisResult = nextResult;

                if (idx + 1 < _records.Length)
                {
                    nextResult = visitor(_records[idx + 1].Key, null);
                }
                else
                {
                    nextResult = 1;
                }

                if (thisResult > 0)
                {
                    // This record's key is too big, so no chance further records
                    // will match.
                    return;
                }
                else if (nextResult >= 0)
                {
                    // Next record's key isn't too small, so worth looking at children
                    BTreeKeyedNode <TKey> child = ((BTree <TKey>)Tree).GetKeyedNode(_records[idx].ChildId);
                    child.VisitRange(visitor);
                }

                idx++;
            }
        }
Пример #2
0
        internal BTreeKeyedNode <TKey> GetKeyedNode(uint nodeId)
        {
            byte[] nodeData = StreamUtilities.ReadExact(this.data, (int)nodeId * this.header.NodeSize, this.header.NodeSize);

            BTreeKeyedNode <TKey> node = BTreeNode.ReadNode <TKey>(this, nodeData, 0) as BTreeKeyedNode <TKey>;

            node.ReadFrom(nodeData, 0);
            return(node);
        }
Пример #3
0
        internal BTreeKeyedNode <TKey> GetKeyedNode(uint nodeId)
        {
            byte[] nodeData = Utilities.ReadFully(_data, (int)nodeId * _header.NodeSize, _header.NodeSize);

            BTreeKeyedNode <TKey> node = BTreeNode.ReadNode <TKey>(this, nodeData, 0) as BTreeKeyedNode <TKey>;

            node.ReadFrom(nodeData, 0);
            return(node);
        }
Пример #4
0
        public BTree(IBuffer data)
        {
            this.data = data;

            byte[] headerInfo = StreamUtilities.ReadExact(this.data, 0, 114);

            this.header = new BTreeHeaderRecord();
            this.header.ReadFrom(headerInfo, 14);

            byte[] node0data = StreamUtilities.ReadExact(this.data, 0, this.header.NodeSize);

            BTreeHeaderNode node0 = BTreeNode.ReadNode(this, node0data, 0) as BTreeHeaderNode;

            node0.ReadFrom(node0data, 0);

            if (node0.HeaderRecord.RootNode != 0)
            {
                this.rootNode = this.GetKeyedNode(node0.HeaderRecord.RootNode);
            }
        }
Пример #5
0
        public BTree(IBuffer data)
        {
            _data = data;

            byte[] headerInfo = Utilities.ReadFully(_data, 0, 114);

            _header = new BTreeHeaderRecord();
            _header.ReadFrom(headerInfo, 14);

            byte[] node0data = Utilities.ReadFully(_data, 0, _header.NodeSize);

            BTreeHeaderNode node0 = BTreeNode.ReadNode(this, node0data, 0) as BTreeHeaderNode;

            node0.ReadFrom(node0data, 0);

            if (node0.HeaderRecord.RootNode != 0)
            {
                _rootNode = GetKeyedNode(node0.HeaderRecord.RootNode);
            }
        }
Пример #6
0
        public override byte[] FindKey(TKey key)
        {
            int nextResult = this.records[0].Key.CompareTo(key);

            int idx = 0;

            while (idx < this.records.Length)
            {
                int thisResult = nextResult;

                if (idx + 1 < this.records.Length)
                {
                    nextResult = this.records[idx + 1].Key.CompareTo(key);
                }
                else
                {
                    nextResult = 1;
                }

                if (thisResult > 0)
                {
                    // This record's key is too big, so no chance further records
                    // will match.
                    return(null);
                }

                if (nextResult > 0)
                {
                    // Next record's key is too big, so worth looking at children
                    BTreeKeyedNode <TKey> child = ((BTree <TKey>) this.Tree).GetKeyedNode(this.records[idx].ChildId);
                    return(child.FindKey(key));
                }

                idx++;
            }

            return(null);
        }