/// <summary> /// Creates a new tree node in storage. /// </summary> /// <param name="isLeaf">Value indicating whether a created node is leaf node</param> /// <returns>Created node</returns> public IBPlusTreeNode <TKey> Create(bool isLeaf) { IPage p = _pageManager.CreatePage(); return(new BPlusTreeNode <TKey>(p.Index) { IsLeaf = isLeaf }); }
private DbItemReference AllocateSinglePage(DbItem item) { DbItemReference result; IPage page; var fsmValue = EnumHelper.FsmValueFromSizeRange(item.SizeRange); var index = _fsm.GetFreePageIndex(fsmValue); bool spaceRemains; if (index != -1) { // place object to existing page page = _pageManager.FetchPage(index); result = PageFormatter.AddFixedSizeItem(page, item, out spaceRemains); if (!spaceRemains) { _fsm.Set(index, FsmValue.Full); } } else { // allocate on a new page page = _pageManager.CreatePage(); var header = new FixedSizeItemsPageHeader { SizeRange = item.SizeRange }; PageFormatter.InitPage(page, header); result = PageFormatter.AddFixedSizeItem(page, item, out spaceRemains); _fsm.Set(result.PageIndex, spaceRemains ? fsmValue : FsmValue.Full); } _pageManager.UpdatePage(page); return(result); }
public IRadixTreeNode Create(int prefixSize, int childCapacity) { CheckRoot(); IPage page; short itemIndex; var node = NewNode(DbItemReference.Null); foreach (var pageIndex in _recentPages) { page = _pageManager.FetchPage(pageIndex); if (page.BackingObject == null) { var obj = RadixTreePageBackingObject.FromPage(page); page = new Page(_pageManager, pageIndex, () => Serialize(obj), obj); } var backingObject = (RadixTreePageBackingObject)page.BackingObject; itemIndex = AddNode(backingObject, node, prefixSize, childCapacity); if (itemIndex != -1) { UpdateRecentPage(page.Index); node.Reference = new DbItemReference(page.Index, itemIndex); _pageManager.UpdatePage(page); return(node); } } page = _pageManager.CreatePage(); var obj1 = new RadixTreePageBackingObject(page.Index); long index1 = page.Index; page = new Page(_pageManager, index1, () => Serialize(obj1), obj1); itemIndex = AddNode((RadixTreePageBackingObject)page.BackingObject, node, prefixSize, childCapacity); if (itemIndex != -1) { UpdateRecentPage(page.Index); node.Reference = new DbItemReference(page.Index, itemIndex); _pageManager.UpdatePage(page); return(node); } Debug.Fail("Should never get here"); return(null); }
/// <summary> /// Creates a new page in storage. /// </summary> /// <returns>Created page</returns> public IPage CreatePage() { CheckDisposed(); Lock(); try { IPage page = _underlyingPageManager.CreatePage(); AddPage(page); return(GetPage(page.Index)); } finally { Unlock(); } }
public void Set(long pageIndex, FsmValue value) { if (!_isInitialized) { Init(); } IPage page = GetFsmPageByTargetPageIndex(pageIndex); if (page == null) { // fsm-page is missing for requested page index long previousPageIndex = _lastFsmPage.Index; var missingPageCount = (int)((pageIndex - (_fsmPageCount - _fsmPageIndexes.Count) * _entryPerPage) / _entryPerPage + 1); var pages = new List <IPage>(missingPageCount); // allocate new pages for (int i = 0; i < missingPageCount; i++) { pages.Add(_pageManager.CreatePage()); } var baseIndex = PageFormatter.GetBasePageIndex(_lastFsmPage); // initialize them for (int i = 0; i < missingPageCount; i++) { baseIndex += _entryPerPage; InitFsmPage(pages[i], previousPageIndex, i == missingPageCount - 1 ? -1 : pages[i + 1].Index, baseIndex); previousPageIndex = pages[i].Index; } // and update pages.ForEach(_pageManager.UpdatePage); // save reference to added pages var lastPageHeader = (FreeSpaceMapPageHeader)PageFormatter.GetPageHeader(_lastFsmPage); lastPageHeader.NextPageIndex = pages[0].Index; lastPageHeader.WriteToPage(_lastFsmPage); _pageManager.UpdatePage(_lastFsmPage); _lastFsmPage = null; _fsmPageCount = -1; Set(pageIndex, value); } else { PageFormatter.SetFsmValue(page, (int)pageIndex % _entryPerPage, value); _pageManager.UpdatePage(page); var fsmValuesToUpdate = _luckyFsmPages.Where(item => item.Value.Page.Index == page.Index).Select(item => item.Key).ToList(); foreach (var fsmValue in fsmValuesToUpdate) { _luckyFsmPages[fsmValue].Page = page; } if (!_luckyFsmPages.ContainsKey(value)) { _luckyFsmPages[value] = new LuckyPage { Page = page, LastGoodIndex = pageIndex } } ; else { if (_scanned.Contains(value)) { _scanned.Remove(value); } } } }