public MGRB Copy() { if (_containers.Count() > 0) { var o = Serialize(); var m = new MGRB(); m.Deserialize(o); return(m); } return(new MGRB()); }
internal void SavePageList(SafeSortedList <T, PageInfo> _pages, List <int> diskpages) { lock (_fileLock) { T[] keys = _pages.Keys(); int blocknum = 0; // TODO : needed?? //if (_externalStrings) //{ // if (_pagelistalllocblock != null) // _strings.FreeBlocks(_pagelistalllocblock); // blocknum = _strings.SaveData("pagelist", BJSON.ToBJSON(keys, // new BJSONParameters { UseUnicodeStrings = false, UseTypedArrays = false })); // File.WriteAllBytes(_FileName + ".pagelist", Helper.GetBytes(blocknum, false)); //} // save page list int c = (_pages.Count() / Global.PageItemCount) + 1; // allocate pages needed while (c > diskpages.Count) { diskpages.Add(GetNewPageNumber()); } byte[] page = new byte[_PageLength]; for (int i = 0; i < (diskpages.Count - 1); i++) { byte[] block = CreateBlockHeader(1, Global.PageItemCount, diskpages[i + 1]); Buffer.BlockCopy(block, 0, page, 0, block.Length); for (int j = 0; j < Global.PageItemCount; j++) { CreatePageListData(_pages, i * Global.PageItemCount, block.Length, j, page, blocknum); } SeekPage(diskpages[i]); _file.Write(page, 0, page.Length); } c = _pages.Count() % Global.PageItemCount; byte[] lastblock = CreateBlockHeader(1, (ushort)c, -1); Buffer.BlockCopy(lastblock, 0, page, 0, lastblock.Length); int lastoffset = (_pages.Count() / Global.PageItemCount) * Global.PageItemCount; for (int j = 0; j < c; j++) { CreatePageListData(_pages, lastoffset, lastblock.Length, j, page, blocknum); } SeekPage(diskpages[diskpages.Count - 1]); _file.Write(page, 0, page.Length); } }
public MGIndex(string path, string filename, byte keysize, bool allowdups) { if (Global.UseLessMemoryStructures) { _cache = new SafeSortedList <int, Page <T> >(); } else { _cache = new SafeDictionary <int, Page <T> >(); } _AllowDuplicates = allowdups; if (path.EndsWith(Path.DirectorySeparatorChar.ToString()) == false) { path += Path.DirectorySeparatorChar; } _index = new IndexFile <T>(path + filename, keysize); // load page list _index.GetPageList(_pageListDiskPages, _pageList, out _LastIndexedRecordNumber); if (_pageList.Count() == 0) { Page <T> page = new Page <T>(); page.FirstKey = (T)RDBDataType <T> .GetEmpty(); page.DiskPageNumber = _index.GetNewPageNumber(); page.isDirty = true; _pageList.Add(page.FirstKey, new PageInfo(page.DiskPageNumber, 0, 0)); _cache.Add(page.DiskPageNumber, page); } }