Exemplo n.º 1
0
        private static void ReadEdgeKeyIndices(BinaryReader reader, TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(reader != null);
            Contract.Requires(tinkerGrapĥ != null);

            // Read the number of edge key indices
            var indexCount = reader.ReadInt32();

            for (var i = 0; i < indexCount; i++)
            {
                // Read the key index name
                var indexName = reader.ReadString();

                tinkerGrapĥ.EdgeKeyIndex.CreateKeyIndex(indexName);

                var items = new ConcurrentDictionary <object, ConcurrentDictionary <string, IElement> >();

                // Read the number of items associated with this key index name
                var itemCount = reader.ReadInt32();
                for (var j = 0; j < itemCount; j++)
                {
                    // Read the item key
                    var key = ReadTypedData(reader);

                    var edges = new ConcurrentDictionary <string, IElement>();

                    // Read the number of edges in this item
                    var edgeCount = reader.ReadInt32();
                    for (var k = 0; k < edgeCount; k++)
                    {
                        // Read the edge identifier
                        var e = tinkerGrapĥ.GetEdge(ReadTypedData(reader));
                        if (e != null)
                        {
                            edges.TryAdd(e.Id.ToString(), e);
                        }
                    }

                    items.Put(key, edges);
                }

                tinkerGrapĥ.EdgeKeyIndex.Index.Put(indexName, items);
            }
        }
Exemplo n.º 2
0
        private static void ReadIndices(BinaryReader reader, TinkerGrapĥ tinkerGrapĥ)
        {
            Contract.Requires(reader != null);
            Contract.Requires(tinkerGrapĥ != null);

            // Read the number of indices
            var indexCount = reader.ReadInt32();

            for (var i = 0; i < indexCount; i++)
            {
                // Read the index name
                var indexName = reader.ReadString();

                // Read the index type
                var indexType = reader.ReadByte();

                if (indexType != 1 && indexType != 2)
                {
                    throw new InvalidDataException("Unknown index class type");
                }

                var tinkerIndex = new TinkerIndex(indexName, indexType == 1 ? typeof(IVertex) : typeof(IEdge));

                // Read the number of items associated with this index name
                var indexItemCount = reader.ReadInt32();
                for (var j = 0; j < indexItemCount; j++)
                {
                    // Read the item key
                    var indexItemKey = reader.ReadString();

                    // Read the number of sub-items associated with this item
                    var indexValueItemSetCount = reader.ReadInt32();
                    for (var k = 0; k < indexValueItemSetCount; k++)
                    {
                        // Read the number of vertices or edges in this sub-item
                        var setCount = reader.ReadInt32();
                        for (var l = 0; l < setCount; l++)
                        {
                            // Read the vertex or edge identifier
                            if (indexType == 1)
                            {
                                var v = tinkerGrapĥ.GetVertex(ReadTypedData(reader));
                                if (v != null)
                                {
                                    tinkerIndex.Put(indexItemKey, v.GetProperty(indexItemKey), v);
                                }
                            }
                            else if (indexType == 2)
                            {
                                var e = tinkerGrapĥ.GetEdge(ReadTypedData(reader));
                                if (e != null)
                                {
                                    tinkerIndex.Put(indexItemKey, e.GetProperty(indexItemKey), e);
                                }
                            }
                        }
                    }
                }

                tinkerGrapĥ.Indices.Put(indexName, tinkerIndex);
            }
        }