public BTree(int t, long root, Func <IFile, IFile, int> comparer, StreamManager manager) { this.t = t; this.manager = manager; this.comparer = comparer; this.root = manager.DiskRead(root); }
public void Open(Stream db) { if (open) { throw new InvalidOperationException("Debe CERRAR el stream antes de poder abrirlo de nuevo"); } if (!db.CanRead) { var q = new FileStream("test.txt", FileMode.Open); manager = new StreamManager(t, q); open = true; if (q.Length == 0) { path = new BTree(t, comparer[0], manager); path.manager.OpenStream(); date = new BTree(t, comparer[1], manager); date.manager.OpenStream(); size = new BTree(t, comparer[2], manager); size.manager.OpenStream(); } else { var trees = manager.LoadBTrees(); path = trees.item1; path.manager.OpenStream(); date = trees.item2; date.manager.OpenStream(); size = trees.item3; size.manager.OpenStream(); } } else { manager = new StreamManager(t, db); open = true; if (db.Length == 0) { path = new BTree(t, comparer[0], manager); path.manager.OpenStream(); date = new BTree(t, comparer[1], manager); date.manager.OpenStream(); size = new BTree(t, comparer[2], manager); size.manager.OpenStream(); } else { var trees = manager.LoadBTrees(); path = trees.item1; path.manager.OpenStream(); date = trees.item2; date.manager.OpenStream(); size = trees.item3; size.manager.OpenStream(); } } }
public BTree(int t, Func <IFile, IFile, int> comparer, StreamManager manager) { this.t = t; manager.OpenStream(); this.manager = manager; this.comparer = comparer; root = AllocateNode(); root.leaf = true; manager.UpdateRoot(root.offset, Array.IndexOf(MyFinder.comparer, comparer)); manager.DiskWrite(root); }