Exemplo n.º 1
0
        public BPlusTreeNodeStorage(IPageManager pageManager, ISerializer <TKey> keySerializer, int maxKeySize)
        {
            if (maxKeySize <= 0)
            {
                throw new ArgumentException("ComparableComparableKeyOf size should be positive", nameof(maxKeySize));
            }

            _pageManager        = pageManager ?? throw new ArgumentNullException(nameof(pageManager));
            _keySerializer      = keySerializer ?? throw new ArgumentNullException(nameof(keySerializer));
            _maxKeySize         = maxKeySize;
            _nodeEntrySizeRange = DbItem.GetSizeRange(_maxKeySize + DbItemReference.BytesLength);

            if (NodeCapacity <= 2)
            {
                throw new ArgumentException("Too large key size", nameof(maxKeySize));
            }

            _dbItems = new DbItem[NodeCapacity];
            var bytes = new byte[_maxKeySize + DbItemReference.BytesLength];

            for (int i = 0; i < NodeCapacity; i++)
            {
                _dbItems[i] = new DbItem(bytes);
            }

            _pageCacheEnabled = _pageManager is ICachingPageManager;
        }
        protected override void Init()
        {
            base.Init();

            //add access-method page
            IPage amPage = PageManager.CreatePage();

            Debug.Assert(amPage.Index == 2, "The first access method page should have index 2");

            var tnph = new BPlusTreeNodePageHeader
            {
                ParentPageIndex   = -1,
                PreviousPageIndex = -1,
                NextPageIndex     = -1,
                IsLeaf            = true,
                SizeRange         = DbItem.GetSizeRange(_maxKeySize + sizeof(Int64) + sizeof(Int16))
            };

            PageFormatter.InitPage(amPage, tnph);
            PageManager.UpdatePage(amPage);
        }