/// <summary> /// Allocates and returns the initial node page. /// </summary> public void Init(int initialPageSize) { // 0th slot: Index 0 is reserved to mean "null node". Only use 0th slot to store PageInfo. _pageSize = initialPageSize; _page = new XPathNode[_pageSize]; _pageInfo = new XPathNodePageInfo(null, 1); _page[0].Create(_pageInfo); }
/// <summary> /// Allocate the next slot in the current node page. Return a reference to the page and the index /// of the allocated slot. /// </summary> public void AllocateSlot(out XPathNode[] page, out int idx) { page = _page; idx = _pageInfo.NodeCount; // Allocate new page if necessary if (++_pageInfo.NodeCount >= _page.Length) { if (_pageSize < (1 << 16)) { // New page shouldn't contain more slots than 16 bits can address _pageSize *= 2; } _page = new XPathNode[_pageSize]; _pageInfo.NextPage = _page; _pageInfo = new XPathNodePageInfo(page, _pageInfo.PageNumber + 1); _page[0].Create(_pageInfo); } }