/// <summary> /// Initializes a new instance of the <see cref="EdgeModel" /> class. /// </summary> /// <param name='id'> Identifier. </param> /// <param name='creationDate'> Creation date. </param> /// <param name='targetVertex'> Target vertex. </param> /// <param name='sourceVertex'> Source vertex. </param> /// <param name='properties'> Properties. </param> public EdgeModel(Int32 id, UInt32 creationDate, VertexModel targetVertex, VertexModel sourceVertex, PropertyContainer[] properties) : base(id, creationDate, properties) { TargetVertex = targetVertex; SourceVertex = sourceVertex; }
/// <summary> /// Generates the properties. /// </summary> /// <returns> The properties. </returns> /// <param name='propertySpecification'> Property specification. </param> public static PropertyContainer[] GenerateProperties( Dictionary<UInt16, PropertySpecification> propertySpecification) { PropertyContainer[] properties = null; if (propertySpecification != null) { var propCounter = 0; properties = new PropertyContainer[propertySpecification.Count]; foreach (var aPropertyDefinition in propertySpecification) { properties[propCounter] = new PropertyContainer { PropertyId = aPropertyDefinition.Key, Value = aPropertyDefinition.Value.FullQualifiedTypeName != null ? Convert.ChangeType(aPropertyDefinition.Value.Property, Type.GetType( aPropertyDefinition.Value.FullQualifiedTypeName, true, true)) : aPropertyDefinition.Value.Property }; propCounter++; } } return properties; }
/// <summary> /// Initializes a new instance of the VertexModel class. For internal usage only /// </summary> /// <param name='id'> Identifier. </param> /// <param name='creationDate'> Creation date. </param> /// <param name='modificationDate'> Modification date. </param> /// <param name='properties'> Properties. </param> /// <param name='outEdges'> Out edges. </param> /// <param name='incEdges'> Inc edges. </param> internal VertexModel(Int32 id, UInt32 creationDate, UInt32 modificationDate, PropertyContainer[] properties, List<EdgeContainer> outEdges, List<EdgeContainer> incEdges) : base(id, creationDate, properties) { _outEdges = outEdges; _inEdges = incEdges; ModificationDate = modificationDate; }
/// <summary> /// Initializes a new instance of the EdgeModel class. /// </summary> /// <param name='id'> Identifier. </param> /// <param name='creationDate'> Creation date. </param> /// <param name='modificationDate'> Modification date. </param> /// <param name='targetVertex'> Target vertex. </param> /// <param name='sourceVertex'> Source vertex. </param> /// <param name='properties'> Properties. </param> internal EdgeModel(Int32 id, UInt32 creationDate, UInt32 modificationDate, VertexModel targetVertex, VertexModel sourceVertex, PropertyContainer[] properties) : base(id, creationDate, properties) { TargetVertex = targetVertex; SourceVertex = sourceVertex; ModificationDate = modificationDate; }
/// <summary> /// Initializes a new instance of the <see cref="VertexModel" /> class. /// </summary> /// <param name='id'> Identifier. </param> /// <param name='creationDate'> Creation date. </param> /// <param name='properties'> Properties. </param> public VertexModel(Int32 id, UInt32 creationDate, PropertyContainer[] properties) : base(id, creationDate, properties) { }
/// <summary> /// Loads the vertex. /// </summary> /// <param name='reader'> Reader. </param> /// <param name='graphElements'> Graph elements. </param> /// <param name='edgeTodo'> Edge todo. </param> private static void LoadVertex(SerializationReader reader, BigList<AGraphElement> graphElements, Dictionary<Int32, List<EdgeOnVertexToDo>> edgeTodo) { var id = reader.ReadInt32(); var creationDate = reader.ReadUInt32(); var modificationDate = reader.ReadUInt32(); #region properties var propertyCount = reader.ReadInt32(); PropertyContainer[] properties = null; if (propertyCount > 0) { properties = new PropertyContainer[propertyCount]; for (var i = 0; i < propertyCount; i++) { var propertyIdentifier = reader.ReadUInt16(); var propertyValue = reader.ReadObject(); properties[i] = new PropertyContainer {PropertyId = propertyIdentifier, Value = propertyValue}; } } #endregion #region edges #region outgoing edges List<EdgeContainer> outEdgeProperties = null; var outEdgeCount = reader.ReadInt32(); if (outEdgeCount > 0) { outEdgeProperties = new List<EdgeContainer>(outEdgeCount); for (var i = 0; i < outEdgeCount; i++) { var outEdgePropertyId = reader.ReadUInt16(); var outEdgePropertyCount = reader.ReadInt32(); var outEdges = new List<EdgeModel>(outEdgePropertyCount); for (var j = 0; j < outEdgePropertyCount; j++) { var edgeId = reader.ReadInt32(); EdgeModel edge = graphElements.GetElement(edgeId) as EdgeModel; if (edge != null) { outEdges.Add(edge); } else { var aEdgeTodo = new EdgeOnVertexToDo { VertexId = id, EdgePropertyId = outEdgePropertyId, IsIncomingEdge = false }; List<EdgeOnVertexToDo> todo; if (edgeTodo.TryGetValue(edgeId, out todo)) { todo.Add(aEdgeTodo); } else { edgeTodo.Add(edgeId, new List<EdgeOnVertexToDo> {aEdgeTodo}); } } } outEdgeProperties.Add(new EdgeContainer(outEdgePropertyId, outEdges)); } } #endregion #region incoming edges List<EdgeContainer> incEdgeProperties = null; var incEdgeCount = reader.ReadInt32(); if (incEdgeCount > 0) { incEdgeProperties = new List<EdgeContainer>(incEdgeCount); for (var i = 0; i < incEdgeCount; i++) { var incEdgePropertyId = reader.ReadUInt16(); var incEdgePropertyCount = reader.ReadInt32(); var incEdges = new List<EdgeModel>(incEdgePropertyCount); for (var j = 0; j < incEdgePropertyCount; j++) { var edgeId = reader.ReadInt32(); EdgeModel edge = graphElements.GetElement(edgeId) as EdgeModel; if (edge != null) { incEdges.Add(edge); } else { var aEdgeTodo = new EdgeOnVertexToDo { VertexId = id, EdgePropertyId = incEdgePropertyId, IsIncomingEdge = true }; List<EdgeOnVertexToDo> todo; if (edgeTodo.TryGetValue(edgeId, out todo)) { todo.Add(aEdgeTodo); } else { edgeTodo.Add(edgeId, new List<EdgeOnVertexToDo> { aEdgeTodo }); } } } incEdgeProperties.Add(new EdgeContainer(incEdgePropertyId, incEdges)); } } #endregion #endregion graphElements.SetValue(id, new VertexModel(id, creationDate, modificationDate, properties, outEdgeProperties, incEdgeProperties)); }
/// <summary> /// Loads the edge. /// </summary> /// <param name='reader'> Reader. </param> /// <param name='graphElements'> Graph elements. </param> /// <param name='sneakPeaks'> Sneak peaks. </param> private static void LoadEdge(SerializationReader reader, BigList<AGraphElement> graphElements, ref List<EdgeSneakPeak> sneakPeaks) { var id = reader.ReadInt32(); var creationDate = reader.ReadUInt32(); var modificationDate = reader.ReadUInt32(); #region properties PropertyContainer[] properties = null; var propertyCount = reader.ReadInt32(); if (propertyCount > 0) { properties = new PropertyContainer[propertyCount]; for (var i = 0; i < propertyCount; i++) { var propertyIdentifier = reader.ReadUInt16(); var propertyValue = reader.ReadObject(); properties[i] = new PropertyContainer {PropertyId = propertyIdentifier, Value = propertyValue}; } } #endregion var sourceVertexId = reader.ReadInt32(); var targetVertexId = reader.ReadInt32(); VertexModel sourceVertex = graphElements.GetElement(sourceVertexId) as VertexModel; VertexModel targetVertex = graphElements.GetElement(targetVertexId) as VertexModel; if (sourceVertex != null && targetVertex != null) { graphElements.SetValue(id,new EdgeModel(id, creationDate, modificationDate, targetVertex,sourceVertex, properties)); } else { sneakPeaks.Add(new EdgeSneakPeak { CreationDate = creationDate, Id = id, ModificationDate = modificationDate, Properties = properties, SourceVertexId = sourceVertexId, TargetVertexId = targetVertexId }); } }
public VertexModel CreateVertex(UInt32 creationDate, PropertyContainer[] properties = null) { if (WriteResource()) { //create the new vertex var newVertex = new VertexModel(_currentId, creationDate, properties); //insert it _graphElements.SetValue(_currentId, newVertex); //increment the id Interlocked.Increment(ref _currentId); //Increase the vertex count VertexCount++; FinishWriteResource(); return newVertex; } throw new CollisionException(); }
public EdgeModel CreateEdge(Int32 sourceVertexId, UInt16 edgePropertyId, Int32 targetVertexId, UInt32 creationDate, PropertyContainer[] properties = null) { if (WriteResource()) { EdgeModel outgoingEdge = null; var sourceVertex = _graphElements.GetElement(sourceVertexId) as VertexModel; var targetVertex = _graphElements.GetElement(targetVertexId) as VertexModel; //get the related vertices if (sourceVertex != null && targetVertex != null) { outgoingEdge = new EdgeModel(_currentId, creationDate, targetVertex, sourceVertex, properties); //add the edge to the graph elements _graphElements.SetValue(_currentId, outgoingEdge); //increment the ids Interlocked.Increment(ref _currentId); //add the edge to the source vertex sourceVertex.AddOutEdge(edgePropertyId, outgoingEdge); //link the vertices targetVertex.AddIncomingEdge(edgePropertyId, outgoingEdge); //increase the edgeCount EdgeCount++; } FinishWriteResource(); return outgoingEdge; } throw new CollisionException(); }