Exemple #1
0
        public static List <byte[]> ReadVariableSizeItems(IPage page)
        {
            PageType pageType = PageHeaderBase.GetPageType(page);

            if (pageType != PageType.RadixTree)
            {
                throw new PageFormatException("Page is not dedicated to variable size items.");
            }

            short headerLength = BitConverter.ToInt16(page.Content, OnPageOffsets.HeaderLength);

            var result = new List <byte[]>();

            var lengthMarkers = ReadMarkers(page, headerLength);

            int offset = 0;

            foreach (var length in lengthMarkers)
            {
                offset += Math.Abs(length);

                var bytes = new byte[length];
                Buffer.BlockCopy(page.Content, page.Content.Length - offset, bytes, 0, length);

                result.Add(bytes);
            }

            return(result);
        }
Exemple #2
0
        public static ushort GetFreeSpace(IPage page)
        {
            PageType pageType = PageHeaderBase.GetPageType(page);

            if (pageType != PageType.RadixTree)
            {
                throw new PageFormatException("Page is not dedicated to variable size items.");
            }

            return(RadixTreeNodesPageHeader.ReadFreeSpace(page));
        }
Exemple #3
0
        public static short ReadItemMarkersLength(IPage page)
        {
            PageType pageType = PageHeaderBase.GetPageType(page);

            if (pageType != PageType.RadixTree)
            {
                throw new PageFormatException("Page is not dedicated to variable size items.");
            }

            short headerLength = BitConverter.ToInt16(page.Content, OnPageOffsets.HeaderLength);

            return(BitConverter.ToInt16(page.Content, headerLength));
        }
Exemple #4
0
        public static byte[] ReadVariableSizeItem(IPage page, short itemIndex)
        {
            PageType pageType = PageHeaderBase.GetPageType(page);

            if (pageType != PageType.RadixTree)
            {
                throw new PageFormatException("Page is not dedicated to variable size items.");
            }


            short headerLength = BitConverter.ToInt16(page.Content, OnPageOffsets.HeaderLength);

            var lengthMarkers = ReadMarkers(page, headerLength);

            if (itemIndex >= lengthMarkers.Length)
            {
                throw new PageFormatException("Wrong item index.");
            }

            int offset = 0;
            int length = 0;

            for (int i = 0; i <= itemIndex; i++)
            {
                length  = lengthMarkers[i];
                offset += Math.Abs(length);
            }

            if (length <= 0)
            {
                throw new PageFormatException("Item has been deleted.");
            }

            var result = new byte[length];

            Buffer.BlockCopy(page.Content, page.Content.Length - offset, result, 0, length);

            return(result);
        }
        public static PageHeaderBase GetPageHeader(IPage page)
        {
            PageHeaderBase ph;
            PageType       pt = PageHeaderBase.GetPageType(page);

            switch (pt)
            {
            case PageType.FreeSpaceMap:
                ph = new FreeSpaceMapPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.Heading:
                ph = new HeadingPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.MultipageItem:
                ph = new MultipageItemPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.FixedSizeItem:
                ph = new FixedSizeItemsPageHeader();
                ph.Read(page);
                return(ph);

            case PageType.BPlusTree:
                ph = new BPlusTreeNodePageHeader();
                ph.Read(page);
                return(ph);

            case PageType.RadixTree:
                ph = new RadixTreeNodesPageHeader();
                ph.Read(page);
                return(ph);
            }
            return(null);
        }