Skip to content

Commit

Permalink
Merge commit '63ccd108e2cd7297b5a4e1d1a2349816fb619c49'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Sep 13, 2024
2 parents c9e1d1f + 63ccd10 commit 4adea9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
20 changes: 18 additions & 2 deletions Bp/MathGraph/MathGraph/MathGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using MathGraph.Serialization;

namespace MathGraph;

public class MathGraph<TElementInfo, TEdgeInfo>: ISerializableElement
public class MathGraph<TElementInfo, TEdgeInfo> : ISerializableElement
{
public MathGraph()
{
Expand Down Expand Up @@ -74,11 +75,26 @@ public void AddBidirectionalEdge(MathGraphElement<TElementInfo, TEdgeInfo> a,
}
}

public string Serialize()
string ISerializableElement.Serialize()
{
var mathGraphSerializer = GetSerializer();
return mathGraphSerializer.Serialize();
}

internal void StartDeserialize(int elementCount)
{
_elementList.Clear();
EnsureElementCapacity(elementCount);
}

/// <summary>
/// 序列化使用设置元素的大小
/// </summary>
/// <param name="capacity"></param>
private void EnsureElementCapacity(int capacity)
{
_elementList.EnsureCapacity(capacity);
}
}

static class MathGraphElementIdGenerator
Expand Down
2 changes: 1 addition & 1 deletion Bp/MathGraph/MathGraph/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public bool TryDeserialize(string value, string? type, [NotNullWhen(true)] out o
if (type == typeof(MathGraph<string, string>).FullName)
{
var mathGraph = new MathGraph<string, string>();
var mathGraphSerializer = mathGraph.GetSerializer();
var mathGraphSerializer = mathGraph.GetSerializer(this);
mathGraphSerializer.Deserialize(value);
result = mathGraph;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public void Deserialize(string json)
}

var dictionary = new Dictionary<int, MathGraphElement<TElementInfo, TEdgeInfo>>();
_mathGraph.StartDeserialize(list.Count);
foreach (var serializationContext in list)
{
var elementType = serializationContext.ElementType;
Expand Down

0 comments on commit 4adea9f

Please sign in to comment.