Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(dotnet): compare Usage option keys ordinally

kevin-gatimu89b45c493214
diff --git a/laya-dotnet/src/Laya/Answers.cs b/laya-dotnet/src/Laya/Answers.cs
index 5da1a9b9..435ed354 100644
--- a/laya-dotnet/src/Laya/Answers.cs
+++ b/laya-dotnet/src/Laya/Answers.cs
@@ -52,9 +52,14 @@ public readonly record struct Usage(int InputTokens, int OutputTokens)
private static bool SameList(IReadOnlyList<string>? a, IReadOnlyList<string>? b) =>
ReferenceEquals(a, b) || (a is not null && b is not null && a.SequenceEqual(b, StringComparer.Ordinal));
+ // Keys compare ordinally whatever comparer either map was built with, so equality stays
+ // symmetric and agrees with GetHashCode's ordinal key hashes.
private static bool SameMap(IReadOnlyDictionary<string, OptionUsage>? a, IReadOnlyDictionary<string, OptionUsage>? b) =>
ReferenceEquals(a, b) || (a is not null && b is not null && a.Count == b.Count
- && a.All(pair => b.TryGetValue(pair.Key, out var value) && value == pair.Value));
+ && a.OrderBy(pair => pair.Key, StringComparer.Ordinal)
+ .Zip(b.OrderBy(pair => pair.Key, StringComparer.Ordinal))
+ .All(pairs => string.Equals(pairs.First.Key, pairs.Second.Key, StringComparison.Ordinal)
+ && pairs.First.Value == pairs.Second.Value));
}
/// <summary>Option-span diagnostics from Python's common.collapsed_options.</summary>
diff --git a/laya-dotnet/tests/Laya.Tests/UsageTests.cs b/laya-dotnet/tests/Laya.Tests/UsageTests.cs
index 13b9e510..2e91e01e 100644
--- a/laya-dotnet/tests/Laya.Tests/UsageTests.cs
+++ b/laya-dotnet/tests/Laya.Tests/UsageTests.cs
@@ -176,4 +176,21 @@ public class UsageTests
Assert.NotEqual(a, a with { InputTokens = 11 });
}
+
+ [Fact]
+ public void Options_KeysCompareOrdinallyWhateverEitherMapsComparer()
+ {
+ var ordinal = Full(options: new Dictionary<string, OptionUsage>(StringComparer.Ordinal)
+ { ["q1"] = new OptionUsage(5, 3, 9) });
+ var ignoreCase = Full(options: new Dictionary<string, OptionUsage>(StringComparer.OrdinalIgnoreCase)
+ { ["Q1"] = new OptionUsage(5, 3, 9) });
+ Assert.False(ordinal.Equals(ignoreCase));
+ Assert.False(ignoreCase.Equals(ordinal));
+
+ var sameKeyIgnoreCase = Full(options: new Dictionary<string, OptionUsage>(StringComparer.OrdinalIgnoreCase)
+ { ["q1"] = new OptionUsage(5, 3, 9) });
+ Assert.True(ordinal.Equals(sameKeyIgnoreCase));
+ Assert.True(sameKeyIgnoreCase.Equals(ordinal));
+ Assert.Equal(ordinal.GetHashCode(), sameKeyIgnoreCase.GetHashCode());
+ }
}