コード例 #1
0
        public WTree(IHeap heap)
        {
            if (heap == null)
            {
                throw new NullReferenceException("heap");
            }

            Heap = heap;

            if (Heap.Exists(0))
            {
                //create root branch with fictive type and handle.
                RootBranch = new Branch(this, NodeType.Leaf, 1);

                //read settings & root cache (always at handle 0).
                byte[] buffer = Heap.Read(0);
                using (MemoryStream ms = new MemoryStream(buffer))
                {
                    Settings.Deserialize(this, ms);
                    RootBranch.Cache.Load(this, new BinaryReader(ms));
                }
            }
            else
            {
                long headerHandle = Heap.ObtainHandle();
                if (headerHandle != 0)
                {
                    throw new Exception("Logical Error.");
                }

                RootBranch = new Branch(this, NodeType.Leaf);
            }

            CacheThread = new Thread(DoCache);
            CacheThread.Start();
        }
コード例 #2
0
ファイル: WTree.cs プロジェクト: ropean/STSdb-4.0.1-src
        public WTree(IHeap heap)
        {
            if (heap == null)
            {
                throw new NullReferenceException("heap");
            }

            Heap = heap;

            if (Heap.Exists(HANDLE_SETTINGS))
            {
                //create root branch with dummy handle
                RootBranch = new Branch(this, NodeType.Leaf, 0);

                //read settings - settings will set the RootBranch.NodeHandle
                using (MemoryStream ms = new MemoryStream(Heap.Read(HANDLE_SETTINGS)))
                    Settings.Deserialize(this, ms);

                //read scheme
                using (MemoryStream ms = new MemoryStream(Heap.Read(HANDLE_SCHEME)))
                    scheme = Scheme.Deserialize(new BinaryReader(ms));

                ////load branch cache
                //using (MemoryStream ms = new MemoryStream(Heap.Read(HANDLE_ROOT)))
                //    RootBranch.Cache.Load(this, new BinaryReader(ms));
                isRootCacheLoaded = false;
            }
            else
            {
                //obtain reserved handles
                var handle = Heap.ObtainHandle();
                if (handle != HANDLE_SETTINGS)
                {
                    throw new Exception("Logical error.");
                }

                scheme = new WaterfallTree.Scheme();
                handle = Heap.ObtainHandle();
                if (handle != HANDLE_SCHEME)
                {
                    throw new Exception("Logical error.");
                }

                handle = Heap.ObtainHandle();
                if (handle != HANDLE_ROOT)
                {
                    throw new Exception("Logical error.");
                }

                handle = Heap.ObtainHandle();
                if (handle != HANDLE_RESERVED)
                {
                    throw new Exception("Logical error.");
                }

                RootBranch = new Branch(this, NodeType.Leaf); //the constructor will invoke Heap.ObtainHandle()

                isRootCacheLoaded = true;
            }

            CacheThread = new Thread(DoCache);
            CacheThread.Start();
        }