/// <summary> /// Relocates data internally in the most compact way possible. /// </summary> public void Compress() { _graph.Compress((originalId, newId) => { _edgeData[newId] = _edgeData[originalId]; }); _edgeData.Resize(_graph.EdgeCount); }
public void TestSerialize() { var graph = new GeometricGraph(1, 100); // add one edge. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddEdge(0, 1, new uint[] { 10 }, null); // serialize. graph.Compress(); var expectedSize = graph.SizeInBytes; using (var stream = new System.IO.MemoryStream()) { Assert.AreEqual(expectedSize, graph.Serialize(stream)); } graph = new GeometricGraph(1, 100); // add one edge. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddVertex(2, 0, 0); graph.AddVertex(3, 0, 0); graph.AddVertex(4, 0, 0); graph.AddVertex(5, 0, 0); graph.AddEdge(0, 1, new uint[] { 10 }, null); graph.AddEdge(0, 2, new uint[] { 20 }, null); graph.AddEdge(0, 3, new uint[] { 30 }, null); graph.AddEdge(0, 4, new uint[] { 40 }, null); graph.AddEdge(5, 1, new uint[] { 50 }, null); graph.AddEdge(5, 2, new uint[] { 60 }, null); graph.AddEdge(5, 3, new uint[] { 70 }, null); graph.AddEdge(5, 4, new uint[] { 80 }, null); // serialize. graph.Compress(); expectedSize = graph.SizeInBytes; using (var stream = new System.IO.MemoryStream()) { Assert.AreEqual(expectedSize, graph.Serialize(stream)); } }
public void TestCompress() { var graph = new GeometricGraph(1, 100); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); var edgeId = graph.AddEdge(0, 1, new uint[] { 10 }, new Coordinate() { Latitude = 1, Longitude = 1 }); graph.Compress(); var edge = graph.GetEdge(edgeId); Assert.IsNotNull(edge); Assert.AreEqual(0, edge.From); Assert.AreEqual(1, edge.To); Assert.AreEqual(edgeId, edge.Id); Assert.AreEqual(1, edge.Shape.Count); Assert.AreEqual(1, edge.Shape.First().Latitude); Assert.AreEqual(1, edge.Shape.First().Longitude); }