Useless changes or something idk

This commit is contained in:
Speykious
2022-01-28 11:48:47 +01:00
parent 1ab4a85643
commit 0a65d1e5eb
2 changed files with 40 additions and 42 deletions

View File

@ -27,12 +27,10 @@ namespace Mediapipe.Net.Framework.Tool
public static string GetUnusedNodeName(CalculatorGraphConfig config, string nodeNameBase)
{
var nodeNames = new HashSet<string>(config.Node.Select(node => node.Name).Where(name => name.Length > 0));
var candidate = nodeNameBase;
var iter = 1;
while (nodeNames.Contains(candidate))
candidate = $"{nodeNameBase}_{++iter:D2}";
for (int i = 2; nodeNames.Contains(candidate); i++)
candidate = $"{nodeNameBase}_{i:D2}";
return candidate;
}
@ -48,39 +46,34 @@ namespace Mediapipe.Net.Framework.Tool
}));
var candidate = inputSidePacketNameBase;
var iter = 1;
while (inputSidePackets.Contains(candidate))
{
candidate = $"{inputSidePacketNameBase}_{++iter:D2}";
}
for (int i = 2; inputSidePackets.Contains(candidate); i++)
candidate = $"{inputSidePacketNameBase}_{i:D2}";
return candidate;
}
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when <paramref name="nodeId" /> is invalid
/// Thrown when <paramref name="nodeId" /> is invalid
/// </exception>
public static string CanonicalNodeName(CalculatorGraphConfig graphConfig, int nodeId)
{
var nodeConfig = graphConfig.Node[nodeId];
var nodeName = nodeConfig.Name.Length == 0 ? nodeConfig.Calculator : nodeConfig.Name;
CalculatorGraphConfig.Types.Node nodeConfig = graphConfig.Node[nodeId];
string nodeName = nodeConfig.Name.Length == 0 ? nodeConfig.Calculator : nodeConfig.Name;
var nodesWithSameName = graphConfig.Node
.Select((node, i) => (node.Name.Length == 0 ? node.Calculator : node.Name, i))
.Where(pair => pair.Item1 == nodeName);
if (nodesWithSameName.Count() <= 1)
{
return nodeName;
}
var seq = nodesWithSameName.Count(pair => pair.i <= nodeId);
return $"{nodeName}_{seq}";
}
/// <exception cref="ArgumentException">
/// Thrown when the format of <paramref cref="stream" /> is invalid
/// Thrown when the format of <paramref cref="stream" /> is invalid
/// </exception>
public static string ParseNameFromStream(string stream)
{
@ -89,7 +82,7 @@ namespace Mediapipe.Net.Framework.Tool
}
/// <exception cref="ArgumentException">
/// Thrown when the format of <paramref cref="tagIndex" /> is invalid
/// Thrown when the format of <paramref cref="tagIndex" /> is invalid
/// </exception>
public static (string, int) ParseTagIndex(string tagIndex)
{
@ -98,7 +91,7 @@ namespace Mediapipe.Net.Framework.Tool
}
/// <exception cref="ArgumentException">
/// Thrown when the format of <paramref cref="stream" /> is invalid
/// Thrown when the format of <paramref cref="stream" /> is invalid
/// </exception>
public static (string, int) ParseTagIndexFromStream(string stream)
{
@ -108,14 +101,13 @@ namespace Mediapipe.Net.Framework.Tool
public static string CatTag(string tag, int index)
{
var colonIndex = index <= 0 || tag.Length == 0 ? "" : $":{index}";
string colonIndex = index <= 0 || tag.Length == 0 ? "" : $":{index}";
return $"{tag}{colonIndex}";
}
public static string CatStream((string, int) tagIndex, string name)
{
var tag = CatTag(tagIndex.Item1, tagIndex.Item2);
string tag = CatTag(tagIndex.Item1, tagIndex.Item2);
return tag.Length == 0 ? name : $"{tag}:{name}";
}
}

View File

@ -61,8 +61,8 @@ namespace Mediapipe.Net.Framework.Tool
public static void ParseTagAndName(string tagAndName, out string tag, out string name)
{
var nameIndex = -1;
var v = tagAndName.Split(':');
int nameIndex;
string[] v = tagAndName.Split(':');
try
{
@ -77,10 +77,11 @@ namespace Mediapipe.Net.Framework.Tool
ValidateName(v[1]);
nameIndex = 1;
}
else
{
throw new ArgumentException("nope");
}
// TODO: what do we put inside of this ArgumentException?
if (nameIndex == -1)
throw new ArgumentException();
}
catch (ArgumentException)
{
@ -93,9 +94,9 @@ namespace Mediapipe.Net.Framework.Tool
public static void ParseTagIndexName(string tagIndexName, out string tag, out int index, out string name)
{
var nameIndex = -1;
var theIndex = 0;
var v = tagIndexName.Split(':');
int nameIndex;
int theIndex = 0;
string[] v = tagIndexName.Split(':');
try
{
@ -116,13 +117,18 @@ namespace Mediapipe.Net.Framework.Tool
ValidateTag(v[0]);
ValidateNumber(v[1]);
theIndex = int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId ? result : throw new ArgumentException();
if (int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId)
theIndex = result;
else
throw new ArgumentException("nope");
ValidateName(v[2]);
nameIndex = 2;
}
if (nameIndex == -1)
throw new ArgumentException();
else
{
throw new ArgumentException("nope");
}
}
catch (ArgumentException)
{
@ -136,32 +142,32 @@ namespace Mediapipe.Net.Framework.Tool
public static void ParseTagIndex(string tagIndex, out string tag, out int index)
{
var theIndex = -1;
var v = tagIndex.Split(':');
int theIndex;
string[] v = tagIndex.Split(':');
try
{
if (v.Length == 1)
{
if (v[0].Length != 0)
{
ValidateTag(v[0]);
}
theIndex = 0;
}
else if (v.Length == 2)
{
if (v[0].Length != 0)
{
ValidateTag(v[0]);
}
ValidateNumber(v[1]);
theIndex = int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId ? result : throw new ArgumentException();
if (int.TryParse(v[1], out var result) && result <= Internal.MaxCollectionItemId)
theIndex = result;
else
throw new ArgumentException("nope");
}
else
{
throw new ArgumentException("nope");
}
if (theIndex == -1)
throw new ArgumentException();
}
catch (ArgumentException)
{