コード例 #1
0
ファイル: BtreeIndexDuplicate.cs プロジェクト: xhute/Kooboo
        private void reloadStartRecordPointer(Int64 sectionStartPointer)
        {
            Int64 position = 0;

            for (int i = 0; i < this.maxJumpTableLevel; i++)
            {
                position = sectionStartPointer + i * sectionlen + 46;  //46 is the start 46 bytes for counter, etc.
                byte[] nextpointer = new byte[8];

                lock (_object)
                {
                    IndexStream.Position = position + 11;   //warning, 11 is the next pointer position, it might change.
                    IndexStream.Read(nextpointer, 0, 8);
                }

                if (BitConverter.ToInt64(nextpointer, 0) > 0)
                {
                    break;
                }
            }

            lock (_object)
            {
                IndexStream.Position = sectionStartPointer + this.startRecordPointerPositionIndex;
                IndexStream.Write(BitConverter.GetBytes(position), 0, 8);
            }
        }
コード例 #2
0
ファイル: BtreeIndexDuplicate.cs プロジェクト: xhute/Kooboo
        private void updateNavigator(Int64 recorddiskposition, Int64 PointerDiskPosition, enumPosition position)
        {
            int relativeposition = 0;

            switch (position)
            {
            case enumPosition.next:
                relativeposition = 11;
                break;

            case enumPosition.previous:
                relativeposition = 3;
                break;

            case enumPosition.top:
                relativeposition = 19;
                break;

            case enumPosition.bottom:
                relativeposition = 27;
                break;

            default:
                relativeposition = 11;
                break;
            }

            lock (_object)
            {
                IndexStream.Position = recorddiskposition + relativeposition;
                IndexStream.Write(BitConverter.GetBytes(PointerDiskPosition), 0, 8);
            }
        }
コード例 #3
0
        private JumpRecord insertNewRecord(Int64 blockposition)
        {
            JumpRecord record = new JumpRecord();

            record.BlockPosition = blockposition;

            record.Indicator = enumSectionType.Record;

            Int64 insertposition = getInsertPosition();

            IndexStream.Position = insertposition;
            IndexStream.Write(record.ToBytes(), 0, sectionlen);

            record.diskLocation = insertposition;
            return(record);
        }
コード例 #4
0
ファイル: BtreeIndexDuplicate.cs プロジェクト: xhute/Kooboo
        private Int64 createNewStartSection()
        {
            /// in the format of
            /// [8] start search pointer. Pointer to the highest jump table.
            /// [2] * = number of counter of each level.  start pointer =

            // header section + number levels.
            int totallen = sectionlen + this.maxJumpTableLevel * sectionlen;

            byte[] totalbytes = new byte[totallen];

            byte[] header = new byte[sectionlen];

            header[0] = startbyteone;
            header[1] = startbytetwo;

            header[44] = startbyteone;
            header[45] = startbytetwo;

            header[2] = (byte)enumSectionType.StartSection;

            List <JumpRecord> tablelist = new List <JumpRecord>();

            for (int i = 0; i < this.maxJumpTableLevel; i++)
            {
                JumpRecord newrecord = new JumpRecord();
                newrecord.BlockPosition = Int64.MinValue;
                newrecord.Indicator     = enumSectionType.Record;
                newrecord.level         = (byte)i;

                tablelist.Add(newrecord);
            }

            for (int i = 0; i < tablelist.Count; i++)
            {
                if (i == 0)
                {
                    updateNavigator(tablelist[i].diskLocation, tablelist[i + 1].diskLocation, enumPosition.next);
                }
                else if (i == tablelist.Count - 1)
                {
                    updateNavigator(tablelist[i].diskLocation, tablelist[i - 1].diskLocation, enumPosition.previous);
                }
                else
                {
                    // in the middle.
                    updateNavigator(tablelist[i].diskLocation, tablelist[i - 1].diskLocation, enumPosition.previous);
                    updateNavigator(tablelist[i].diskLocation, tablelist[i + 1].diskLocation, enumPosition.next);
                }
            }


            Int64 writeposition = getInsertPosition();

            //write position for each start of level table.
            for (int i = 0; i < tablelist.Count; i++)
            {
                tablelist[i].diskLocation = writeposition + 46 + i * 46;
            }

            Int64 lastitemindex = tablelist[tablelist.Count - 1].diskLocation;

            System.Buffer.BlockCopy(BitConverter.GetBytes(lastitemindex), 0, header, 3, 8);

            lock (_object)
            {
                IndexStream.Position = writeposition;
                IndexStream.Write(header, 0, sectionlen);

                foreach (var item in tablelist)
                {
                    IndexStream.Position = item.diskLocation;
                    IndexStream.Write(item.ToBytes(), 0, sectionlen);
                }
            }

            return(writeposition);
        }