Esempio n. 1
0
            public static void Write <VertexT, EdgeT, GraphT>(BinaryWriter writer, GenericGraph <VertexT, EdgeT, GraphT> graph)
                where VertexT : GenericVertex <VertexT, EdgeT, GraphT>
                where EdgeT : GenericEdge <VertexT, EdgeT, GraphT>
                where GraphT : GenericGraph <VertexT, EdgeT, GraphT>
            {
                Write(writer, (AbstractGraphElement <GraphT>)graph);

                writer.Write(graph.Vertices.Count);
                foreach (var pair in graph.Vertices)
                {
                    writer.Write(pair.Key);
                    Write(writer, pair.Value);
                }

                writer.Write(graph.Edges.Count);
                foreach (var e in graph.Edges)
                {
                    writer.Write(e.StartVertex.Id);
                    writer.Write(e.EndVertex.Id);
                    Write(writer, e);
                }
            }
Esempio n. 2
0
            public static void Read <VT, ET, VertexT, EdgeT, GraphT>(BinaryReader reader, GenericGraph <VertexT, EdgeT, GraphT> graph)
                where VT : VertexT
                where ET : EdgeT
                where VertexT : GenericVertex <VertexT, EdgeT, GraphT>
                where EdgeT : GenericEdge <VertexT, EdgeT, GraphT>
                where GraphT : GenericGraph <VertexT, EdgeT, GraphT>
            {
                int     i;
                ulong   id;
                VertexT v;

                graph.Clear();

                Read(reader, graph);

                var size = reader.ReadInt32();

                for (i = 0; i < size; i++)
                {
                    id = reader.ReadUInt64();
                    v  = graph.CreateVertex(typeof(VT), id);
                    Read(reader, v);
                }

                size = reader.ReadInt32();
                for (i = 0; i < size; i++)
                {
                    id = reader.ReadUInt64();
                    v  = graph.GetVertexById(id);

                    var id2 = reader.ReadUInt64();
                    var v2  = graph.GetVertexById(id2);

                    EdgeT e = v.ConnectTo <ET>(v2);

                    Read(reader, e);
                }
            }