Example #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);
            }
        }
Example #2
0
        public EntryInfo[] ListAllFiles()
        {
            // Get root index page from cache
            var  pageIndex = CacheIndexPage.GetPage(Header.IndexRootPageID);
            bool cont      = true;

            List <EntryInfo> list = new List <EntryInfo>();

            while (cont)
            {
                for (int i = 0; i <= pageIndex.NodeIndex; i++)
                {
                    // Convert node (if is not logicaly deleted) to Entry
                    var node = pageIndex.Nodes[i];
                    if (!node.IsDeleted)
                    {
                        list.Add(new EntryInfo(node));
                    }
                }

                // Go to the next page
                if (pageIndex.NextPageID != uint.MaxValue)
                {
                    pageIndex = CacheIndexPage.GetPage(pageIndex.NextPageID);
                }
                else
                {
                    cont = false;
                }
            }

            return(list.ToArray());
        }