コード例 #1
0
        public IndexPage GetFreeIndexPage()
        {
            var freeIndexPage = CacheIndexPage.GetPage(Header.FreeIndexPageID);

            // Check if "free page" has no more index to be used
            if (freeIndexPage.NodeIndex >= IndexPage.NODES_PER_PAGE - 1)
            {
                Header.LastPageID++; // Take last page and increase
                Header.IsDirty = true;

                var newIndexPage = new IndexPage(Header.LastPageID); // Create a new index page
                freeIndexPage.NextPageID = newIndexPage.PageID;      // Point older page to the new page
                Header.FreeIndexPageID   = Header.LastPageID;        // Update last index page

                CacheIndexPage.AddPage(freeIndexPage, true);

                return(newIndexPage);
            }
            else
            {
                // Has more free index on same index page? return them
                freeIndexPage.NodeIndex++; // Reserve space
                return(freeIndexPage);
            }
        }
コード例 #2
0
        public bool Delete(Guid id)
        {
            // Search index node from guid
            var indexNode = Search(id);

            // If null, not found (return false)
            if (indexNode == null)
            {
                return(false);
            }

            // Delete the index node logicaly
            indexNode.IsDeleted = true;

            // Add page (from index node) to cache and set as dirty
            CacheIndexPage.AddPage(indexNode.IndexPage, true);

            // Mark all data blocks (from data pages) as IsEmpty = true
            DataFactory.MarkAsEmpty(indexNode.DataPageID, this);

            // Set header as Dirty to be saved on dispose
            Header.IsDirty = true;

            return(true); // Confirma a exclusão
        }