Пример #1
0
            public void Load(WTree tree, BinaryReader reader)
            {
                int count = (int)CountCompression.Deserialize(reader);

                Capacity = count;

                NodeType nodeType = (NodeType)reader.ReadByte();

                for (int i = 0; i < count; i++)
                {
                    //read fullKey
                    var locator = tree.DeserializeLocator(reader);
                    var key     = locator.KeyPersist.Read(reader);
                    var fullKey = new FullKey(locator, key);

                    //read branch info
                    long      nodeID    = reader.ReadInt64();
                    NodeState nodeState = (NodeState)reader.ReadInt32();

                    Branch branch = new Branch(tree, nodeType, nodeID);
                    branch.NodeState = nodeState;

                    branch.Cache.Load(tree, reader);

                    Add(new KeyValuePair <FullKey, Branch>(fullKey, branch));
                }
            }
Пример #2
0
            public void Store(WTree tree, BinaryWriter writer)
            {
                CountCompression.Serialize(writer, checked ((ulong)Count));

                Debug.Assert(Count > 0);
                writer.Write((byte)this[0].Value.NodeType);

                for (int i = 0; i < Count; i++)
                {
                    var     kv      = this[i];
                    FullKey fullkey = kv.Key;
                    Branch  branch  = kv.Value;
                    //lock (branch)
                    //{
                    //}

                    //write locator
                    tree.SerializeLocator(writer, fullkey.Locator);
                    fullkey.Locator.KeyPersist.Write(writer, fullkey.Key);

                    //write branch info
                    writer.Write(branch.NodeHandle);
                    writer.Write((int)branch.NodeState);

                    branch.Cache.Store(tree, writer);
                }
            }
Пример #3
0
            public static void Deserialize(WTree tree, Stream stream)
            {
                BinaryReader reader  = new BinaryReader(stream);
                int          version = reader.ReadInt32();

                switch (version)
                {
                case 0:
                {
                    tree.GlobalVersion         = reader.ReadInt64();
                    tree.RootBranch.NodeHandle = reader.ReadInt64();
                    tree.RootBranch.NodeType   = (NodeType)reader.ReadByte();
                    tree.Depth = reader.ReadInt32();
                    tree.INTERNAL_NODE_MAX_OPERATIONS_IN_ROOT = reader.ReadInt32();
                    tree.INTERNAL_NODE_MIN_BRANCHES           = reader.ReadInt32();
                    tree.INTERNAL_NODE_MAX_BRANCHES           = reader.ReadInt32();
                    tree.INTERNAL_NODE_MIN_OPERATIONS         = reader.ReadInt32();
                    tree.INTERNAL_NODE_MAX_OPERATIONS         = reader.ReadInt32();
                }
                break;

                case 1:     //from 4.0.3
                {
                    tree.GlobalVersion         = reader.ReadInt64();
                    tree.RootBranch.NodeHandle = reader.ReadInt64();
                    tree.RootBranch.NodeType   = (NodeType)reader.ReadByte();
                    tree.Depth = reader.ReadInt32();

                    tree.INTERNAL_NODE_MIN_BRANCHES           = reader.ReadInt32();
                    tree.INTERNAL_NODE_MAX_BRANCHES           = reader.ReadInt32();
                    tree.INTERNAL_NODE_MAX_OPERATIONS_IN_ROOT = reader.ReadInt32();
                    tree.INTERNAL_NODE_MIN_OPERATIONS         = reader.ReadInt32();
                    tree.INTERNAL_NODE_MAX_OPERATIONS         = reader.ReadInt32();
                    tree.LEAF_NODE_MIN_RECORDS = reader.ReadInt32();
                    tree.LEAF_NODE_MAX_RECORDS = reader.ReadInt32();
                }
                break;

                default:
                    throw new NotSupportedException("Unknown WTree header version.");
                }
            }
Пример #4
0
            public void Load(WTree tree, BinaryReader reader)
            {
                int count = reader.ReadInt32();

                if (count == 0)
                {
                    return;
                }

                for (int i = 0; i < count; i++)
                {
                    //read locator
                    var locator = tree.DeserializeLocator(reader);

                    //read operations
                    var operations = locator.OperationsPersist.Read(reader);

                    Add(locator, operations);
                }
            }
Пример #5
0
            public static void Serialize(WTree tree, Stream stream)
            {
                BinaryWriter writer = new BinaryWriter(stream);

                const int VERSION = 1;

                writer.Write(VERSION);

                switch (VERSION)
                {
                //case 0:
                //    {
                //        writer.Write(tree.GlobalVersion);
                //        writer.Write(tree.RootBranch.NodeHandle);
                //        writer.Write((byte)tree.RootBranch.NodeType);
                //        writer.Write(tree.Depth);
                //        writer.Write(tree.INTERNAL_NODE_MAX_OPERATIONS_IN_ROOT);
                //        writer.Write(tree.INTERNAL_NODE_MIN_BRANCHES);
                //        writer.Write(tree.INTERNAL_NODE_MAX_BRANCHES);
                //        writer.Write(tree.INTERNAL_NODE_MIN_OPERATIONS);
                //        writer.Write(tree.INTERNAL_NODE_MAX_OPERATIONS);
                //    }
                //    break;
                case 1:
                {
                    writer.Write(tree.GlobalVersion);
                    writer.Write(tree.RootBranch.NodeHandle);
                    writer.Write((byte)tree.RootBranch.NodeType);
                    writer.Write(tree.Depth);

                    writer.Write(tree.INTERNAL_NODE_MIN_BRANCHES);
                    writer.Write(tree.INTERNAL_NODE_MAX_BRANCHES);
                    writer.Write(tree.INTERNAL_NODE_MAX_OPERATIONS_IN_ROOT);
                    writer.Write(tree.INTERNAL_NODE_MIN_OPERATIONS);
                    writer.Write(tree.INTERNAL_NODE_MAX_OPERATIONS);
                    writer.Write(tree.LEAF_NODE_MIN_RECORDS);
                    writer.Write(tree.LEAF_NODE_MAX_RECORDS);
                }
                break;
                }
            }
Пример #6
0
            public void Store(WTree tree, BinaryWriter writer)
            {
                writer.Write(Count);
                if (Count == 0)
                {
                    return;
                }

                //write cache
                foreach (var kv in this)
                {
                    var locator    = kv.Key;
                    var operations = kv.Value;

                    //write locator
                    tree.SerializeLocator(writer, locator);

                    //write operations
                    locator.OperationsPersist.Write(writer, operations);
                }
            }
Пример #7
0
 /// <summary>
 /// on brand new branch
 /// </summary>
 public Branch(WTree tree, NodeType nodeType)
     : this(tree, nodeType, tree.heap.ObtainNewHandle())
 {
     node = WTree.Node.Create(this);
 }
Пример #8
0
 /// <summary>
 /// on load
 /// </summary>
 public Branch(WTree tree, NodeType nodeType, long nodeHandle)
 {
     Tree       = tree;
     NodeType   = nodeType;
     NodeHandle = nodeHandle;
 }