private static void ReadVertexKeyIndices(BinaryReader reader, TinkerGrapĥ tinkerGrapĥ) { Contract.Requires(reader != null); Contract.Requires(tinkerGrapĥ != null); // Read the number of vertex key indices var indexCount = reader.ReadInt32(); for (var i = 0; i < indexCount; i++) { // Read the key index name var indexName = reader.ReadString(); tinkerGrapĥ.VertexKeyIndex.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 vertices = new ConcurrentDictionary <string, IElement>(); // Read the number of vertices in this item var vertexCount = reader.ReadInt32(); for (var k = 0; k < vertexCount; k++) { // Read the vertex identifier var v = tinkerGrapĥ.GetVertex(ReadTypedData(reader)); if (v != null) { vertices.TryAdd(v.Id.ToString(), v); } } items.Put(key, vertices); } tinkerGrapĥ.VertexKeyIndex.Index.Put(indexName, items); } }
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); } }