示例#1
0
        public virtual IIndex CreateIndex(string indexName, Type indexClass, params Parameter[] indexParameters)
        {
            IndexableGraphContract.ValidateCreateIndex(indexName, indexClass, indexParameters);

            if (Indices.ContainsKey(indexName))
            {
                throw ExceptionFactory.IndexAlreadyExists(indexName);
            }

            var index = new TinkerIndex(indexName, indexClass);

            Indices.Put(index.Name, index);
            return(index);
        }
示例#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);
            }
        }